description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = list(map(int, input().split()))
ans = []
def myrec(dig):
a = 1
if dig == 0:
return
while a <= dig:
a *= 2
a //= 2
dig -= a
ans.append(a)
myrec(dig)
myrec(n)
ans.sort(reverse=True)
i = 0
while len(ans) < k and i <= len(ans) - 1:
if ans[i] == 1:
i += 1
continue
ans.append(ans[i] // 2)
ans[i] = ans[i] // 2
if len(ans) != k:
print("NO")
else:
print("YES")
print(" ".join(map(str, ans))) | 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 RETURN WHILE VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
now = 2**30
nn = 30
ans = []
while now > n:
nn -= 1
now //= 2
ans.append(now)
n -= now
k -= 1
if k == 0 and n == 0:
print("YES")
print(ans[0])
else:
while n != 0:
while now > n:
nn -= 1
now //= 2
n -= now
ans.append(now)
k -= 1
if k < 0:
print("NO")
else:
ans.sort()
nini = len(ans) - 1
dopi_ans = []
while k != 0:
while ans[nini] <= 1:
dopi_ans.append(ans.pop(nini))
nini -= 1
if nini < 0:
break
if nini < 0:
break
alfa = ans.pop(nini)
ans.append(alfa // 2)
ans.append(alfa // 2)
k -= 1
nini = len(ans) - 1
if nini < 0:
print("NO")
else:
print("YES")
print(" ".join(map(str, ans + dopi_ans))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, kk = map(int, input().split())
bn = str(bin(n))[2:]
if bn.count("1") > kk or n < kk:
print("NO")
else:
k = [0] * 50
k[0] = n
s = n
i = 0
while 1:
if s <= kk:
break
if s - k[i] // 2 < kk:
k[i + 1] = s - kk
k[i] -= (s - kk) * 2
break
else:
s -= k[i] // 2
k[i + 1] = k[i] // 2
k[i] -= k[i] - k[i] % 2
i += 1
print("YES")
c = 0
for i in k:
if i != 0:
print((str(2**c) + " ") * i, end="")
c += 1 | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR STRING VAR STRING VAR NUMBER |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | MOD = 10**9 + 7
I = lambda: list(map(int, input().split()))
l = []
i = 0
while 2**i <= 10**9:
l.append(2**i)
i += 1
n, k = I()
res = []
temp = n
for i in reversed(l):
while k > 0 and n - i >= k - 1:
res.append(i)
n -= i
k -= 1
if sum(res) != temp:
print("NO")
else:
print("YES")
print(*res) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | def solve(n, k):
arr = [(1) for i in range(k)]
sm = k
i = k - 1
while i >= 0:
while sm + arr[i] <= n:
sm += arr[i]
arr[i] *= 2
i -= 1
return arr
n, k = map(int, input().split())
res = solve(n, k)
if sum(res) == n:
print("YES")
print(*res)
else:
print("NO") | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
h = [int(_) for _ in bin(n)[2:]]
plz = list(reversed(h))
options = []
i = 0
for char in range(len(plz)):
if plz[char] == 1:
options.append(2**char)
if len(options) > k:
print("NO")
else:
while len(options) < k:
try:
if options[i] != 1:
half = options[i] / 2
del options[i]
options.append(half)
options.append(half)
else:
i += 1
except IndexError:
print("NO")
break
if len(options) == k:
print("YES")
printable = list(map(str, map(int, options)))
print(" ".join(printable)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING WHILE FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | entrada = input().split(" ")
n = int(entrada[0])
k = int(entrada[1])
lista = [1] * k
total = k
for i in range(k - 1, -1, -1):
while total + lista[i] <= n:
total = total + lista[i]
lista[i] = lista[i] * 2
if total != n:
print("NO")
else:
print("YES")
print(*lista, sep=" ") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
s = [i for i in bin(n)[2:]]
if n < k or s.count("1") > k:
print("NO")
else:
print("YES")
L = []
for i in range(31):
L.append(2**i)
a = []
for i in reversed(range(31)):
while k > 0 and n - L[i] >= k - 1:
a.append(L[i])
k -= 1
n -= L[i]
print(*a) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | t, k = input().split()
t = int(t)
k = int(k)
a = []
b = []
l = 0
if k > t:
print("NO")
else:
j = 0
while t > 0:
if t % 2 == 1:
a.append(2**j)
l += 1
t //= 2
j += 1
if k < l:
print("NO")
else:
while 1:
if len(a) == k:
break
if a[0] == 1:
a.remove(1)
b.append(1)
k -= 1
else:
x = a[0] // 2
a.remove(a[0])
a.append(x)
a.append(x)
print("YES")
print(*b, *a) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING WHILE NUMBER IF FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
if k > n:
print("NO")
else:
a = []
f = n
summ = 0
i = 0
while n != 0:
if n % 2 != 0:
a.append(i)
n //= 2
i += 1
if len(a) > k:
print("NO")
else:
a.sort()
c = dict()
for i in a:
if i in c:
c[i] += 1
else:
c[i] = 1
summ = len(a)
while summ != k:
if c[max(c.keys())] == 0:
c.pop(max(c.keys()))
else:
summ += 1
x = max(c.keys())
c[max(c.keys())] -= 1
if x - 1 in c:
c[x - 1] += 2
else:
c[x - 1] = 2
a = []
for i in c.keys():
for j in range(c[i]):
a.append(i)
a.sort()
print("YES")
x = 2 ** a[0]
print(x, end=" ")
for i in range(1, len(a)):
for i in range(a[i] - a[i - 1]):
x *= 2
print(x, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, m = map(int, input().split())
b = bin(n)[2:]
j = b.count("1")
if j <= m <= n:
print("YES")
else:
exit(print("NO"))
heap = []
t = 0
for i in b[::-1]:
if i == "1":
heap.append(int(2**t))
t += 1
heap.sort()
p = 0
if heap[0] == 1:
heap = heap[1:]
m = m - 1
p = 1
while len(heap) != m:
while len(heap) != m and heap[-1] != 1:
t = heap.pop()
t = t // 2
if t == 1:
m = m - 2
p = p + 2
else:
heap = heap + [t] + [t]
heap += [1] * p
print(*heap) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR LIST VAR LIST VAR VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | def pr(d):
print("YES")
for k in d:
for _ in range(d[k]):
print(2**k, end=" ")
n, k = map(int, input().split())
d = {}
for p, v in enumerate(bin(n)[:1:-1]):
d[p] = int(v)
b = sum(d.values())
i = max(d.keys())
if k > n or k < b:
print("NO")
else:
while b < k:
if d[i]:
d[i - 1] += 2
d[i] -= 1
b += 1
else:
i -= 1
pr(d) | FUNC_DEF EXPR FUNC_CALL VAR STRING FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
i = 0
s = bin(n)[2:][::-1]
d = {}
while pow(2, i) <= 10**9:
d[pow(2, i)] = 0
i += 1
p = -1
c = 0
flag = 0
for i in range(len(s)):
if s[i] == "1":
d[pow(2, i)] = 1
c += 1
p = i
m = 0
for i in d.items():
m += i[1]
x = d.items()
x = sorted(x, key=lambda y: y[0])
x = [list(i) for i in x]
while m < k:
while p > 0 and x[p][1] > 0 and m < k:
m += 1
x[p - 1][1] += 2
x[p][1] -= 1
if p == 0 and m < k:
flag = 1
break
p -= 1
if c > k:
print("NO")
elif flag == 1:
print("NO")
else:
s = ""
print("YES")
for i in x:
if i[1] > 0:
for _ in range(i[1]):
print(i[0], end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT WHILE FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR WHILE VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | def output_successful_answer(count):
print("YES")
power = 1
for i in range(len(count) - 1, -1, -1):
while count[i] > 0:
print(power, end=" ")
count[i] -= 1
power *= 2
print()
def get_ans(count, total_powers, k, i):
while total_powers < k and i + 1 < len(count):
if count[i] >= 1:
count[i + 1] += 2
count[i] -= 1
total_powers += 1
while total_powers < k and count[i] >= 1:
count[i + 1] += 2
count[i] -= 1
total_powers += 1
i += 1
return total_powers
n, k = map(int, input().split())
count = list(map(int, list(bin(n)[2:])))
total_powers = get_ans(count, sum(count), k, 0)
if total_powers == k:
output_successful_answer(count)
else:
print("NO") | FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF WHILE VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN 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 VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | def mlt():
return map(int, input().split())
x, y = mlt()
if x == y:
print("YES")
print("1 " * x)
exit(0)
s = []
pw = 0
v = x
while x:
if x % 2:
s.append(1 << pw)
pw += 1
x //= 2
if y > v or y < len(s):
print("NO")
exit(0)
res = []
s.reverse()
cur = -1
n = 0
while n < len(s):
if s[n] > y:
break
if s[n] <= y:
rem = len(s) - n - 1
if rem + s[n] >= y:
cur = s[n]
break
else:
y -= s[n]
res += [1] * s[n]
n += 1
cr = [s[n]]
y -= len(s[n + 1 :]) + 1
res += s[n + 1 :]
ind = 0
tm = y
while y:
cur = cr[ind]
cr.append(cur // 2)
cr.append(cur // 2)
y -= 1
ind += 1
cr.reverse()
res += cr[: tm + 1]
print("YES")
print(*res) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP LIST NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = [int(x) for x in input().split()]
b = bin(n)[2:][::-1]
if b.count("1") > k or k > n:
print("NO")
else:
nums = []
ans = ""
for i in range(len(b)):
if b[i] == "1":
nums.append(2**i)
_k = 0
while _k + len(nums) < k:
num = nums.pop()
if num == 1:
ans += "1 "
_k += 1
else:
num = num // 2
nums.append(num)
nums.append(num)
for n in nums:
ans += str(n) + " "
print("YES")
print(ans[: len(ans) - 1]) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
a = bin(n)[2:]
c = 0
l = []
for i in range(len(a)):
if a[i] == "1":
c += 1
l.append(pow(2, len(a) - i - 1))
if c == k:
print("YES")
s = ""
for i in l:
s += str(i) + " "
print(s)
elif c < k:
i = 0
while c != k and i < len(l):
a = l[i] // 2
if a != 0:
l[i] = a
l.insert(i, a)
c += 1
else:
i += 1
if c == k:
print("YES")
s = ""
for i in l:
s += str(i) + " "
print(s)
else:
print("NO")
else:
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = [int(x) for x in input().split()]
if n < k:
print("NO")
else:
p = []
t = n
i = 1
j = 0
while t != 0:
if t & i != 0:
p.append(2**j)
t = t & t - 1
j += 1
i <<= 1
if len(p) > k:
print("NO")
else:
print("YES")
i = 0
diff = k - len(p)
while diff != 0:
if p[i] == 1:
i += 1
continue
p[i] //= 2
p.append(p[i])
diff -= 1
p = map(str, p)
print(" ".join(p)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
b = bin(n)[2:][::-1]
t = b.count("1")
if k < t:
print("NO")
exit(0)
s, i = [], 1
for j in b:
if j == "1":
s.append(i)
i *= 2
j = len(s) - 1
ans = []
while k - t > 0:
if s[j] != 1:
s[j] //= 2
s.append(s[j])
t += 1
j += 1
elif j == 0:
break
else:
ans.append(str(s[j]))
del s[j]
j -= 1
print("YES\n" + " ".join(map(str, ans + s)) if len(s) + len(ans) == k else "NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR LIST NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST WHILE BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP VAR VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | def solve():
n, k = [int(i) for i in input().split(" ")]
a = [1] * k
s = k
for i in range(k):
while s + a[i] <= n:
s += a[i]
a[i] *= 2
if s != n:
return "NO"
o = "YES\n"
o += " ".join(str(i) for i in a)
return o
print(solve()) | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN STRING ASSIGN VAR STRING VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = list(map(int, input().split()))
x = []
ones = 0
while n:
if n % 2 == 0:
x.append(0)
else:
x.append(1)
ones += 1
n = int(n / 2)
x.reverse()
n = ones
if n > k:
print("NO")
else:
for i in range(len(x)):
if n == k:
break
if x[i] != 0 and i + 1 < len(x):
if n + x[i] <= k:
n += x[i]
x[i + 1] += 2 * x[i]
x[i] = 0
else:
x[i] -= k - n
x[i + 1] += 2 * (k - n)
n = k
if n != k:
print("NO")
else:
print("YES")
for i in range(0, len(x)):
while x[i] != 0:
print(pow(2, len(x) - 1 - i), end=" ")
x[i] -= 1 | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING VAR VAR NUMBER |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | a, b = map(int, input().split())
c = 0
s = str(bin(a))[2:][::-1]
lol = []
for i in range(len(s)):
if s[i] == "1":
lol.append(pow(2, i))
c += 1
if b > a or b < c:
print("NO")
else:
k = b - c
while len(lol) < b:
yo = []
for i in range(len(lol)):
if lol[i] > 1:
yo.append(lol[i] // 2)
yo.append(lol[i] // 2)
k -= 1
else:
yo.append(lol[i])
if k == 0:
for j in range(i + 1, len(lol)):
yo.append(lol[j])
break
lol = yo[:]
print("YES")
print(*lol) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = [int(i) for i in input().split()]
a = [0] * 33
c = 0
for i in range(33):
if n >> i & 1 == 1:
a[i] += 1
c += 1
if c > k:
print("NO")
else:
pos = 32
while c < k and pos > 0:
if a[pos] == 0:
pos -= 1
continue
c += 1
a[pos] -= 1
a[pos - 1] += 2
if c != k:
print("NO")
else:
print("YES")
for i in range(33):
for j in range(a[i]):
print(1 << i, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
twolist = [1]
indexStart = 0
for i in range(1, 30):
twolist.append(twolist[-1] * 2)
if twolist[-1] <= n:
indexStart = i
remainSum = n
ans = []
while remainSum > 0:
if twolist[indexStart] <= remainSum:
ans.append(twolist[indexStart])
remainSum -= twolist[indexStart]
else:
indexStart -= 1
if len(ans) > k or k > n:
print("NO")
else:
rmk = len(ans)
ir = 0
while ir < rmk and rmk < k:
if ans[ir] == 1:
ir += 1
continue
hf = int(ans[ir] / 2)
ans[ir] = hf
ans.append(hf)
rmk += 1
print("YES")
print(" ".join(map(str, ans))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | x, y = map(int, input().split())
a = 0
b = 0
ind = 0
s = []
while x > 0:
if x % 2 == 1:
a += 1
b += 1 << ind
s.append(1 << ind)
x >>= 1
ind += 1
if y < a or y > b:
print("NO")
exit(0)
if x == y:
print("YES")
for n in range(x):
print(1, end=" ")
exit(0)
s.reverse()
n = 0
res = []
while s[n] < y:
y -= s[n]
res += [1] * s[n]
n += 1
res += s[n + 1 :]
y -= len(s) - (n + 1)
cnt = [0, s[n]]
k = 1
dgt = 1
while dgt < y:
cnt.append(cnt[k] // 2)
cnt.append(cnt[k] // 2)
k += 1
dgt += 1
if dgt == y:
break
cnt.append(cnt[k] // 2)
cnt.append(cnt[k] // 2)
k += 1
dgt += 1
cnt.reverse()
for n in range(y):
res.append(cnt[n])
print("YES")
print(*res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR VAR VAR VAR BIN_OP LIST NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | inp = input().split()
n = int(inp[0])
k = int(inp[1])
a = []
cc = 0
ck = k
while n != 0:
a.append(n % 2)
cc += n % 2
n //= 2
a = a[::-1]
if k < cc:
print("NO")
else:
k -= cc
for i in range(len(a) - 1):
if a[i] > 0:
temp2 = min(k, a[i])
a[i] -= temp2
a[i + 1] += temp2 * 2
k -= temp2
if k <= 0:
break
if k < 0 or k > 0:
print("NO")
else:
print("YES")
s = []
for i in range(len(a)):
for j in range(a[i]):
s.append(str(2 ** (len(a) - i - 1)))
s = s[::-1]
print(" ".join(s)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | import sys
input = sys.stdin.readline
def swaparr(arr, a, b):
temp = arr[a]
arr[a] = arr[b]
arr[b] = temp
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def nCr(n, k):
if k > n - k:
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
def upper_bound(a, x, lo=0):
hi = len(a)
while lo < hi:
mid = (lo + hi) // 2
if a[mid] < x:
lo = mid + 1
else:
hi = mid
return lo
def primefs(n):
primes = {}
while n % 2 == 0 and n > 0:
primes[2] = primes.get(2, 0) + 1
n = n // 2
for i in range(3, int(n**0.5) + 2, 2):
while n % i == 0 and n > 0:
primes[i] = primes.get(i, 0) + 1
n = n // i
if n > 2:
primes[n] = primes.get(n, 0) + 1
return primes
def power(x, y, p):
res = 1
x = x % p
if x == 0:
return 0
while y > 0:
if y & 1 == 1:
res = res * x % p
y = y >> 1
x = x * x % p
return res
def swap(a, b):
temp = a
a = b
b = temp
return a, b
def find(x, link):
p = x
while p != link[p]:
p = link[p]
while x != p:
nex = link[x]
link[x] = p
x = nex
return p
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x, y = swap(x, y)
if x != y:
size[x] += size[y]
link[y] = x
def sieve(n):
prime = [(True) for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p] == True:
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
return prime
MAXN = int(1000000.0 + 5)
def spf_sieve():
spf[1] = 1
for i in range(2, MAXN):
spf[i] = i
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, ceil(MAXN**0.5), 2):
if spf[i] == i:
for j in range(i * i, MAXN, i):
if spf[j] == j:
spf[j] = i
def factoriazation(x):
ret = {}
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1
x = x // spf[x]
return ret
def int_array():
return list(map(int, input().strip().split()))
def str_array():
return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float("inf")
NINF = -float("inf")
n, k = int_array()
binary = bin(n).replace("0b", "")
if binary.count("1") > k or k > n:
print("NO")
else:
this = sorted(
[(2 ** (len(binary) - i - 1)) for i in range(len(binary)) if binary[i] == "1"]
)
ones = 0
while len(this) + ones != k:
if this[-1] == 1:
this.pop()
ones += 1
else:
x = this[-1]
if k - (len(this) - 1) - ones >= x:
this.pop()
ones += x
else:
this.pop()
this.append(x // 2)
this.append(x // 2)
this += [1] * ones
print("YES")
print(*this) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR DICT WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING IF FUNC_CALL VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
l = []
while n >= 1:
l.append(n % 2)
n = n // 2
p = []
for i in range(len(l)):
if l[i] != 0:
p.append(2**i * l[i])
c = 0
pl = len(p)
if pl > k:
c = -1
else:
y = 1
cn = 0
k = k - pl
fg = 0
while k > 0:
if y > pl:
c = -1
break
if p[-1] <= k:
cn = cn + p[-1]
k = k - p[-1] + 1
p.pop(-1)
y += 1
else:
a = -1
k = k + 1
t = k
while k >= 1:
a += 1
k = k // 2
a = 2**a
h1 = 2 * a - t
g1 = p[-1] // a
h2 = 2 * (t - a)
g2 = g1 // 2
p.pop(-1)
fg = 1
break
if c == -1:
print("NO")
else:
print("YES", end="\n")
if fg == 1:
for i in range(h1):
p.append(g1)
for i in range(h2):
p.append(g2)
p.sort()
for i in range(cn):
print(1, end=" ")
for i in range(len(p)):
print(p[i], end=" ")
print() | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
n, k = mi()
if k < bin(n).count("1") or k > n:
print("NO")
else:
ans = []
cur = bin(n).count("1")
for i in range(30):
if n >> i & 1:
st = [1 << i]
while cur < k and st:
r = st.pop()
if r == 1:
ans.append(r)
continue
st.append(r >> 1)
st.append(r >> 1)
cur += 1
ans.extend(st)
print("YES")
print(*ans) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST BIN_OP NUMBER VAR WHILE VAR VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | import sys
n, k = map(int, sys.stdin.readline().split())
def find(n, k):
pow = 0
tmp_two = 1
two = []
while tmp_two <= 10**9:
pow += 1
two.append(tmp_two)
tmp_two = 2**pow
if k > n:
return "NO"
else:
numbers = {}
for t in two:
numbers[t] = 0
mx_pos = 0
min_nums = 0
while mx_pos != -1:
mx_pos = -1
while mx_pos < len(two) - 1:
if two[mx_pos + 1] <= n:
mx_pos += 1
else:
break
if mx_pos != -1:
n -= two[mx_pos]
numbers[two[mx_pos]] += 1
min_nums += 1
if min_nums > k:
return "NO"
else:
change = len(two) - 1
while min_nums < k:
while numbers[two[change]] == 0:
change -= 1
numbers[two[change]] -= 1
numbers[two[change - 1]] += 2
if change <= 0:
return "NO"
min_nums += 1
ret_nums = []
for n in numbers:
ret_nums = ret_nums + [n] * numbers[n]
ret_nums = [str(x) for x in ret_nums]
return "YES\n" + " ".join(ret_nums)
print(numbers)
print(two)
print(find(n, k)) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR RETURN STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER RETURN STRING VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP STRING FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
Bin = [0] * 32
One = i = 0
while n > 0:
if n % 2 == 1:
Bin[i] = 1
One += 1
i += 1
n //= 2
if One > k:
print("NO")
exit()
for i in range(31, 0, -1):
if One == k:
break
if Bin[i] >= 1:
while Bin[i] != 0 and One < k:
Bin[i] -= 1
Bin[i - 1] += 2
One += 1
if One < k:
print("NO")
exit()
print("YES")
res = []
for i in range(31):
while Bin[i] > 0:
res.append(str(1 << i))
Bin[i] -= 1
print(" ".join(res)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR IF VAR VAR NUMBER WHILE VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = [int(i) for i in input().split()]
s = bin(n)
stack = []
j = 0
for i in reversed(s):
if i == "1":
stack.append(2**j)
j += 1
if len(stack) > k or n < k:
print("NO")
exit(0)
ones = 0
while len(stack) != k - ones:
while True:
tmp = stack.pop()
if tmp != 1:
break
else:
ones += 1
stack.append(tmp // 2)
stack.append(tmp // 2)
print("YES")
print(*[(1) for i in range(ones)], end=" ")
print(*stack) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | N, K = [int(x) for x in input().split()]
binary = list(bin(N))
binary = binary[2:]
binary.reverse()
checker = []
for i in range(len(binary)):
if binary[i] == "1":
checker.append(2**i)
if binary.count("1") > K or N < K:
print("NO")
exit()
else:
x = 0
counter = len(checker)
if counter == K:
print("YES")
print(*checker)
exit()
while True:
while checker[x] % 2 == 0:
checker[x] = checker[x] // 2
checker.append(checker[x])
counter += 1
if counter == K:
print("YES")
print(*checker)
exit()
x += 1 | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR WHILE NUMBER WHILE BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split(" "))
s = []
if n < k:
print("NO")
else:
while n > 0:
s.append(int(n % 2))
n = int(n / 2)
if k < sum(s):
print("NO")
else:
print("YES")
for i in range(len(s)):
while s[len(s) - i - 1] != 0:
if sum(s) == k:
break
s[len(s) - i - 1] -= 1
s[len(s) - i - 2] += 2
else:
continue
break
ans = []
for i in range(len(s)):
while s[i] != 0:
ans.append(2**i)
s[i] -= 1
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, u = map(int, input().split())
jj = u
k = str(bin(n))
k = k[2:]
lis = []
for i in range(len(k)):
if k[i] == "1":
lis.append(2 ** (len(k) - i - 1))
if len(lis) > u:
print("NO")
exit()
u = u - len(lis)
i = 0
while u > 0 and len(lis) > i:
if lis[i] == 1:
i = i + 1
else:
lis[i] = int(lis[i] / 2)
lis.append(lis[i])
u = u - 1
lis.sort()
if len(lis) == jj:
for x in range(len(lis)):
lis[x] = str(int(lis[x]))
print("YES")
print(" ".join(lis))
else:
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
if k > n:
print("NO")
elif k == n:
print("YES")
for i in range(n):
print("1", end=" ")
print()
else:
pows = [0] * 30
l = i = 0
nc = n
while nc > 0:
pows[i] = nc % 2
l += pows[i]
nc //= 2
i += 1
if k < l:
print("NO")
else:
for i in range(29, 0, -1):
if l < k:
while pows[i] > 0 and l < k:
pows[i] -= 1
pows[i - 1] += 2
l += 1
else:
break
m = 1
print("YES")
for i in range(30):
for j in range(pows[i]):
print(m, end=" ")
m *= 2
print() | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR WHILE VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
m = bin(n)
m = m[2:]
if m.count("1") > k:
print("NO")
elif m.count("1") == k:
print("YES")
for i in range(len(m)):
if m[i] == "1":
print(2 ** (len(m) - 1 - i), end=" ")
else:
a = [0] * (len(m) + 1)
for i in range(len(m)):
a[i] = int(m[len(m) - i - 1])
cnt = m.count("1")
for i in range(len(a) - 1, 0, -1):
l = min(a[i], k - cnt)
cnt += l
a[i - 1] += 2 * l
a[i] -= l
if cnt < k:
print("NO")
else:
print("YES")
for i in range(len(a)):
while a[i] > 0:
print(2**i, end=" ")
a[i] -= 1 | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR STRING VAR VAR NUMBER |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
if k > n:
print("NO")
exit()
nb = bin(n)[-1:1:-1]
ans = {}
c = 0
for i in range(len(nb)):
if nb[i] == "1":
if nb[i] not in ans:
ans[2**i] = 1
else:
ans[2**i] += 1
c += 1
if k < c:
print("NO")
exit()
while c != k:
for i, j in ans.items():
if i != 1 and j != 0:
ans[i] -= 1
if i // 2 not in ans:
ans[i // 2] = 2
else:
ans[i // 2] += 2
break
c += 1
print("YES")
for k, v in ans.items():
for _ in range(v):
print(k, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | xs = list(map(int, input().split(" ")))
b = bin(xs[0])[2:]
k = xs[1]
r = b.count("1")
ks = []
for i, q in enumerate(reversed(list(b))):
if q == "1":
ks.append(i)
if k < len(ks):
print("NO")
else:
stack = ks
ans = []
p = 0
q = len(ks)
while q < xs[1] and len(stack) > 0:
x = stack.pop()
if x == 0:
ans.append(0)
else:
stack.append(x - 1)
stack.append(x - 1)
q += 1
if q != k:
print("NO")
else:
ans = ans + stack
ans = " ".join(list(map(lambda x: str(2**x), ans)))
print("YES")
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
binN = list(map(int, bin(n)[2:]))
c = binN.count(1)
if k < c or k > n:
print("NO")
else:
i = 0
while i < len(binN) - 1 and c < k:
while binN[i] > 0 and c < k:
c = c + 1
binN[i] = binN[i] - 1
binN[i + 1] = binN[i + 1] + 2
i = i + 1
i = len(binN) - 1
output = []
while i >= 0:
while binN[i] > 0:
output.append(2 ** (len(binN) - i - 1))
binN[i] = binN[i] - 1
i = i - 1
print("YES")
print(" ".join(map(str, output))) | 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 NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR WHILE VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | def main():
a = input()
n, k = [int(i) for i in a.split(" ")]
if k > n:
print("NO")
return
c = [0] * 30
cnt = 0
for i in range(30):
if n & 1 << i != 0:
c[i] += 1
cnt += 1
if cnt > k:
print("NO")
return
print("YES")
k -= cnt
for i in range(29, 0, -1):
while k > 0 and c[i] > 0:
k -= 1
c[i] -= 1
c[i - 1] += 2
res = ""
for i in range(29, -1, -1):
while c[i] > 0:
c[i] -= 1
res += str(1 << i) + " "
print(res)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER WHILE VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, k = map(int, input().split())
if k > n:
print("NO")
else:
b = bin(n)[2:]
if b.count("1") == k:
b = b[::-1]
print("YES")
for i in range(len(b)):
if b[i] == "1":
print(1 << i, end=" ")
print("")
elif b.count("1") < k:
l = []
x = -1
b = b[::-1]
for i in range(len(b)):
if b[i] == "1":
l.append(1 << i)
k -= len(l)
for i in l:
x += 1
if k <= 0:
break
if i != 1:
i //= 2
k -= 1
l += [i] * 2
l[x] = 0
if k == 0:
l.sort()
print("YES")
for i in l:
if i != 0:
print(i, end=" ")
print()
else:
print("NO")
else:
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP LIST VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | import sys
n, k = map(int, input().split())
m = bin(n)[2:]
m = [int(i) for i in m]
def val(a):
l = len(a)
x = 0
p = 1
for i in range(l):
x += a[i] * p
p *= 2
return x
while True:
if sum(m) == k:
print("YES")
m = m[::-1]
x = 1
for i in m:
for j in range(i):
print(x, end=" ")
x *= 2
print()
sys.exit(0)
else:
l = len(m)
f = 0
x = sum(m)
for i in range(l - 1):
while m[i] > 0:
m[i] -= 1
m[i + 1] += 2
f = 1
x += 1
if x == k:
break
if x == k:
break
if f == 0:
print("NO")
sys.exit(0) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR WHILE NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER |
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, ....
You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.
Input
The only line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 2 β
10^5).
Output
If it is impossible to represent n as the sum of k powers of two, print NO.
Otherwise, print YES, and then print k positive integers b_1, b_2, ..., b_k such that each of b_i is a power of two, and β _{i = 1}^{k} b_i = n. If there are multiple answers, you may print any of them.
Examples
Input
9 4
Output
YES
1 2 2 4
Input
8 1
Output
YES
8
Input
5 1
Output
NO
Input
3 7
Output
NO | n, x = map(int, input().split())
v = n
l = []
i = 0
for k in range(32):
if (n & 1 << k) >> k:
l.append(pow(2, k))
x -= len(l)
if x < 0:
print("NO")
else:
i = 0
while x > 0:
while i < len(l) and l[i] == 1:
i += 1
if i == len(l):
print("NO")
exit()
l[i] //= 2
l.insert(i, l[i])
x -= 1
l = list(map(str, l))
print("YES")
print(" ".join(l)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Sereja has an n Γ m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a component form a rectangle of size h Γ w, then the component must contain exactly hw cells.
A connected component of the same values is a set of cells of the table that meet the following conditions: every two cells of the set have the same value; the cells of the set form a connected region on the table (two cells are connected if they are adjacent in some row or some column of the table); it is impossible to add any cell to the set unless we violate the two previous conditions.
Can Sereja change the values of at most k cells of the table so that the table met the described requirement? What minimum number of table cells should he change in this case?
-----Input-----
The first line contains integers n, m and k (1 β€ n, m β€ 100;Β 1 β€ k β€ 10). Next n lines describe the table a: the i-th of them contains m integers a_{i}1, a_{i}2, ..., a_{im} (0 β€ a_{i}, j β€ 1) β the values in the cells of the i-th row.
-----Output-----
Print -1, if it is impossible to meet the requirement. Otherwise, print the minimum number of cells which should be changed.
-----Examples-----
Input
5 5 2
1 1 1 1 1
1 1 1 1 1
1 1 0 1 1
1 1 1 1 1
1 1 1 1 1
Output
1
Input
3 4 1
1 0 0 0
0 1 1 1
1 1 1 0
Output
-1
Input
3 4 1
1 0 0 1
0 1 1 0
1 0 0 1
Output
0 | read_line = lambda: [int(i) for i in input().split()]
n, m, k = read_line()
a = [read_line() for i in range(n)]
if n < m:
n, m, a = m, n, list(zip(*a))
xs = []
for y in a:
x = 0
for b in y:
x = 2 * x + b
xs.append(x)
def work(y):
tot = 0
for x in xs:
c = bin(x ^ y).count("1")
tot += min(c, m - c)
return tot
ans = min(list(map(work, xs if m > k else list(range(1 << m)))))
print(ans if ans <= k else -1) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER |
You've got a string $S$ consisting of $n$ lowercase English letters from your friend. It turned out that this is a number written in poman numerals. The poman numeral system is long forgotten. All that's left is the algorithm to transform number from poman numerals to the numeral system familiar to us. Characters of $S$ are numbered from $1$ to $n$ from left to right. Let's denote the value of $S$ as $f(S)$, it is defined as follows:
If $|S| > 1$, an arbitrary integer $m$ ($1 \le m < |S|$) is chosen, and it is defined that $f(S) = -f(S[1, m]) + f(S[m + 1, |S|])$, where $S[l, r]$ denotes the substring of $S$ from the $l$-th to the $r$-th position, inclusively.
Otherwise $S = c$, where $c$ is some English letter. Then $f(S) = 2^{pos(c)}$, where $pos(c)$ is the position of letter $c$ in the alphabet ($pos($a$) = 0$, $pos($z$) = 25$).
Note that $m$ is chosen independently on each step.
Your friend thinks it is possible to get $f(S) = T$ by choosing the right $m$ on every step. Is he right?
-----Input-----
The first line contains two integers $n$ and $T$ ($2 \leq n \leq 10^5$, $-10^{15} \leq T \leq 10^{15}$).
The second line contains a string $S$ consisting of $n$ lowercase English letters.
-----Output-----
Print "Yes" if it is possible to get the desired value. Otherwise, print "No".
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 -1
ba
Output
Yes
Input
3 -7
abc
Output
No
Input
7 -475391
qohshra
Output
Yes
-----Note-----
In the second example, you cannot get $-7$. But you can get $1$, for example, as follows:
First choose $m = 1$, then $f($abc$) = -f($a$) + f($bc$)$
$f($a$) = 2^0 = 1$
$f($bc$) = -f($b$) + f($c$) = -2^1 + 2^2 = 2$
In the end $f($abc$) = -1 + 2 = 1$ | _, T = [int(x) for x in input().split()]
L = [(ord(x) - ord("a")) for x in input()]
T -= 2 ** L[-1]
T += 2 ** L[-2]
L = L[:-2]
L.sort(reverse=True)
for c in L:
T += (1 if T < 0 else -1) * (1 << c)
print("Yes" if T == 0 else "No") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER STRING STRING |
You've got a string $S$ consisting of $n$ lowercase English letters from your friend. It turned out that this is a number written in poman numerals. The poman numeral system is long forgotten. All that's left is the algorithm to transform number from poman numerals to the numeral system familiar to us. Characters of $S$ are numbered from $1$ to $n$ from left to right. Let's denote the value of $S$ as $f(S)$, it is defined as follows:
If $|S| > 1$, an arbitrary integer $m$ ($1 \le m < |S|$) is chosen, and it is defined that $f(S) = -f(S[1, m]) + f(S[m + 1, |S|])$, where $S[l, r]$ denotes the substring of $S$ from the $l$-th to the $r$-th position, inclusively.
Otherwise $S = c$, where $c$ is some English letter. Then $f(S) = 2^{pos(c)}$, where $pos(c)$ is the position of letter $c$ in the alphabet ($pos($a$) = 0$, $pos($z$) = 25$).
Note that $m$ is chosen independently on each step.
Your friend thinks it is possible to get $f(S) = T$ by choosing the right $m$ on every step. Is he right?
-----Input-----
The first line contains two integers $n$ and $T$ ($2 \leq n \leq 10^5$, $-10^{15} \leq T \leq 10^{15}$).
The second line contains a string $S$ consisting of $n$ lowercase English letters.
-----Output-----
Print "Yes" if it is possible to get the desired value. Otherwise, print "No".
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 -1
ba
Output
Yes
Input
3 -7
abc
Output
No
Input
7 -475391
qohshra
Output
Yes
-----Note-----
In the second example, you cannot get $-7$. But you can get $1$, for example, as follows:
First choose $m = 1$, then $f($abc$) = -f($a$) + f($bc$)$
$f($a$) = 2^0 = 1$
$f($bc$) = -f($b$) + f($c$) = -2^1 + 2^2 = 2$
In the end $f($abc$) = -1 + 2 = 1$ | import sys
input = sys.stdin.readline
n, T = map(int, input().split())
S = input().strip()
L = [(ord(s) - 97) for s in S]
T += pow(2, L[-2]) - pow(2, L[-1])
L = L[:-2]
L.sort(reverse=True)
for i in range(len(L)):
if T > 0:
T -= 1 << L[i]
else:
T += 1 << L[i]
if T == 0:
print("Yes")
else:
print("No") | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You've got a string $S$ consisting of $n$ lowercase English letters from your friend. It turned out that this is a number written in poman numerals. The poman numeral system is long forgotten. All that's left is the algorithm to transform number from poman numerals to the numeral system familiar to us. Characters of $S$ are numbered from $1$ to $n$ from left to right. Let's denote the value of $S$ as $f(S)$, it is defined as follows:
If $|S| > 1$, an arbitrary integer $m$ ($1 \le m < |S|$) is chosen, and it is defined that $f(S) = -f(S[1, m]) + f(S[m + 1, |S|])$, where $S[l, r]$ denotes the substring of $S$ from the $l$-th to the $r$-th position, inclusively.
Otherwise $S = c$, where $c$ is some English letter. Then $f(S) = 2^{pos(c)}$, where $pos(c)$ is the position of letter $c$ in the alphabet ($pos($a$) = 0$, $pos($z$) = 25$).
Note that $m$ is chosen independently on each step.
Your friend thinks it is possible to get $f(S) = T$ by choosing the right $m$ on every step. Is he right?
-----Input-----
The first line contains two integers $n$ and $T$ ($2 \leq n \leq 10^5$, $-10^{15} \leq T \leq 10^{15}$).
The second line contains a string $S$ consisting of $n$ lowercase English letters.
-----Output-----
Print "Yes" if it is possible to get the desired value. Otherwise, print "No".
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 -1
ba
Output
Yes
Input
3 -7
abc
Output
No
Input
7 -475391
qohshra
Output
Yes
-----Note-----
In the second example, you cannot get $-7$. But you can get $1$, for example, as follows:
First choose $m = 1$, then $f($abc$) = -f($a$) + f($bc$)$
$f($a$) = 2^0 = 1$
$f($bc$) = -f($b$) + f($c$) = -2^1 + 2^2 = 2$
In the end $f($abc$) = -1 + 2 = 1$ | n, t = input().split()
n, t = int(n), int(t)
s = list(input())
if n == 1:
if 2 ** (ord(s) - 97) == t:
print("Yes")
else:
print("No")
elif n == 2:
if 2 ** (ord(s[1]) - 97) - 2 ** (ord(s[0]) - 97) == t:
print("Yes")
else:
print("No")
else:
t -= 2 ** (ord(s[-1]) - 97) - 2 ** (ord(s[-2]) - 97)
t = abs(t)
s = s[:-2]
count = [0] * 32
for char in s:
count[ord(char) - 97] += 1
for i in range(30, -1, -1):
for x in range(count[i]):
if t > 0:
t -= 1 << i
else:
t += 1 << i
if t == 0:
print("Yes")
else:
print("No") | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER IF BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | n = int(input())
v = [0] * n
g = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
v[a - 1] += 1
v[b - 1] += 1
for i in range(n):
if v[i] > 1:
p = i
break
s = [p]
d = [-1] * n
d[p] = 0
x = -1
minans = 1
maxans = n - 1
while s:
q = s.pop()
t = 0
for node in g[q]:
if d[node] == -1:
d[node] = d[q] + 1
s.append(node)
if v[node] == 1:
t += 1
if x == -1:
x = d[node] & 1
elif d[node] & 1 != x:
minans = 3
maxans -= max(0, t - 1)
print(minans, maxans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | import sys
input = sys.stdin.readline
graph, leaves = {(i + 1): [] for i in range(int(input()))}, []
dist, queue, second = {(i + 1): (0) for i in range(len(graph))}, [], set()
for _ in range(len(graph) - 1):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
for node in graph:
if len(graph[node]) == 1:
leaves.append(node)
queue.append(1)
while queue:
searching = queue.pop()
for peer in graph[searching]:
if not dist[peer]:
dist[peer] = dist[searching] + 1
queue.append(peer)
if len(set([(dist[node] % 2) for node in leaves])) == 1:
minimum = 1
else:
minimum = 3
for leaf in leaves:
for peer in graph[leaf]:
second.add(peer)
maximum = len(graph) - 1 - len(leaves) + len(second)
print(minimum, maximum) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER LIST VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | n = int(input())
ls = [[] for x in range(n)]
for inp in range(n - 1):
point1, point2 = [(int(x) - 1) for x in input().split()]
ls[point1].append(point2)
ls[point2].append(point1)
bottom = []
e = [0] * n
max_res = n - 1
for i in range(n):
temp = ls[i]
if len(temp) == 1:
if e[temp[0]] == 1:
max_res -= 1
else:
e[temp[0]] = 1
bottom.append(i)
queue = [0]
seen = [-1] * n
seen[0] = 0
while queue:
point = queue.pop()
for i in ls[point]:
if seen[i] == -1:
queue.append(i)
seen[i] = 1 - seen[point]
f = seen[bottom[0]]
for i in bottom:
if seen[i] != f:
min_res = 3
break
else:
min_res = 1
print(min_res, max_res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | import sys
input = sys.stdin.buffer.readline
n = int(input())
childs = [set() for i in range(n + 1)]
marker = [False] * (n + 1)
for i in range(n - 1):
a, b = map(int, input().split())
childs[a].add(b)
childs[b].add(a)
for i in range(1, n + 1):
if len(childs[i]) == 1:
father = list(childs[i])[0]
marker[father] = True
fans = sum(marker) + n - 1 - sum([(len(child) == 1) for child in childs])
has_odd = False
root = None
for i in range(1, n + 1):
if len(childs[i]) == 1:
root = i
break
bfs = [(root, 0, -1)]
while len(bfs):
node, dist, dad = bfs[-1]
bfs.pop()
for child in childs[node]:
if child == dad:
continue
bfs.append((child, dist + 1, node))
if len(childs[node]) == 1 and dad != -1:
has_odd |= dist % 2
print(3 if has_odd else 1, fans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | n = int(input())
g = [[] for x in range(n + 1)]
vis, fMax, lenFlag, leafCount, parent = [([0] * (n + 1)) for x in range(5)]
for i in range(n - 1):
u, v = map(int, input().split())
g[u].append(v)
g[v].append(u)
for i in range(1, n + 1):
if len(g[i]) > 1:
root = i
break
i = 0
q = [root]
vis[root] = 1
while i < len(q):
u = q[i]
i += 1
for v in g[u]:
if not vis[v]:
vis[v] = 1
q.append(v)
parent[v] = u
if len(g[v]) == 1:
leafCount[u] += 1
q.reverse()
for u in q:
fMax[u] -= max(leafCount[u] - 1, 0)
if len(g[u]) == 1:
lenFlag[u] = 2
if u == root:
break
v = parent[u]
if lenFlag[u] == -1 or lenFlag[u] == lenFlag[v]:
lenFlag[v] = -1
elif lenFlag[v] == 0:
lenFlag[v] = 3 - lenFlag[u]
fMax[v] += fMax[u] + 1
if lenFlag[root] == -1:
print(3, end=" ")
else:
print(1, end=" ")
print(fMax[root]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | class Nd:
def __init__(self):
self.link = []
def bind(self, other):
self.link.append(other)
other.link.append(self)
def hang(self):
br = set()
lv = set()
cnt = 0
self.level = 0
self.par = None
que = [self]
while que:
leaf = True
cur = que.pop()
for nd in cur.link:
if nd != cur.par:
nd.level = cur.level + 1
nd.par = cur
que.append(nd)
leaf = False
if leaf:
br.add(cur.par)
lv.add(cur.level % 2)
else:
cnt += 1
print(1 if len(lv) < 2 else 3, cnt + len(br) - 1)
n = int(input())
a = [Nd() for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
a[u - 1].bind(a[v - 1])
for nd in a:
if len(nd.link) > 1:
nd.hang()
break | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR LIST VAR WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | import sys
input = sys.stdin.readline
n = int(input())
g = [[] for i in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
leaf = []
for i in range(n):
if len(g[i]) == 1:
leaf.append(i)
q = [0]
use = [-1] * n
use[0] = 0
while q:
ver = q.pop()
for to in g[ver]:
if use[to] == -1:
use[to] = 1 - use[ver]
q.append(to)
f = use[leaf[0]]
for l in leaf:
if f != use[l]:
MIN = 3
break
else:
MIN = 1
MAX = n - 1
fp = [0] * n
for l in leaf:
for to in g[l]:
if fp[to] == 1:
MAX -= 1
else:
fp[to] = 1
print(MIN, MAX) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | n = int(input().strip())
conns = [set() for i in range(n + 1)]
for i in range(n - 1):
a, b = [int(d) for d in input().strip().split()]
conns[a].add(b)
conns[b].add(a)
even = False
odd = False
for i in range(1, n + 1):
if len(conns[i]) > 1:
first = i
break
q = [(first, -1, 0)]
index = 0
while index < len(q):
node, parent, dist = q[index]
index += 1
if len(conns[node]) == 1:
if dist % 2 == 0:
even = True
else:
odd = True
for c in conns[node]:
if c != parent:
q += [(c, node, dist + 1)]
num_leaves = [(0) for i in range(n + 1)]
for i in range(1, n + 1):
if len(conns[i]) == 1:
for c in conns[i]:
num_leaves[c] += 1
ma = n - 1
for val in num_leaves:
if val > 0:
ma -= val - 1
if even and odd:
mi = 3
else:
mi = 1
print(mi, ma) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int, input().split())) for i in range(n - 1)]
graph = [[] for i in range(n + 1)]
deg = [(0) for i in range(n + 1)]
if n == 3:
print(1, 1)
exit()
for a, b in ab:
graph[a].append(b)
graph[b].append(a)
deg[a] += 1
deg[b] += 1
root = 0
leaf = set()
for i in range(1, n + 1):
if deg[i] >= 2 and not root:
root = i
elif deg[i] == 1:
leaf.add(i)
dist = [(0) for i in range(n + 1)]
stack = [root]
dist[root] = 1
while stack:
x = stack.pop()
for y in graph[x]:
if not dist[y]:
dist[y] = dist[x] + 1
stack.append(y)
colors = set()
for x in leaf:
colors.add(dist[x] % 2)
if len(colors) == 2:
mn = 3
else:
mn = 1
mx = n - 1
for i in range(1, n + 1):
if deg[i] >= 3:
cnt = 0
for j in graph[i]:
if j in leaf:
cnt += 1
if cnt >= 2:
mx -= cnt - 1
print(mn, mx) | IMPORT 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 VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | import sys
def I():
return sys.stdin.readline().rstrip()
n = int(I())
adj = [list() for _ in range(n + 1)]
for e in range(n - 1):
i, j = map(int, I().split())
adj[i].append(j)
adj[j].append(i)
ischild = [None] + [(len(adj[i]) == 1) for i in range(1, n + 1)]
childs = [None] + [sum(ischild[j] for j in adj[i]) for i in range(1, n + 1)]
lev = [None] * (n + 1)
rt = next(i for i in range(1, n + 1) if not ischild[i])
lev[rt] = 0
nq = [rt]
while True:
q = nq
nq = []
for i in q:
for j in adj[i]:
if lev[j] == None:
lev[j] = lev[i] + 1
nq.append(j)
if len(nq) == 0:
break
mn = 3 if len({(lev[i] % 2) for i in range(1, n + 1) if ischild[i]}) > 1 else 1
mx = n - 1 - sum(max(0, childs[i] - 1) for i in range(1, n + 1))
print(mn, mx) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR WHILE NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR VAR IF VAR VAR NONE ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | n = int(input())
u = []
for i in range(n):
u.append([])
for i in range(n - 1):
a, b = map(int, input().split())
u[a - 1].append(b - 1)
u[b - 1].append(a - 1)
for i in range(n):
if len(u[i]) == 1:
st = i
q = [st]
q0 = 0
d = [n + 1] * n
d[st] = 0
ans1 = 1
ans2 = n - 1
while len(q) > q0:
v = q[q0]
q0 += 1
lst = 0
for i in u[v]:
if len(u[i]) == 1:
lst += 1
if d[i] > d[v] + 1:
d[i] = d[v] + 1
q.append(i)
if lst > 0:
ans2 -= lst - 1
for i in range(n):
if d[i] > 1 and d[i] % 2 == 1 and len(u[i]) == 1:
ans1 = 3
print(ans1, ans2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | import sys
n = int(sys.stdin.readline())
edge = [
list(map(lambda x: int(x) - 1, sys.stdin.readline().split())) for _ in range(n - 1)
]
nbhd = [[] for _ in range(n)]
for e in edge:
nbhd[e[0]].append(e[1])
nbhd[e[1]].append(e[0])
leaf = [(len(nbhd[i]) == 1) for i in range(n)]
level = [None] * n
i = 0
level[0] = 0
cur = [0]
while None in level:
temp = []
for j in cur:
for k in nbhd[j]:
if level[k] == None:
level[k] = i + 1
temp.append(k)
cur = temp
i += 1
col = [(x & 1) for x in level]
count = [0] * n
for i in range(n):
if leaf[i]:
count[nbhd[i][0]] += 1
M = n - 1 - sum([(x - 1) for x in count if x >= 1])
if len(set([col[i] for i in range(n) if leaf[i]])) == 1:
m = 1
else:
m = 3
print(m, M) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER WHILE NONE VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR VAR IF VAR VAR NONE ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | def push(g, u, v):
if u not in g:
g[u] = []
if v not in g:
g[v] = []
g[u].append(v)
g[v].append(u)
n = int(input())
g = {}
p = {}
for _ in range(n - 1):
u, v = map(int, input().split())
push(g, u, v)
for u in g:
if len(g[u]) >= 2:
root = u
break
p[root] = 0
S = [root]
i = 0
while i < len(S):
u = S[i]
for v in g[u]:
if v != p[u]:
p[v] = u
S.append(v)
i += 1
min_ = 1
sub = 0
cnt = [0] * (n + 1)
path = [0] * (n + 1)
for u in S[::-1]:
if len(g[u]) == 1:
cnt[p[u]] += 1
path[u] = 1
for v in g[u]:
if v == p[u]:
continue
path[u] |= 3 ^ path[v]
for u in S:
if cnt[u] >= 1:
sub += cnt[u] - 1
if path[u] == 3:
min_ = 3
print(str(min_) + " " + str(n - 1 - sub)) | FUNC_DEF IF VAR VAR ASSIGN VAR VAR LIST IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | import sys
input = sys.stdin.buffer.readline
n = int(input())
neig = [0] * n
lev = [0] * n
for i in range(n):
neig[i] = [0]
lev[i] = [-1]
lev[0][0] = 0
for i in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
neig[a][0] += 1
neig[b][0] += 1
neig[a].append(b)
neig[b].append(a)
tod = [0]
while len(tod) > 0:
foo = tod.pop()
for i in range(1, neig[foo][0] + 1):
if lev[neig[foo][i]][0] == -1:
lev[foo].append(neig[foo][i])
lev[neig[foo][i]][0] = lev[foo][0] + 1
lev[neig[foo][i]].append(foo)
tod.append(neig[foo][i])
ends = [0, 0]
ma = n - 1
for i in range(n):
if neig[i][0] == 1:
ends[lev[i][0] % 2] = 1
else:
bn = -1
for j in range(1, neig[i][0] + 1):
if neig[neig[i][j]][0] == 1:
bn += 1
if bn > 0:
ma -= bn
print(1 + 2 * ends[0] * ends[1], ma) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER ASSIGN VAR VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | tree = {}
n = int(input())
for i in range(1, n + 1):
tree[i] = []
for i in range(n - 1):
u, v = [int(x) for x in input().strip().split()]
tree[u].append(v)
tree[v].append(u)
depth = [None for i in range(n + 1)]
def dfs(i):
stack = [(i, 1, -1)]
while len(stack) > 0:
curr, curr_depth, prev = stack[-1]
stack.pop()
depth[curr] = curr_depth
for node in tree[curr]:
if node != prev:
stack.append((node, curr_depth + 1, curr))
for i in range(1, n + 1):
if len(tree[i]) == 1:
root = i
break
dfs(root)
mn = 1
for i in range(1, n + 1):
if len(tree[i]) == 1 and i != root:
if depth[i] % 2 == 0:
mn = 3
mx = n - 1
for i in range(1, n + 1):
ct = 0
for node in tree[i]:
if len(tree[node]) == 1:
ct += 1
if ct >= 2:
mx -= ct - 1
print(mn, mx) | ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | import sys
input = sys.stdin.readline
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = map(int, input().split())
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
q = [0]
color = [-1] * N
color[0] = 0
while q:
qq = []
for p in q:
for np in graph[p]:
if color[np] == -1:
color[np] = color[p] ^ 1
qq.append(np)
q = qq
Cs = set()
Vs = set()
ans2 = N - 1
for n in range(N):
if len(graph[n]) == 1:
Cs.add(color[n])
Vs.add(graph[n][0])
ans2 -= 1
ans1 = 1 if len(Cs) == 1 else 3
ans2 += len(Vs)
print(ans1, ans2) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER WHILE VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold:
* For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of weights of all edges on the simple path between v_{1} and v_{2} has to be equal to 0.
Note that you can put very large positive integers (like 10^{(10^{10})}).
It's guaranteed that such assignment always exists under given constraints. Now let's define f as the number of distinct weights in assignment.
<image> In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0. f value is 2 here, because there are 2 distinct edge weights(4 and 5).
<image> In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1 and vertex 6 (3, 4, 5, 4) is not 0.
What are the minimum and the maximum possible values of f for the given tree? Find and print both.
Input
The first line contains integer n (3 β€ n β€ 10^{5}) β the number of vertices in given tree.
The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 β€ a_{i} < b_{i} β€ n) β it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.
Output
Print two integers β the minimum and maximum possible value of f can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.
Examples
Input
6
1 3
2 3
3 4
4 5
5 6
Output
1 4
Input
6
1 3
2 3
3 4
4 5
4 6
Output
3 3
Input
7
1 2
2 7
3 4
4 7
5 6
6 7
Output
1 6
Note
In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image>
In the second example, possible assignments for each minimum and maximum are described in picture below. The f value of valid assignment of this tree is always 3.
<image>
In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.
<image> | import sys
input = sys.stdin.readline
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
cur = 0
prev = -1
while len(G[cur]) > 1:
for y in G[cur]:
if y == prev:
continue
prev = cur
cur = y
break
root = cur
depth = [-1] * n
leaf = [0] * n
stk = [root]
depth[root] = 0
while stk:
i = stk.pop()
if len(G[i]) == 1:
leaf[i] = 1
for j in G[i]:
if depth[j] == -1:
depth[j] = depth[i] + 1
stk.append(j)
m = 0
for i in range(n):
if leaf[i]:
continue
for j in G[i]:
if not leaf[j]:
continue
m += 1
break
def solve_mn():
for d, l in zip(depth, leaf):
if l and d % 2:
return 3
return 1
mn = solve_mn()
mx = n - 1 - sum(leaf) + m
print(mn, mx) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR VAR VAR IF VAR VAR VAR NUMBER FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = [int(i) for i in input().split()]
gr = []
a = [(2**i - 1) for i in range(31)]
j = 30
while x > 0:
while a[j] > x:
j -= 1
gr.append(j)
x -= a[j]
n = sum(gr)
if n > 10**4:
print(-1)
exit()
print(n)
cur = 1
for i in gr:
for j in range(i):
print(cur, end=" ")
cur += d | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
start = 1
ans = []
for i in range(61):
if x & 1 << i:
for j in range(i):
ans.append(start)
start += d
ans.append(start)
start += d
print(len(ans))
print(" ".join(map(str, ans))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, k = list(map(int, input().split()))
tot = 0
now = 1
d = 1
ans = []
def add(am, el):
global ans
ans += [el] * am
def rec(l):
global d
global tot
now = 1
while True:
if tot + (2**now - 1) > x:
if tot - len(ans) != 0:
rec(x - len(ans))
break
tot += 2**now - 1
add(now, d)
now += 1
d += k
if tot == x:
break
rec(x)
print(len(ans))
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF VAR BIN_OP LIST VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | from sys import stdin, stdout
X, d = stdin.readline().strip().split(" ")
X, d = int(X), int(d)
di = {}
ctr = 1
y = 0
ctr1 = 0
while 1 << y <= X:
if 1 << y & X & (1 << y & X) - 1 == 0 and 1 << y & X != 0:
ctr1 += y + 1
di[ctr] = y
ctr += d + 1
di[ctr] = 1
ctr += d + 1
y += 1
stdout.write(str(ctr1) + "\n")
for i in di:
stdout.write((str(i) + " ") * di[i]) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
n = 1
ans = []
cnt = 0
for i in range(60, 0, -1):
if x >> i & 1:
for j in range(1, i + 1):
ans.append(n)
n += d
cnt += 1
while cnt:
ans.append(n)
n += d
cnt -= 1
if x & 1:
ans.append(n)
print(len(ans))
for i in ans:
print(i, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
c = 1
r = "\n"
e = 29
b = 2**e - 1
while x:
while x < b:
e -= 1
b >>= 1
r += f"{c * d} " * e
c += e
x -= b
print(c - 1, r) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE VAR WHILE VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR STRING VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
pw = [(2**i - 1) for i in range(31, -1, -1)]
p = [i for i in range(31, -1, -1)]
ans = []
el = 1
i = 0
while x > 0:
while pw[i] > x:
i += 1
for z in range(p[i]):
ans.append(el)
x -= pw[i]
el += d
if x != 0:
print("-1")
else:
print(len(ans))
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | import sys
input = sys.stdin.buffer.readline
x, d = map(int, input().split())
bit = 0
count = 1
lst = []
total = 1
remind = 0
while x:
count = 0
bit = 0
while bit <= x:
bit = 1 << count
count += 1
bit = bit >> 1
count -= 2
if not lst:
for i in range(count):
lst.append(1)
remind += 1
else:
item = lst[-1] + d
for i in range(count):
lst.append(item)
remind += 1
x -= bit
total += 1
for i in range(remind):
if lst:
item = lst[-1] + d
else:
item = 1
lst.append(item)
print(len(lst))
print(*lst) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = list(map(int, input().split()))
arr = []
n = 0
s = ""
while x > 0:
s += str(x % 2)
x //= 2
f = 1
l = 999999999999999999
for i in range(len(s)):
if int(s[i]):
arr += [f] * i + [l]
f += d
l -= d
n += i + 1
if n == -1:
print(-1)
else:
print(n)
print(*arr) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP LIST VAR VAR LIST VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
def get_next(x):
if bin(x + 1).count("1") == 1:
return bin(x).count("1")
return len(bin(x)) - 3
a = []
w = 1
while x:
c = get_next(x)
a += c * [w]
w += d + 1
x -= 2**c - 1
print(len(a))
print(*a) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER RETURN FUNC_CALL FUNC_CALL VAR VAR STRING RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | X, d = map(int, input().split())
a = list()
cur = 1
for i in range(32):
if X & 1 << i:
for j in range(i):
a.append(cur)
cur = cur + d
a.append(cur)
cur = cur + d
print(len(a))
for i in a:
print(i, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
a = []
pot = 2**30
e = 30
last = 0
while x > 0:
while x < pot - 1:
e -= 1
pot //= 2
x -= pot - 1
a += [(last + d) for i in range(e)]
last += d
print(len(a))
print(" ".join(map(str, a))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
ans = []
cur = 1
while x > 0:
k = 1
while 2**k - 1 <= x:
k += 1
k -= 1
for i in range(k):
ans.append(cur)
x -= 2**k - 1
cur += d
print(len(ans))
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = [int(i) for i in input().split()]
if x == 1:
print(1)
print(1)
exit()
ind = 0
tmp = 1
counter = 0
ans = []
while x > 0:
t = x & 1
if t == 1:
for j in range(ind):
ans.append(tmp)
counter += 1
tmp += d + 1
x >>= 1
ind += 1
for i in range(counter):
ans.append(ans[-1] + d + 1)
print(len(ans))
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = list(map(int, input().split()))
def dmax(x):
i = 0
while 2**i - 1 <= x:
i += 1
return i - 1
tec = 1
n = 0
step = dmax(x)
stroka = ""
while step != 0:
stroka += (str(tec) + " ") * step
tec += d
x -= 2**step - 1
n += step
step = dmax(x)
print(n)
print(stroka) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | import sys
[X, d] = map(int, sys.stdin.readline().strip().split())
a = []
m = 1 - d
i = 31
while i > 0:
if 2**i - 1 > X:
i -= 1
continue
a.extend([m + d] * i)
m += d
X -= 2**i - 1
print(len(a))
print(" ".join(map(str, a))) | IMPORT ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
l = []
a = 1
while x >= 0:
c = 1
while 2**c - 1 <= x:
c += 1
c -= 1
l = l + [a] * c
a += d
x -= 2**c - 1
if c == 0:
x -= 1
a -= d
if len(l) > 10**4 or l[-1] > 10**18:
exit(print(-1))
print(len(l))
ans = ""
for i in l:
ans += "{} ".format(i)
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP LIST VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | p2 = [(i, 2**i - 1) for i in range(1, 40)]
X, d = map(int, input().split(" "))
lens = []
for i in p2[::-1]:
if X >= i[1]:
X -= i[1]
lens.append(i[0])
el = 1
if sum(lens) >= 10000:
print(-1)
exit(0)
print(sum(lens) + X)
for i in lens:
print((str(el) + " ") * i, end="")
el += d
for i in range(X):
print(el, end=" ")
el += d | ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING VAR STRING VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
result = []
added = 0
while x > 0:
b = "{0:b}".format(x + 1)
result += [1 + added * d] * (len(b) - 1)
x = x - (1 << len(b) - 1) + 1
added += 1
if len(result) > 10000 or result[-1] >= 10**18:
print(-1)
else:
print(len(result))
print(" ".join(map(str, result))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR BIN_OP LIST BIN_OP NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | p = [1]
def powers_():
global p
for i in range(1, 31):
p.append(p[i - 1] * 2)
for i in range(1, 31):
p[i] = p[i] - 1
powers_()
xn = input().split(" ")
x = int(xn[0])
vc = []
temp = 1
sum = 0
while x != 0:
for i in range(30, 0, -1):
if p[i] <= x:
x = x - int(p[i])
vc.append({"f": temp, "s": i})
sum = sum + i
break
temp = temp + int(xn[1]) + 1
print(sum)
for i in range(0, len(vc)):
for j in range(0, int(vc[i]["s"])):
print(vc[i]["f"], end=" ") | ASSIGN VAR LIST NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR DICT STRING STRING VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING STRING |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | ii = lambda: int(input())
kk = lambda: map(int, input().split())
ll = lambda: list(kk())
x, d = kk()
v = 1
s = []
for i in range(35):
if 2**i > x:
break
if 2**i & x:
s.extend([v] * i)
s.append(v + 10**9)
v += 2 * 10**9
print(len(s))
print(*s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
r = []
e = 29
b = 2**e - 1
while x:
while x < b:
e -= 1
b >>= 1
r += [str((len(r) + 1) * d)] * e
x -= b
print(len(r))
print(" ".join(r)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE VAR WHILE VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP LIST FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | def m2(n):
r = 1
d = 0
while (r << 1) - 1 <= n:
r <<= 1
d += 1
return r - 1, d
x, d = [int(x) for x in input().split()]
le = 0
ost = x
nums = []
kols = []
inf = 10**18
last_num = 1 - d
while ost != 0:
n, deg = m2(ost)
ost -= n
le += deg
last_num += d
nums.append(last_num)
kols.append(deg)
if le > 10**4:
print(-1)
exit()
if last_num > inf:
print(-1)
exit()
print(sum(kols))
for i in range(len(nums)):
print(*([nums[i]] * kols[i]), end=" ") | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR VAR STRING |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | from sys import stdin, stdout
x, d = map(int, stdin.readline().split())
psze = 100
cur = 1
ans = []
while x:
for z in range(1, psze):
v = (1 << z) - 1
if v > x:
i = z - 1
x = x - (1 << i) + 1
break
for j in range(i):
ans.append(cur)
cur += d
stdout.write(str(len(ans)) + "\n" + " ".join(list(map(str, ans)))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | s = [(2**i - 1) for i in range(31, 0, -1)]
z = [i for i in range(31, 0, -1)]
x, d = map(int, input().split())
st = 1
p = 0
ret = []
while x > 0:
while s[p] > x:
p += 1
for i in range(z[p]):
ret.append(st)
st += d
x -= s[p]
if x != 0:
print("-1")
else:
print(len(ret))
print(" ".join(str(i) for i in ret)) | ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER WHILE VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = [int(i) for i in input().split()]
cr = 1
ans = []
while x:
i = 0
while (1 << i) - 1 <= x:
i += 1
for j in range(i - 1):
ans.append(cr)
x -= (1 << i - 1) - 1
cr += d
print(len(ans))
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | n, d = [int(c) for c in input().split(" ")]
n_copy = n
groupsize_cases = [(2**c - 1) for c in range(100)]
groups = []
i = 1
while n >= groupsize_cases[i]:
i += 1
i -= 1
while n > 0:
while n >= groupsize_cases[i]:
groups.append(i)
n -= groupsize_cases[i]
i -= 1
ans = []
current_number = 1
for num in groups:
ans.append(current_number)
for i in range(num - 1):
ans.append(current_number)
current_number += d + 1
print(len(ans))
for num in ans:
print(num, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
A = []
a = 1
k = 0
while a < x:
a *= 2
a //= 2
x = bin(x)[2:][::-1]
y = 1
for i in range(len(x) - 1, -1, -1):
if x[i] == "1":
A += i * [y]
k += 1
y += d + 1
while k:
A.append(y)
y += d + 1
k -= 1
print(len(A))
for i in A:
print(i, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR LIST VAR VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | import itertools
def subsequence_counter(x, d):
ans = []
new = "{0:b}".format(x)
counter = 1
for i in range(len(new)):
if new[i] == "1":
ans.extend(list(itertools.repeat(counter, len(new) - i - 1)))
ans.append(d + counter + 1)
if new[i] == "0":
continue
counter += 2 * d + counter + 1
return len(ans), ans
a, b = input().split()
a = int(a)
b = int(b)
c, d = subsequence_counter(a, b)
print(c)
print(" ".join(map(str, d))) | IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = map(int, input().split())
s = str(bin(x))[2:]
wqa = 1
ans = []
koms = 0
for i in range(len(s)):
if s[i] == "1":
for idq in range(len(s) - i - 1):
ans.append(wqa)
koms += 1
wqa += d + 1
for ii in range(koms):
ans.append(wqa)
wqa += d
print(len(ans))
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | X, d = map(int, input().split())
x = X
ans = list()
ln = 0
last = 1
while x > 0:
if last >= 10**18:
print(-1)
exit()
i = 0
while 2 ** (i + 1) - 1 <= x:
i += 1
t = 2**i - 1
x -= t
if ln + i > 10000:
print(-1)
exit()
for _ in range(i):
ans.append(last)
ln += 1
last += d
print(len(ans))
print(" ".join(map(str, ans))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | x, d = [int(s) for s in input().split()[:2]]
def getd(y):
if y <= 1:
return y
da = 1
num = 0
while da * 2 <= y:
da *= 2
num += 1
return num
f = 1
ans = []
while x > 0:
num = getd(x)
n = 2**num - 1
for i in range(num):
ans.append(f)
f += d + 1
x -= n
print(len(ans))
for i in ans[:-1]:
print(i, end=" ")
print(ans[-1]) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER |
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | X, D = map(int, input().split())
cn = 1
add0 = 1 if X & 1 else 0
ans = []
for i in range(30, 0, -1):
if not X & 1 << i:
continue
ans += [cn] * i
add0 += 1
cn += D
for i in range(add0):
ans.append(cn)
cn += D
print(len(ans))
print(" ".join(map(str, ans))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP LIST VAR VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.
To be more clear, consider all integer sequence with length k (a_1, a_2, ..., a_{k}) with $\sum_{i = 1}^{k} 2^{a_{i}} = n$. Give a value $y = \operatorname{max}_{1 \leq i \leq k} a_{i}$ to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest.
For definitions of powers and lexicographical order see notes.
-----Input-----
The first line consists of two integers n and k (1 β€ n β€ 10^18, 1 β€ k β€ 10^5)Β β the required sum and the length of the sequence.
-----Output-----
Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second lineΒ β the required sequence.
It is guaranteed that the integers in the answer sequence fit the range [ - 10^18, 10^18].
-----Examples-----
Input
23 5
Output
Yes
3 3 2 1 0
Input
13 2
Output
No
Input
1 2
Output
Yes
-1 -1
-----Note-----
Sample 1:
2^3 + 2^3 + 2^2 + 2^1 + 2^0 = 8 + 8 + 4 + 2 + 1 = 23
Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.
Answers like (4, 1, 1, 1, 0) do not have the minimum y value.
Sample 2:
It can be shown there does not exist a sequence with length 2.
Sample 3:
$2^{-1} + 2^{-1} = \frac{1}{2} + \frac{1}{2} = 1$
Powers of 2:
If x > 0, then 2^{x} = 2Β·2Β·2Β·...Β·2 (x times).
If x = 0, then 2^{x} = 1.
If x < 0, then $2^{x} = \frac{1}{2^{-x}}$.
Lexicographical order:
Given two different sequences of the same length, (a_1, a_2, ... , a_{k}) and (b_1, b_2, ... , b_{k}), the first one is smaller than the second one for the lexicographical order, if and only if a_{i} < b_{i}, for the first i where a_{i} and b_{i} differ. | n, k = map(int, input().split())
a = list(bin(n))
a = a[2:]
b = []
for i in range(100005):
b.append(0)
l = len(a)
c = 0
for i in range(l):
if a[i] == "1":
b[65 - (l - i - 1)] = 1
c += 1
lini = 65 - (l - i - 1)
if c <= k:
gfati = 0
for i in range(129):
if gfati == 1:
break
if c == k:
break
if b[i] == 0:
continue
else:
if i > lini:
lini = i
if c + b[i] <= k:
b[i + 1] += 2 * b[i]
c += b[i]
b[i] = 0
else:
gfati = 1
if 1:
for i in range(lini, 1000005, 1):
if c == k:
break
if b[i] != 0:
if c + 1 <= k:
b[i] -= 1
c += 1
b[i + 1] += 2
print("Yes")
for i in range(100005):
if b[i] != 0:
for j in range(b[i]):
print(65 - i, end=" ")
else:
print("No") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR STRING EXPR FUNC_CALL VAR STRING |
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.
To be more clear, consider all integer sequence with length k (a_1, a_2, ..., a_{k}) with $\sum_{i = 1}^{k} 2^{a_{i}} = n$. Give a value $y = \operatorname{max}_{1 \leq i \leq k} a_{i}$ to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest.
For definitions of powers and lexicographical order see notes.
-----Input-----
The first line consists of two integers n and k (1 β€ n β€ 10^18, 1 β€ k β€ 10^5)Β β the required sum and the length of the sequence.
-----Output-----
Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second lineΒ β the required sequence.
It is guaranteed that the integers in the answer sequence fit the range [ - 10^18, 10^18].
-----Examples-----
Input
23 5
Output
Yes
3 3 2 1 0
Input
13 2
Output
No
Input
1 2
Output
Yes
-1 -1
-----Note-----
Sample 1:
2^3 + 2^3 + 2^2 + 2^1 + 2^0 = 8 + 8 + 4 + 2 + 1 = 23
Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.
Answers like (4, 1, 1, 1, 0) do not have the minimum y value.
Sample 2:
It can be shown there does not exist a sequence with length 2.
Sample 3:
$2^{-1} + 2^{-1} = \frac{1}{2} + \frac{1}{2} = 1$
Powers of 2:
If x > 0, then 2^{x} = 2Β·2Β·2Β·...Β·2 (x times).
If x = 0, then 2^{x} = 1.
If x < 0, then $2^{x} = \frac{1}{2^{-x}}$.
Lexicographical order:
Given two different sequences of the same length, (a_1, a_2, ... , a_{k}) and (b_1, b_2, ... , b_{k}), the first one is smaller than the second one for the lexicographical order, if and only if a_{i} < b_{i}, for the first i where a_{i} and b_{i} differ. | n, k = map(int, input().split())
bits = [(0) for i in range(128)]
tmp = n
sumBits = 0
for i in range(64):
if tmp % 2 == 1:
bits[63 - i] = 1
sumBits += 1
tmp = tmp >> 1
if sumBits > k:
print("No")
elif sumBits == k:
print("Yes")
res = []
for i in range(63, -1, -1):
if bits[63 - i] == 1:
res.append(i)
print(*res)
else:
ind = 0
while k != sumBits:
if bits[ind] != 0:
if bits[ind] <= k - sumBits:
bits[ind + 1] += 2 * bits[ind]
sumBits += bits[ind]
bits[ind] = 0
else:
break
ind += 1
if k != sumBits:
for i in range(127, -1, -1):
if bits[i] != 0:
bits[i] -= 1
first = i + 1
break
if k - sumBits < 128 - first:
for i in range(first, k - sumBits + first):
bits[i] = 1
bits[k - sumBits + first - 1] = 2
else:
for i in range(first, 128):
bits[i] = 1
bits += [1] * (k - sumBits + first - 128)
bits[-1] = 2
print("Yes")
res = []
for i in range(len(bits)):
if bits[i] != 0:
res += [63 - i] * bits[i]
print(*res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP LIST NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP LIST BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.