description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
def nextDay(cells):
ans = [0]
for i in range(1, len(cells) - 1):
ans.append(int(cells[i - 1] == cells[i + 1]))
ans.append(0)
return ans
seen = {}
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR... |
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells, N):
seen = {}
while N:
seen.setdefault(str(cells), N)
print(seen)
N -= 1
cells = [0] + [(cells[i - 1] ^ cells[i + 1] ^ 1) for i in range(1, 7)] + [0]
if str(cells) in seen:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER LIST NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR ... |
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
seen = dict()
is_fast_forwarded = False
state_bitmap = 0
for cell in cells:
state_bitmap <<= 1
state_bitmap = state_bitmap | cell
while N > 0:
if not is_fas... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER IF VAR IF VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_C... |
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
visited = {str(cells): N}
cycle = 0
hascycle = False
def get_next(cells) -> List[int]:
tmp = [0] + [(cells[i - 1] ^ cells[i + 1] ^ 1) for i in range(1, 7)] + [0]
return tmp
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER LIST NUMBER RETURN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR... |
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
prison_size = len(cells)
seen = {}
seen[str(cells)] = 0
history = [cells]
for d in range(1, N + 1):
ans = [0] * prison_size
for i in range(1, 7):
ans[i]... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBE... |
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
def next(state):
return tuple(
(
1
if i > 0 and i < len(state) - 1 and state[i - 1] == state[i + 1]
else 0
)
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR B... |
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
for i in range((N - 1) % 14 + 1):
cells = [0] + [(cells[i - 1] ^ cells[i + 1] ^ 1) for i in range(1, 7)] + [0]
return cells | CLASS_DEF FUNC_DEF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER LIST NUMBER RETURN VAR VAR VAR |
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
def transform(cells):
nxtCells = [0] * len(cells)
for i in range(1, len(cells) - 1):
nxtCells[i] = 1 if cells[i - 1] == cells[i + 1] else 0
return nxtCells
day = ... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER I... |
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
if not cells:
return cells
day1 = self.nextDay(cells)
cells = day1.copy()
count = 0
N -= 1
while N > 0:
each_day = self.nextDay(cells)
count += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL... |
There are 8 prison cells in a row, and each cell is either occupied or vacant.
Each day, whether the cell is occupied or vacant changes according to the following rules:
If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
Otherwise, it becomes vacant.
(Note that... | class Solution:
def prisonAfterNDays(self, cells: List[int], N: int) -> List[int]:
cell = 0
for c in cells:
cell = cell << 1 | c
seendict = {}
index = 0
while True:
if cell in seendict:
if (N - index) % (index - seendict[cell]) == 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL STRING VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR B... |
You are given an array of $n$ integers $a_1, a_2, \ldots, a_n$.
You will perform $q$ operations. In the $i$-th operation, you have a symbol $s_i$ which is either "<" or ">" and a number $x_i$.
You make a new array $b$ such that $b_j = -a_j$ if $a_j s_i x_i$ and $b_j = a_j$ otherwise (i.e. if $s_i$ is '>', then all $a... | import sys
N, Q = map(int, input().split())
A = list(map(int, input().split()))
Sign = [0] * (3 + 10**5)
SX = [tuple(sys.stdin.readline().split()) for _ in range(Q)]
mini = 3 + 10**5
Sign = [0] * (3 + 10**5)
keep = 1
for s, x in SX[::-1]:
x = int(x)
ax = abs(x) + int((s == ">") ^ (x < 0))
sin = 1 if s == "... | IMPORT 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 BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN ... |
You are given an array of $n$ integers $a_1, a_2, \ldots, a_n$.
You will perform $q$ operations. In the $i$-th operation, you have a symbol $s_i$ which is either "<" or ">" and a number $x_i$.
You make a new array $b$ such that $b_j = -a_j$ if $a_j s_i x_i$ and $b_j = a_j$ otherwise (i.e. if $s_i$ is '>', then all $a... | n, q = map(int, input().split())
a = list(map(int, input().split()))
swaps = [0] * q
for i in range(q):
b = input().split()
b[1] = int(b[1])
out = 1 if b[0] == "<" and b[1] <= 0 or b[0] == ">" and b[1] >= 0 else 0
split = b[1] + 0.5 if b[0] == ">" else b[1] - 0.5
sign = 1 if split > 0 else -1
sp... | 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER STRING VAR NUMBER NUMBER VAR NUMBER ... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def convert(x, k):
binary = ""
while x != 0:
d = x % 2
binary += str(d)
x //= 2
while 1:
if len(binary) != k:
binary += "0"
else:
break
decimal = 0
for i in range(len(binary)):
if binary[i] == "1":
decimal += 2 ** (k... | FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL V... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def decimal_to_binary(n):
if n == 0:
list1 = []
list1.append(0)
return list1
list1 = []
while n:
list1.append(n % 2)
n = n // 2
list1.reverse()
return list1
def binary_to_decimal(list1, k):
ans = 0
size = len(list1) - 1
for i in range(size, 0 - 1... | FUNC_DEF IF VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER NUMBE... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for i in range(int(input())):
a, b = map(str, input().split())
a = int(a)
b = list(b)
c = [""] * (1 << a)
for ii in range(1 << a):
ss = int(str("{0:0" + str(a) + "b}").format(ii), 2)
s = int(str("{0:0" + str(a) + "b}").format(ii)[::-1], 2)
c[s] = b[ss]
print(str("".join(c... | 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR BIN_OP BIN_OP STRI... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def reversebit(n, length):
a = []
for i in range(length):
a.append(n % 2)
n = n // 2
s = 0
for i in range(length):
s += a[i] * 2 ** (length - 1 - i)
return s
for _ in range(int(input())):
n, s = input().split()
n = int(n)
b = []
for i in range(2**n):
... | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL V... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def transformIndex(k, index):
i = k
new_index = 0
while i > 0:
res = index % 2
index = index // 2
new_index = new_index << 1 | res
i -= 1
return new_index
def solution(k, message):
k = int(k)
ans = ""
for i in range(len(message)):
ans += message[tran... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSI... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
return input().strip()
def invr():
return map(int, input().split())
def outp(n):
sys.stdout.write(str(n) + "\n")
def outlt(lst):
sys.stdout.write(" ".j... | 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 RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL ... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def arrange(k, s):
t = [char for char in s]
def reverse_bits(n, k):
r = 0
while n:
if n & 1:
r |= 1 << k - 1
n >>= 1
k -= 1
return r
for pos in range(1, 2**k - 1):
t[reverse_bits(pos, k)] = s[pos]
return "".join(t)
t... | FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_C... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for test_case in range(int(input())):
input1 = input().split(" ")
bits = input1[0]
string = input1[1]
new_str = []
for i in range(len(string)):
new_str.append("")
for i in range(len(string)):
og_letter = string[i]
bin_str = "{0:0" + bits + "b}"
binary = bin_str.fo... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | a = int(input())
for i in range(a):
b = list(map(str, input().split()))
l = []
for j in range(len(b[1])):
c = bin(j)
c = "0" * (int(b[0]) - (len(c) - 2)) + c[2:]
l.append(c[::-1])
c = []
for j in range(len(l)):
c.append(b[1][int(l[j], 2)])
print("".join(c)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def rev(i, n):
binary = bin(i)
reverse = binary[-1:1:-1]
reverse = reverse + (n - len(reverse)) * "0"
return int(reverse, 2)
t = int(input())
while t:
n, l = input().split()
n = int(n)
list = [char for char in l]
for i in range(2**n):
j = rev(i, n)
if i > j:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR F... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | t = int(input())
for i in range(0, t):
n, a = input().strip().split()
n = int(n)
for j in range(0, 2**n):
c = bin(j)[2:]
c = "0" * (n - len(c)) + c
c = c[::-1]
print(a[int(c, 2)], end="")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for i in range(int(input())):
k, s = map(str, input().split())
k = int(k)
a = ""
for i in range(2**k):
v = 0
x = k
while i > 0:
v = v + 2 ** (x - 1) * (i % 2)
i = i // 2
x = x - 1
a = a + s[int(v)]
print(a) | 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 ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMB... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def get_binary(num, bits):
ans = []
for i in range(bits):
ans.append("0")
i = bits - 1
while i >= 0:
ans[i] = str(num % 2)
num //= 2
i -= 1
return "".join(ans)
for t in range(int(input())):
temp = list(input().split())
k = int(temp[0])
s = temp[1]
an... | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR A... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | t = int(input())
def binStrToInt(binary_str):
length = len(binary_str)
num = 0
for i in range(length):
num = num + int(binary_str[i])
num = num * 2
return num // 2
for index in range(t):
inp = input().split()
k = int(inp[0])
word = inp[1]
formatStr = "{0:0" + str(k) +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSI... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def padded_bin(i, width):
s = bin(i)
return s[:2] + s[2:].zfill(width)
t = int(input())
while t:
k, s = map(str, input().split())
k = int(k)
l = list()
new = list()
length = len(s)
for i in s:
l.append(i)
for i in range(0, length):
j = padded_bin(i, k)
j = j... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR F... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | t = int(input())
while t:
t -= 1
n, a = input().split()
n = int(n)
ans = ""
for i in range(2**n):
ans += a[int(bin(i)[2:].rjust(n, "0")[::-1], 2)]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for _ in range(int(input())):
array = list(input().split())
k = int(array[0])
length = 2**k
final = [0] * length
for i in range(length):
p = bin(i)[2:]
for TT in range(k - len(p)):
p = "0" + p
p = p[-1::-1]
final[int(p, 2)] = array[1][i]
print("".join(... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VA... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for t in range(int(input())):
k, msg = input().strip().split()
k = int(k)
msg = list(msg)
new_msg = ["0"] * 2**k
for i in range(0, 2**k):
binary = bin(i)
rev = binary[-1:1:-1]
rev = rev + (k - len(rev)) * "0"
new_msg[int(rev, 2)] = msg[i]
print("".join(str(i) for ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASS... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def binary(a, n):
ans = []
while a != 0:
ans.append(a & 1)
a >>= 1
temp = []
for x in range(n - len(ans)):
temp.append(0)
return int("".join(map(str, ans + temp)), 2)
for w in range(int(input())):
line = input().split()
k = int(line[0])
line = line[1]
ans = ... | FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VA... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def convert_to_num(l):
l = list(map(int, l))
k = len(l)
num = 0
i = 0
while i < k:
num += l[i] * 2**i
i += 1
return num
def to_binary(l, k):
t = list(l)
if len(t) == k:
return t
t_1 = k - len(t)
while t_1 > 0:
t.insert(0, "0")
t_1 -= 1
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR WHILE VAR NU... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for t in range(int(input())):
n, word = input().split()
n = int(n)
length = 2**n
new_word = ""
for i in range(length):
binary = "{0:b}".format(i, n)
if len(binary) < n:
binary = "0" * (n - len(binary)) + binary
pos = int(binary[::-1], 2)
new_word += word[p... | 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 BIN_OP NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASS... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | t = int(input())
for z in range(t):
dictionary = {}
k, string = map(str, input().split())
k = int(k)
for i in range(2**k):
dictionary[str(bin(i)[2:].zfill(k))] = string[i]
for i in range(2**k):
alpha = bin(i)[2:].zfill(k)
alpha = alpha[::-1]
print(dictionary[str(alpha... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR A... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for tests in range(int(input())):
K, old = input().split()
new = [i for i in old]
K = int(K)
for letter in range(len(old)):
binary = bin(letter)[2:]
binary = "0" * (K - len(binary)) + binary
binary = "".join(binary[::-1])
new[int(binary, 2)] = old[letter]
print("".joi... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR NUMBER... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for t in range(int(input())):
k, text = map(str, input().split())
k = int(k)
dic = {(0): 0}
alp = ["."] * 2**k
for i in range(1, 2**k):
if i not in dic:
ibin = list(bin(i))
ibin = ibin[2:]
if len(ibin) != k:
ibin = ["0"] * (k - len(ibin)) +... | 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 ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIG... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | n = int(input())
for i in range(n):
st = input().split(" ")
k = int(st[0])
msg = list(st[1])
arr = [x for x in range(2**k)]
for i in range(len(msg)):
binNum = bin(i).replace("0b", "").zfill(k)
revbinIndex = int(binNum[::-1], 2)
arr[revbinIndex] = msg[i]
for i in arr:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR S... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for i in range(int(input())):
n, s = input().split()
l = list(s)
for i in range(len(s)):
b = bin(i)[2:]
b = int(("0" * (int(n) - len(b)) + b)[::-1], 2)
l[b] = s[i]
print("".join(l)) | 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | t = int(input())
while t:
k, s = map(str, input().split())
k = int(k)
for i in range(2**k):
j = bin(i)[2:]
r = "0" * (k - len(j)) + j
print(s[int(r[::-1], 2)], end="")
print("")
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUM... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | n = int(input())
while n > 0:
a, b = input().split()
a = int(a)
s = [" " for i in range(len(b))]
for i in range(len(b)):
bin1 = str(bin(i))[2:]
bin1 = "0" * (a - len(bin1)) + bin1
bin1 = int(bin1[::-1], 2)
s[bin1] = b[i]
print("".join(s))
n -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL 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... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | t = int(input())
for i in range(t):
inp = input()
arr = [(int(i) if i.isdigit() else i) for i in inp.split()]
li = [0] * 2 ** arr[0]
for j, k in enumerate(arr[1]):
ind = bin(j)[2:]
av = arr[0] - len(ind)
f = "0" * av + ind
mod_place = int(f[::-1], 2)
li[mod_place]... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CAL... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for _ in range(int(input())):
lst = list(input().split())
n, string = int(lst[0]), lst[1]
dictionary = dict()
for i in range(2**n):
temp = bin(i)[2:]
temp = "0" * (n - len(temp)) + temp
dictionary[temp] = string[i]
output = ""
for i in dictionary.keys():
rev = i[:... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSI... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | allzero = "0000000000000000"
for _ in range(int(input())):
k, s = map(str, input().split())
k = int(k)
a = list(s)
b = ["a"] * pow(2, k)
for i in range(pow(2, k)):
t = bin(i)[2:].zfill(k)
rt = t[::-1]
b[int(rt, 2)] = a[i]
ans = "".join(e for e in b)
print(ans) | ASSIGN VAR STRING 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | from sys import stdin, stdout
def sin():
return stdin.readline().rstrip()
def listInput():
return list(map(int, sin().split()))
def printBS(li):
if not li:
return
for i in range(len(li) - 1):
stdout.write("%d " % li[i])
stdout.write("%d\n" % li[-1])
def rev(a, k):
b = 0
... | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL V... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | t = int(input())
for _ in range(t):
k, s = input().rstrip().split()
k = int(k)
d = []
for i, c in enumerate(s):
b = bin(i)[2:].rjust(k, "0")[::-1]
d.append((int(b, base=2), c))
d = sorted(d)
print("".join([c for i, c in d])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CAL... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for _ in range(int(input())):
k, s = input().split()
k = int(k)
n = 2**k
ans = [0] * n
for i in range(n):
ans[int(bin(i)[2:].zfill(k)[::-1], 2)] = s[i]
print("".join(ans)) | 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 BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CAL... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | tests = int(input())
for i in range(tests):
num, string = input().split()
num = int(num)
arr = [0] * 2**num
arr[0] = string[0]
for j in range(2**num):
pos = j
ans = 0
count = 0
while j != 0:
if j & 1:
ans |= 1 << num - 1 - count
... | 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 VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | t = int(input())
for i in range(t):
n, s = map(str, input().split())
n = int(n)
l = list(s)
for j in range(len(s)):
z = bin(j)[2:]
z = int(("0" * (n - len(z)) + z)[::-1], 2)
l[z] = s[j]
print("".join(l)) | 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 ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CA... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for i in range(int(input())):
k, t = input().strip().split()
k = int(k)
l = len(t)
a = [" " for _ in range(l)]
for i in range(l):
s = str(bin(i))[2:]
s = "0" * (k - len(s)) + s
j = int(s[::-1], 2)
a[j] = t[i]
print("".join(a)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR 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... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | for _ in range(int(input())):
k, l = map(str, input().split())
main = list(l)
nn = []
i = 0
while i < len(main):
f = list(str(bin(i)[2:].zfill(int(k))))
f.reverse()
h = "".join(f)
p = int(h, 2)
nn.append(main[p])
i += 1
print("".join(nn)) | 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 ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR ... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def function(K, A):
arr = [(0) for i in range(len(A))]
for i in range(len(A)):
data = A[i]
value = K
num = i
res = 0
while num:
res = res << 1
res += num & 1
num = num >> 1
value -= 1
if value > 0:
res = ... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VA... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def rev(i, val):
a = i
arr = []
while a > 0:
arr.append(a % 2)
a //= 2
while len(arr) < val:
arr.append(0)
change = 0
for i in range(val):
change += 2 ** (val - 1 - i) * arr[i]
return change
t = int(input())
for _ in range(t):
val, st = input().split()
... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR V... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def masking(bits, n):
a = 1 << n - 1
ret = 0
mask = 1
i = 0
while i <= n - 1:
mask = 1 << i
a = 1 << n - i - 1
if bits & mask:
ret = ret | a
i += 1
return ret
for t in range(int(input())):
n, var = map(str, input().strip().split())
n = int(n)... | FUNC_DEF ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR F... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def decimalToBinary(n, k):
b = bin(n).replace("0b", "")
if len(b) < k:
return (k - len(b)) * "0" + b
return b
def binaryToDecimal(n):
return int(n, 2)
for _ in range(int(input())):
l = []
k, s = input().split(" ")
k = int(k)
d = {}
final = ""
for num in range(0, 2**k)... | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING IF FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN V... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def calcindex(n, i):
sum = 0
count = 0
while i > 0:
if i % 2 == 1:
sum = sum + pow(2, n - count - 1)
i = i // 2
count += 1
return sum
def calc(n, s):
n = int(n)
marked = [(False) for i in range(2**n)]
s = list(s)
for i in range(2**n):
index =... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC... |
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g... | def b(n, k):
s = ""
while n // 2 != 0:
s += str(n % 2)
n = n // 2
s += str(n)
if len(s) < k:
s = s + "0" * (k - len(s))
return s
t = int(input())
for i in range(t):
k, s = map(str, input().split())
k = int(k)
y = 2**k
ans = ["0"] * y
for j in range(y):
... | FUNC_DEF ASSIGN VAR STRING WHILE BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VA... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def dfs(self, u, connect_chars, visited):
visited[u] = 1
for v in connect_chars[u]:
if visited[v] == 0:
self.dfs(v, connect_chars, visited)
def binaryPalindrome(self, n, k):
pos_arr = [0] * n
for i in range(n):
pos_arr[i] ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def binaryPalindrome(self, n, k):
def dfs(parent, ans, connectchars):
ans[parent] = 1
for i in connectchars[parent]:
if not ans[i]:
dfs(i, ans, connectchars)
arr = [0] * n
ans = [0] * n
connectchars = [set... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_O... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def binaryPalindrome(self, n, k):
arr = ["0"] * n
arr[0] = arr[-1] = "1"
for i in range(1, n):
if i % k == 0:
arr[i] = "1"
i = 0
j = n - 1
while i < j:
if arr[i] == "1":
arr[j] = "1"
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def dfs(self, temp, result, charsjoin):
result[temp] = 1
for i in range(len(charsjoin[temp])):
if not result[charsjoin[temp][i]]:
self.dfs(charsjoin[temp][i], result, charsjoin)
def binaryPalindrome(self, n, k):
result = [0] * n
arr =... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FOR VA... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def dfs(self, parent, ans, connectChars):
ans[0] = 1
for linked_k_i in connectChars[0]:
ans[linked_k_i] = 1
def binaryPalindrome(self, n, k):
arr = [(0) for i in range(n)]
ans = [(0) for i in range(n)]
connectChars = [[] for i in range(k)]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def dfs(self, node, ans, adj):
ans[node] = 1
for k in adj[node]:
if not ans[k]:
self.dfs(k, ans, adj)
return None
def binaryPalindrome(self, n, k):
arr = [(i % k) for i in range(n)]
ans = [0] * n
adj = {}
for i... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN NONE FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL V... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def binaryPalindrome(self, n, k):
output = ["0" for i in range(n)]
base = ["0" for i in range(k)]
out = 0
if k >= n:
output[0] = "1"
output[-1] = "1"
output = "".join(output)
return int(output)
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR FUNC_CALL STRING VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER ST... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def construct_answer(self, ans, arr, connected_zero_set):
for i in range(len(arr)):
if arr[i] in connected_zero_set:
ans[i] = 1
return "".join(str(element) for element in ans)
def binaryPalindrome(self, n, k):
arr = [(0) for i in range(n)]
... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP ... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def binaryPalindrome(self, n, k):
ans = [0] * n
arr = [0] * n
graph = [set() for i in range(k)]
for i in range(n):
arr[i] = i % k
for i in range(n // 2):
graph[arr[i]].add(arr[n - i - 1])
graph[arr[n - i - 1]].add(arr[i])
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP ... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def binaryPalindrome(self, n, k):
a = [0] * n
r = []
c = [[] for i in range(k)]
if k == 1:
return str(k) * n
for i in range(n):
a[i] = i % k
t = [0] * k
for i in range(int(n / 2)):
c[a[i]].append(a[n - i - 1... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ... |
Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros... | class Solution:
def binaryPalindrome(self, n, k):
arr = [("0" if i % k else "1") for i in range(n)]
for i in range(n):
if arr[i] == "1":
arr[n - i - 1] = "1"
output = ""
for i in arr:
output += i
return output | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR STRING STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR STRING FOR VAR VAR VAR VAR RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
arr = sorted(arr)
for i in range(len(arr)):
count = arr.count(arr[i])
if count == 1:
return arr[i] | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
h = {}
for num in arr:
h[num] = h.get(num, 0) + 1
for key in h:
if h[key] == 1:
return key | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
seen = {}
for x in arr:
if x not in seen:
seen[x] = 1
else:
seen[x] += 1
singleelem = {value: key for key, value in seen.items()}
return singleelem[1] | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR RETURN VAR NUMBER |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
ones = 0
twos = 0
for x in arr:
ones = (ones ^ x) & ~twos
twos = (twos ^ x) & ~ones
return ones | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
sort = sorted(arr)
if N == 1:
return sort[0]
if sort[0] != sort[1]:
return sort[0]
for i in range(1, N):
if i == N - 1:
return sort[i]
if (sort[i - 1] != sort[i]) & (sort... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER RETURN VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
a = 0
b = 0
for i in range(N):
b = b ^ a & arr[i]
a = a ^ arr[i]
common = ~(a & b)
a = a & common
b = b & common
return a | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
dic = {}
for i in arr:
if i not in dic:
dic[i] = 1
else:
dic[i] += 1
for key, value in dic.items():
if value == 1:
return key | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
count = 0
arr.sort()
for i in range(N - 1):
if arr[i] != arr[i + 1] and count == 0:
return arr[i]
else:
count += 1
if arr[i] != arr[i + 1]:
count = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR NUMBER |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
d = dict()
for i in arr:
m = 1
if i in d.keys():
m += d[i]
d[i] = m
for i in d.keys():
if d[i] == 1:
return i
return 0 | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
arr.sort()
for i in range(1, N, 3):
if arr[i] != arr[i - 1]:
return arr[i - 1]
return arr[-1] | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER RETURN VAR NUMBER |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
ones = 0
twos = 0
for i in range(N):
current = arr[i]
twos |= ones & current
ones ^= current
common = ones & twos
ones &= ~common
twos &= ~common
return ones | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
a, b, c = -1, 0, 0
for r in arr:
a1, b1, c1 = a & r, b & r, c & r
a, b, c = a ^ a1, b ^ b1, c ^ c1
a, b, c = a | c1, b | a1, c | b1
return b | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
g = {}
for i in range(0, N):
c = arr[i]
if c not in g:
g[c] = 1
else:
g[c] = g[c] + 1
for x in g:
if g[x] == 1:
return x | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
d = {}
ans = 0
for i in arr:
if i not in d.keys():
d[i] = 1
else:
d[i] += 1
for i in list(d.keys()):
if d[i] == 1:
return i | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
sum1 = 0
for i in arr:
sum1 += i
set1 = set(arr)
set1 = sorted(set1)
sum2 = 0
for ele in set1:
sum2 += ele
return int(sum2 - (sum1 - sum2) / 2) | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
d = dict()
for ele in arr:
d[ele] = 0
for ele in arr:
d[ele] = d[ele] + 1
for ele in d.keys():
if d[ele] == 1:
return ele | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
p = {}
for i in arr:
p[i] = 0
for i in range(N):
p[arr[i]] += 1
for i in p:
if p[i] == 1:
return i | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
ones = twos = 0
for i in range(N):
twos |= ones & arr[i]
ones ^= arr[i]
comm = ~(ones & twos)
ones &= comm
twos &= comm
return ones | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, a, n):
d = {}
for i in range(n):
if a[i] not in d.keys():
d[a[i]] = 1
else:
d[a[i]] += 1
for i in d.keys():
if d[i] == 1:
return i | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER RETURN VAR |
Given an array of integers arr[] of length N, every element appears thrice except for one which occurs once.
Find that element which occurs once.
Example 1:
Input:
N = 4
arr[] = {1, 10, 1, 1}
Output:
10
Explanation:
10 occurs once in the array while the other
element 1 occurs thrice.
Example 2:
Input:
N = 10
arr[] = {3... | class Solution:
def singleElement(self, arr, N):
return (3 * sum(set(arr)) - sum(arr)) // 2
sums = [0] * 32
for a in arr:
for i in range(32):
if a >> i & 1:
sums[i] = (sums[i] + 1) % 3
output = 0
for i, b in enumerate(sums):
... | CLASS_DEF FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | def bit_count(N):
t = 0
while N > 0:
d = N % 2
N = int(N / 2)
if d == 1:
t += 1
return t
class Solution:
def ncr(self, n, r):
if r > n:
return 0
if r == 0 or r == n:
return 1
if self.cache[n][r] != -1:
ret... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMB... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
def fact(self, n):
res = 1
for i in range(2, n + 1):
res *= i
return res
def combi(self, n, r):
if n == 0 or n < r:
return 0
return self.fact(n) / self.fact(r) / self.fact(n - r)
def count(self, N):
st = bin(N)[2:]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIG... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | import sys
sys.setrecursionlimit(10**8)
class Solution:
def count(self, N):
def fact(num):
if num == 1 or num == 0:
return 1
return num * fact(num - 1)
ans = 0
binary = str(bin(N))[2:]
n = len(binary)
count_one = 0
for i i... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER FOR ... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
def nCr(self, n, r):
if r > n:
return 0
p = 1
for i in range(r):
p = p * n
n -= 1
q = r
for i in range(q):
p = p // r
r -= 1
return p
def count(self, N):
ones = 0
c = 0
... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBE... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
def count(self, N):
ones, res = 0, 0
for i in range(40):
if N & 1 == 1:
ones += 1
res += self.C(i, ones)
N >>= 1
return res
def C(self, n, r):
if n < r:
return 0
if n == r or r == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_O... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
def comb(self, n, r):
if r > n:
return 0
if n == 0:
return 0
if r == 0:
return 1
if r == 1:
return n
if r > n - r:
r = n - r
ans = 1
for i in range(1, r + 1):
ans *= n - r... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
cache = [([-1] * 40) for _ in range(40)]
def count(self, N):
ones, res = 0, 0
for i in range(40):
if N & 1 == 1:
ones += 1
res += self.C(i, ones)
N >>= 1
return res
def C(self, n, r):
if n < r:
... | CLASS_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RE... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
def count(self, N):
def c(n, r):
if r > n:
return 0
res = 1
for i in range(r):
res *= n - i
res /= i + 1
return res
i = 0
ans = 0
cnt = 0
while N:
if... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
def csb(self, n):
count = 0
while n > 0:
n &= n - 1
count += 1
return count
def ncr(self, n, r):
if n < r:
return 0
res = 1
for i in range(r):
res *= n - i
res //= i + 1
return r... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF BIN_O... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
def ncr(self, n, r):
if r > n:
return 0
if r == 0 or r == n:
return 1
if self.cache[n][r] != -1:
return self.cache[n][r]
res = self.ncr(n - 1, r - 1) + self.ncr(n - 1, r)
self.cache[n][r] = res
return res
def c... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL V... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
def count(self, N):
dp = [([-1] * 64) for i in range(64)]
def solve(spots, ones):
if ones > spots:
return 0
if ones == 0 or ones == spots:
return 1
if dp[spots][ones] != -1:
return dp[spots][ones]
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR R... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | import sys
sys.setrecursionlimit(100000)
class Solution:
def count(self, N):
def nCr(n, r):
if r > n:
return 0
ans = 1
for i in range(r):
ans *= n - i
ans /= i + 1
return int(ans)
if N == 1:
... | IMPORT EXPR FUNC_CALL VAR NUMBER CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUM... |
Shreyansh has an integer N. He is really curious about the binary representation of integers. He sees that any given integer has a number of set bits. Now he wants to find out that how many positive integers, strictly less than N, have the same number of set bits as N.
He is a little weak in maths. Help him find the nu... | class Solution:
def fact(self, n):
if n == 0:
return 1
return n * self.fact(n - 1)
def count(self, N):
r = 0
i = 0
ans = 0
while N != 0:
if N & 1 == 1:
r += 1
if i == 0:
ans = 0
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.