description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
from sys import stdin
text = stdin.read().splitlines()
t = int(text[0])
def ones(s):
return len(list(filter(lambda x: x == "1", s)))
for i in range(1, 2 * t + 1, 2):
n = int(text[i])
binum = text[i + 1]
if binum[0] == "0" or binum[-1] == "0":
print("NO")
continue
onecount = ones(binum)
if onecount % 2 != 0:
print("NO")
continue
a = []
b = []
aopens = 0
bopens = 0
u = -1
whatput = 0
for c in binum:
if c == "1":
u += 1
if u >= onecount / 2:
aopens -= 1
bopens -= 1
a.append(")")
b.append(")")
else:
aopens += 1
bopens += 1
a.append("(")
b.append("(")
else:
whatput = 1 - whatput
if whatput == 0:
a.append("(")
b.append(")")
else:
a.append(")")
b.append("(")
print("YES")
print("".join(a))
print("".join(b))
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
def solve():
n = int(input())
s = input()
count = c = 0
for j in range(n):
if s[j] == "0":
count += 1
else:
c += 1
if s[0] == "0" or s[n - 1] == "0" or count % 2:
print("NO")
return
a = ""
b = ""
f = 0
c = int(c / 2)
one = 0
for j in range(n):
if s[j] == "0":
if f:
a += ")"
b += "("
else:
a += "("
b += ")"
f ^= 1
else:
if c > one:
a += "("
b += "("
else:
a += ")"
b += ")"
one += 1
print("YES")
print(a)
print(b)
t = int(input())
for i in range(t):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
for _ in range(int(input())):
n = int(input())
s = input()
o = s.count("1")
z = n - o
c = 0
o = o // 2
opn = False
done = False
if z % 2:
print("NO")
else:
a, b = "", ""
for i in s:
if i == "1":
if o:
c += 1
a += "("
b += "("
o -= 1
else:
a += ")"
b += ")"
c -= 1
elif c:
if opn:
a += "("
b += ")"
else:
b += "("
a += ")"
opn = not opn
else:
print("NO")
done = True
break
if not done:
print("YES")
print(a)
print(b)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR STRING STRING FOR VAR VAR IF VAR STRING IF VAR VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR STRING VAR STRING VAR NUMBER IF VAR IF VAR VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
def count(string, character):
count = 0
for i in range(len(string)):
if string[i] == character:
count = count + 1
return count
for t in range(int(input())):
n = int(input())
s = input()
zc = count(s, "0")
if zc % 2 == 1 or s[0] == "0" or s[-1] == "0":
print("NO")
else:
oc = count(s, "1")
a = ""
b = ""
c = 0
flag = 1
for i in range(len(s)):
if s[i] == "1":
c = c + 1
if c <= oc // 2:
a = a + "("
b = b + "("
else:
a = a + ")"
b = b + ")"
else:
if flag == 1:
a = a + "("
b = b + ")"
else:
a = a + ")"
b = b + "("
flag = not flag
print("YES")
print(a)
print(b)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
for q in range(int(input())):
n = int(input())
s = input()
x = s.count("1")
y = s.count("0")
a_str = ""
b_str = ""
possible = True
if y % 2 == 1:
possible = False
else:
xh = x // 2
yh = y // 2
openx = 0
a_open = 0
b_open = 0
for i in range(n):
if s[i] == "1":
if openx < xh:
openx += 1
a_open += 1
b_open += 1
a_str += "("
b_str += "("
elif a_open == 0 or b_open == 0:
possible = False
break
else:
a_open -= 1
b_open -= 1
a_str += ")"
b_str += ")"
elif a_open == 0 and b_open == 0:
possible = False
break
elif a_open >= b_open:
a_open -= 1
a_str += ")"
b_open += 1
b_str += "("
else:
a_open += 1
a_str += "("
b_open -= 1
b_str += ")"
if possible:
print("YES")
print(a_str)
print(b_str)
else:
print("NO")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR STRING VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR STRING VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
import sys
input = sys.stdin.readline
def main():
n = int(input())
S = input().strip()
l = S.count("1")
o = S.count("0")
if l % 2 == 1:
print("NO")
return
if S[0] == "0" or S[-1] == "0":
print("NO")
return
print("YES")
cnt_o = 0
cnt_l = 0
T1 = []
T2 = []
for s in S:
if s == "1":
if cnt_l < l // 2:
T1.append("(")
T2.append("(")
else:
T1.append(")")
T2.append(")")
cnt_l += 1
else:
cnt_o += 1
if cnt_o % 2 == 0:
T1.append("(")
T2.append(")")
else:
T1.append(")")
T2.append("(")
print("".join(T1))
print("".join(T2))
for _ in range(int(input())):
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.buffer.readline())
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def LI1():
return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def LLI1(rows_number):
return [LI1() for _ in range(rows_number)]
def BI():
return sys.stdin.buffer.readline().rstrip()
def SI():
return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 10**9 + 7
def ng(aa):
now = 0
for a in aa:
now += a
if now < 0:
return True
return False
for _ in range(II()):
n = II()
n2 = n // 2
s = SI()
zero, one = [], []
for i, c in enumerate(s):
if c == "0":
zero.append(i)
else:
one.append(i)
if len(zero) & 1:
print("NO")
continue
a = [1] * n
b = [1] * n
for i in range(len(zero)):
if i & 1:
a[zero[i]] = -1
else:
b[zero[i]] = -1
for i in range(len(one) // 2, len(one)):
a[one[i]] = -1
b[one[i]] = -1
if ng(b):
print("NO")
continue
print("YES")
a = "".join("(" if a[i] == 1 else ")" for i in range(n))
b = "".join("(" if b[i] == 1 else ")" for i in range(n))
print(a)
print(b)
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR VAR NUMBER STRING STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR NUMBER STRING STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
T = int(input())
for ts in range(T):
N = int(input())
s = input()
if s[0] == "0" or s[-1] == "0":
print("NO")
continue
a = ["("]
b = ["("]
ca = 1
cb = 1
for i in range(1, N - 1):
if s[i] == "1":
if ca == 0 or cb == 0:
a.append("(")
b.append("(")
ca += 1
cb += 1
elif ca == cb == 1:
if s[i + 1] == "1":
a.append(")")
b.append(")")
ca -= 1
cb -= 1
else:
a.append("(")
b.append("(")
ca += 1
cb += 1
else:
a.append(")")
b.append(")")
ca -= 1
cb -= 1
elif ca == 0:
a.append("(")
b.append(")")
ca += 1
cb -= 1
elif cb == 0:
a.append(")")
b.append("(")
ca -= 1
cb += 1
elif ca > cb:
a.append(")")
b.append("(")
ca -= 1
cb += 1
else:
a.append("(")
b.append(")")
ca += 1
cb -= 1
a.append(")")
b.append(")")
ca -= 1
cb -= 1
if ca == cb == 0:
print("YES")
print("".join(a))
print("".join(b))
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST STRING ASSIGN VAR LIST STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
def ii():
return int(input())
def li():
return [int(i) for i in input().split()]
for t in range(ii()):
n = ii()
s = input()
ones = 0
if s[0] != "1" or s[n - 1] != "1":
print("NO")
else:
for i in range(n):
ones += s[i] == "1"
if ones % 2 == 1:
print("NO")
else:
a = ""
b = ""
ones //= 2
flag = 0
for i in range(n):
if s[i] == "1":
if ones > 0:
a += "("
b += "("
ones -= 1
else:
a += ")"
b += ")"
elif flag == 0:
flag = 1
a += "("
b += ")"
else:
flag = 0
a += ")"
b += "("
print("YES")
print(a)
print(b)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR STRING VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER VAR STRING VAR STRING ASSIGN VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
s = input()
cnt = 0
for i in s:
cnt += i == "1"
if s[0] == "0" or s[n - 1] == "0" or cnt % 2 == 1:
print("NO")
continue
k = 0
a, b = "", ""
flip = False
for i in range(n):
if s[i] == "1":
if k * 2 < cnt:
a += "("
b += "("
else:
a += ")"
b += ")"
k += 1
else:
if flip:
a += ")"
b += "("
else:
a += "("
b += ")"
flip = not flip
print("YES")
print(a)
print(b)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR STRING IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER IF VAR VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
for i in range(int(input())):
n = int(input())
s = input()
cnt = 0
for i in s:
if i == "0":
cnt += 1
if cnt % 2 == 1 or s[0] == "0" or s[n - 1] == "0":
print("NO")
continue
a = ""
b = ""
turn = False
cnt1 = n - cnt
c1 = 0
for i in s:
if i == "0":
if turn:
a += "("
b += ")"
else:
a += ")"
b += "("
turn ^= 1
else:
c1 += 1
if c1 <= cnt1 // 2:
a += "("
b += "("
else:
a += ")"
b += ")"
print("YES\n", a, "\n", b)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING VAR STRING VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
t = int(input())
for _ in range(t):
n = int(input())
temp = [int(i) for i in input()]
a, b = "", ""
temp_a, temp_b = 0, 0
flag = 0
k = temp.count(1)
if n % 2 != 0 or temp[0] == 0 or temp[-1] == 0 or k % 2 != 0:
flag = 1
open_a, open_b = n // 2, n // 2
close_a, close_b = n // 2, n // 2
k = k // 2
f = 1
for i in temp:
if temp_a < 0 or temp_b < 0:
break
if i == 1:
if k == 0:
a += ")"
b += ")"
temp_a -= 1
temp_b -= 1
else:
a += "("
b += "("
temp_a += 1
temp_b += 1
k -= 1
else:
if f:
b += ")"
a += "("
temp_b -= 1
temp_a += 1
else:
a += ")"
b += "("
temp_a -= 1
temp_b += 1
f = (f + 1) % 2
if flag == 1 or temp_a != 0 or temp_b != 0:
print("NO")
else:
print("YES")
print(a)
print(b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
import sys
for _ in range(int(input())):
n = int(input())
s = sys.stdin.readline().rstrip()
one = s.count("1")
if s[0] == s[-1] == "1" and one % 2 == 0:
a = []
b = []
one //= 2
flag = 0
for i in s:
if i == "0":
a.append(["(", ")"][flag % 2])
b.append([")", "("][flag % 2])
flag += 1
elif one > 0:
a.append("(")
b.append("(")
one -= 1
else:
a.append(")")
b.append(")")
print("YES")
print("".join(a))
print("".join(b))
else:
print("NO")
|
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR LIST STRING STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
for _ in range(int(input())):
n = int(input())
s = [int(a) for a in input()]
cnt = sum(s)
if s[0] and s[-1] and n & 1 ^ 1 and cnt & 1 ^ 1:
a, b, p = [0] * n, [0] * n, 1
for i, x in enumerate(s):
if x:
if cnt > 0:
a[i] = b[i] = 1
cnt -= 2
else:
a[i] = p
p ^= 1
b[i] = p
print(
"YES",
"".join([("(" if x else ")") for x in a]),
"".join([("(" if x else ")") for x in b]),
sep="\n",
)
else:
print("NO")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_CALL STRING VAR STRING STRING VAR VAR FUNC_CALL STRING VAR STRING STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
for s in [*open(0)][2::2]:
N = len(s) - 1
o = s.count("1")
if s[0] < "1" or s[-2] < "1":
print("NO")
continue
if o & 1:
print("NO")
continue
n = 0
a = [0] * N
b = [0] * N
c = 1
for i in range(N):
if s[i] < "1":
if c:
a[i] = ")"
b[i] = "("
else:
a[i] = "("
b[i] = ")"
c ^= 1
else:
n += 1
if 2 * n > o:
a[i] = b[i] = ")"
n += 1
else:
a[i] = b[i] = "("
print("YES\n" + "".join(a) + "\n" + "".join(b))
|
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL STRING VAR STRING FUNC_CALL STRING VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
t = int(input())
for _ in range(t):
n = int(input())
a = input()
z = 0
o = 0
if a[0] != "1" or a[-1] != "1":
print("NO")
else:
d = {}
for i in range(n):
if a[i] == "1":
o += 1
z = n - o
if z % 2 != 0:
print("NO")
else:
print("YES")
c = 0
e = 0
s1 = ""
s2 = ""
for i in range(n):
if a[i] == "1":
if c < o // 2:
s1 += "("
s2 += "("
c = c + 1
else:
s1 += ")"
s2 += ")"
elif e == 0:
s1 += "("
s2 += ")"
e = 1
else:
s1 += ")"
s2 += "("
e = 0
print(s1)
print(s2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR STRING VAR STRING IF VAR NUMBER VAR STRING VAR STRING ASSIGN VAR NUMBER VAR STRING VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
def solve():
n = int(input())
s = input()
c = []
b = []
z = s.count("1")
if s[0] != "1" or s[-1] != "1":
print("NO")
else:
p = n - z
if p % 2:
print("NO")
return
k = 0
t = 0
for j in s:
if j == "1":
if k < z // 2:
c.append("(")
b.append("(")
k = k + 1
else:
c.append(")")
b.append(")")
elif t == 0:
c.append("(")
b.append(")")
t = 1
else:
c.append(")")
b.append("(")
t = 0
print("YES")
print("".join(c))
print("".join(b))
for _ in range(int(input())):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
t = int(input())
for _ in range(t):
n = int(input())
s = input()
if s[0] == "0" or s[-1] == "0" or s.count("0") % 2 == 1 or s.count("1") % 2 == 1:
print("NO")
continue
zero = s.count("0")
one = s.count("1")
zopen = zero // 2
zclose = zero // 2
oopen = one // 2
oclose = one // 2
a = ""
b = ""
cura = 0
curb = 0
flag = 0
for i in range(n):
if s[i] == "1":
if oopen > 0:
a += "("
b += "("
cura += 1
curb += 1
oopen -= 1
elif oclose > 0 and cura - 1 >= 0 and curb - 1 >= 0:
a += ")"
b += ")"
cura -= 1
curb -= 1
oclose -= 1
else:
flag = 1
else:
if curb >= cura and zopen > 0:
a += "("
b += ")"
cura += 1
curb -= 1
zopen -= 1
else:
a += ")"
b += "("
cura -= 1
curb += 1
zclose -= 1
if cura < 0 or curb < 0:
flag = 1
if flag == 1:
print("NO")
else:
print("YES")
print(a)
print(b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
t = int(input())
for i in range(t):
n = int(input())
s = input()
cnt = 0
for i in range(n):
if s[i] == "1":
cnt += 1
if cnt % 2 != 0 or s[0] == "0" or s[-1] == "0":
print("NO")
else:
flag = 0
k = 0
a = ""
b = ""
for i in range(n):
if s[i] == "1":
if k < cnt // 2:
a += "("
b += "("
k += 1
else:
a += ")"
b += ")"
elif flag == 0:
a += "("
b += ")"
flag = 1
else:
a += ")"
b += "("
flag = 0
print("YES")
print(a)
print(b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR STRING VAR STRING IF VAR NUMBER VAR STRING VAR STRING ASSIGN VAR NUMBER VAR STRING VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input()))
o = l.count(1)
z = l.count(0)
if n % 2 != 0:
print("NO")
elif o % 2 != 0:
print("NO")
elif l[0] == 0 or l[n - 1] == 0:
print("NO")
else:
print("YES")
a = ""
b = ""
for i in range(n):
if l[i] == 1:
if o != 0:
a += "("
b += "("
o -= 2
else:
a += ")"
b += ")"
elif z % 2 == 0:
a += ")"
b += "("
z -= 1
else:
a += "("
b += ")"
z -= 1
print(a)
print(b)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR STRING VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING VAR NUMBER VAR STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
def solve():
n = int(input())
s = input()
if s[len(s) - 1] == "0" or s[0] == "0":
print("NO")
return
else:
ones = 0
for i in range(len(s)):
ones += s[i] == "1"
if ones % 2 == 1:
print("NO")
return
else:
print("YES")
sol1 = [None] * n
sol2 = [None] * n
cojones = ones
ones = 0
for i in range(n):
if s[i] == "1":
if ones < cojones / 2:
sol1[i] = "("
sol2[i] = "("
else:
sol1[i] = ")"
sol2[i] = ")"
ones += 1
alt = 0
for i in range(n):
if s[i] == "0":
if alt == 0:
alt = 1
sol1[i] = "("
sol2[i] = ")"
else:
alt = 0
sol1[i] = ")"
sol2[i] = "("
for i in range(n):
print(sol1[i], end="")
print()
for i in range(n):
print(sol2[i], end="")
print()
return 0
t = int(input())
while t:
solve()
t -= 1
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
from sys import stdin, stdout
t = int(input())
for _ in range(t):
n = int(input())
s = list(stdin.readline())
s1 = [0] * n
s2 = [0] * n
c = 0
for i in range(n):
if s[i] == "0":
if c % 2:
s1[i] = ")"
s2[i] = "("
else:
s1[i] = "("
s2[i] = ")"
c += 1
psum1 = [0] * n
psum2 = [0] * n
c1 = 0
c2 = 0
for i in range(n - 1, -1, -1):
if s1[i] == ")":
if c1 == 1:
c1 = -1
else:
c1 -= 1
elif s1[i] == "(":
c1 += 1
if s2[i] == ")":
if c2 == 1:
c2 = -1
else:
c2 -= 1
elif s2[i] == "(":
c2 += 1
psum1[i] = c1
psum2[i] = c2
c1 = 0
c2 = 0
for i in range(n):
if s1[i] == 0:
if c1 <= max(-1 * psum1[i], 0) or c2 <= max(-1 * psum2[i], 0):
s1[i] = "("
s2[i] = "("
c1 += 1
c2 += 1
else:
s1[i] = ")"
s2[i] = ")"
c1 -= 1
c2 -= 1
elif s1[i] == "(":
c1 += 1
c2 -= 1
else:
c1 -= 1
c2 += 1
flag = True
c1 = 0
c2 = 0
for i in range(n):
if s1[i] == "(":
c1 += 1
else:
c1 -= 1
if s2[i] == "(":
c2 += 1
else:
c2 -= 1
if c1 < 0 or c2 < 0:
flag = False
break
if flag and c1 == 0 and c2 == 0:
stdout.write("YES\n")
for i in s1:
stdout.write(i)
stdout.write("\n")
for i in s2:
stdout.write(i)
else:
stdout.write("NO")
stdout.write("\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
cases = int(input())
while cases:
cases -= 1
num = int(input())
s = list(map(int, list(input())))
if len(s) % 2 != 0 or s[0] == 0 or s[-1] == 0 or s.count(0) % 2 != 0:
print("NO")
else:
ones = s.count(1) // 2
zeros = s.count(0)
ans1 = ""
ans2 = ""
for n in s:
if n == 1 and ones > 0:
ans1 += "("
ans2 += "("
ones -= 1
elif n == 1:
ans1 += ")"
ans2 += ")"
elif n == 0 and zeros % 2 == 0:
ans1 += "("
ans2 += ")"
zeros -= 1
else:
ans1 += ")"
ans2 += "("
zeros -= 1
print("YES")
print(ans1)
print(ans2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING VAR NUMBER VAR STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
import sys
t = int(sys.stdin.readline())
for _ in range(t):
n = int(sys.stdin.readline())
data = sys.stdin.readline().rstrip()
cnt_one = 0
for i in data:
if i == "1":
cnt_one += 1
if data[0] == "0" or data[-1] == "0" or cnt_one % 2 == 1:
print("NO")
continue
fir_ans, sec_ans = "", ""
idx, record = 0, 1
for i in range(n):
if data[i] == "1":
fir_ans += ")" if 2 * idx >= cnt_one else "("
sec_ans += fir_ans[-1]
idx += 1
else:
fir_ans += ")" if record == 1 else "("
sec_ans += "(" if record == 1 else ")"
record = -record
print("YES")
print(fir_ans)
print(sec_ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER VAR VAR STRING STRING VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER STRING STRING VAR VAR NUMBER STRING STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
for k in range(int(input())):
n = int(input())
s = input()
a, b = "", ""
x = s.count("1")
y = s.count("0")
if s[0] != "1" or s[n - 1] != "1" or n % 2 != 0 or x % 2 != 0 or y % 2 != 0:
print("NO")
else:
for i in range(n):
if s[i] == "1":
if x % 2 == 0 and x != 0:
a += "("
b += "("
x -= 2
else:
a += ")"
b += ")"
elif y % 2 == 0:
a += "("
b += ")"
y -= 1
else:
a += ")"
b += "("
y -= 1
print("YES")
print(a)
print(b)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR STRING VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING VAR NUMBER VAR STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
def init_array(n):
arr1d = [0] * n
return arr1d
def init_array2d(arr_rows, arr_columns):
arr2d = [[(0) for a in range(arr_columns)] for b in range(arr_rows)]
return arr2d
def print_array2d(arr2d):
for f in range(len(arr2d)):
for q in range(len(arr2d[0])):
print(arr2d[f][q])
def get_array2d_input(arr_rows, arr_columns):
arr2d = [[(0) for f in range(arr_columns)] for q in range(arr_rows)]
for f in range(arr_rows):
line = input()
words = line.split()
for q in range(arr_columns):
arr2d[f][q] = int(words[q])
return arr2d
def solve():
dummy = 0
testCases = int(input())
for test_case in range(1, testCases + 1):
line1 = input()
word1 = line1.split()
N = int(word1[0])
s = input()
cost = 0
brackets_a = ""
brackets_b = ""
stack_a = []
stack_b = []
possible = True
for i in range(N):
if s[i] == "1":
if len(stack_a) == 0 or len(stack_b) == 0:
brackets_a += "("
brackets_b += "("
stack_a.append("(")
stack_b.append("(")
elif i < N - 1:
if len(stack_a) == 1 and len(stack_b) == 1:
if s[i + 1] == "0":
brackets_a += "("
brackets_b += "("
stack_a.append("(")
stack_b.append("(")
else:
if len(stack_a) == 0 or len(stack_b) == 0:
possible = False
break
brackets_a += ")"
brackets_b += ")"
stack_a.pop()
stack_b.pop()
else:
if len(stack_a) == 0 or len(stack_b) == 0:
possible = False
break
brackets_a += ")"
brackets_b += ")"
stack_a.pop()
stack_b.pop()
else:
if len(stack_a) == 0 or len(stack_b) == 0:
possible = False
break
brackets_a += ")"
brackets_b += ")"
stack_a.pop()
stack_b.pop()
elif len(stack_a) == 0 and len(stack_b) == 0:
possible = False
break
elif len(stack_a) >= len(stack_b):
if len(stack_a) == 0:
possible = False
break
brackets_a += ")"
brackets_b += "("
stack_a.pop()
stack_b.append("(")
else:
if len(stack_b) == 0:
possible = False
break
brackets_a += "("
brackets_b += ")"
stack_b.pop()
stack_a.append("(")
ans = ""
if possible:
if len(stack_a) == 0 and len(stack_b) == 0:
ans = "YES"
else:
ans = "NO"
else:
ans = "NO"
if ans == "NO":
print("NO")
else:
print("YES")
print(brackets_a)
print(brackets_b)
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING IF VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
import sys
lines = sys.stdin.readlines()
lineidx = 0
def readLine():
global lineidx
s = lines[lineidx].strip()
lineidx += 1
return s
t = int(readLine())
for testcase in range(t):
n = int(readLine())
s = readLine()
cntone = s.count("1")
cntzero = s.count("0")
if cntone % 2 != 0 or cntzero % 2 != 0:
print("NO")
continue
cntone /= 2
a = ["x"] * n
b = ["x"] * n
bala = balb = 0
for i in range(n):
if s[i] == "1":
if cntone > 0:
cntone -= 1
a[i] = b[i] = "("
else:
a[i] = b[i] = ")"
else:
if cntzero % 2 == 0:
a[i] = "("
b[i] = ")"
else:
a[i] = ")"
b[i] = "("
cntzero -= 1
if a[i] == "(":
bala += 1
else:
bala -= 1
if b[i] == "(":
balb += 1
else:
balb -= 1
if bala < 0 or balb < 0:
break
if bala != 0 or balb != 0:
print("NO")
else:
print("YES")
print("".join(a))
print("".join(b))
|
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
import sys
input = sys.stdin.readline
def solve():
n = int(input())
s = input().strip()
c = s.count("1")
if c % 2 == 1 or n % 2 == 1:
print("NO")
return
c //= 2
b = 0
b1 = 0
b2 = 0
s1 = []
s2 = []
for i in s:
if i == "1":
if c > 0:
s1.append("(")
s2.append("(")
c -= 1
b1 += 1
b2 += 1
else:
s1.append(")")
s2.append(")")
b1 -= 1
b2 -= 1
else:
if b:
s1.append(")")
s2.append("(")
b1 -= 1
b2 += 1
else:
s1.append("(")
s2.append(")")
b1 += 1
b2 -= 1
b ^= 1
if b1 < 0 or b2 < 0:
print("NO")
return
if b1 == 0 and b2 == 0:
print("YES")
print("".join(s1))
print("".join(s2))
else:
print("NO")
for i in range(int(input())):
solve()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
t = int(input())
for _ in range(t):
n = int(input())
s = input()
a = ""
b = ""
x = 0
y = 0
f = 1
one = s.count("1")
half = one // 2
if one % 2:
f = 0
for i in range(n):
if x < 0 or y < 0:
f = 0
break
if s[i] == "1":
if half != 0:
a += "("
b += "("
x += 1
y += 1
half -= 1
else:
a += ")"
b += ")"
x -= 1
y -= 1
elif x <= y:
a += "("
x += 1
b += ")"
y -= 1
else:
a += ")"
x -= 1
b += "("
y += 1
if x != 0 or y != 0 or f == 0:
print("NO")
else:
print("YES")
print(a)
print(b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING IF VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.
You are given a binary string $s$ of length $n$. Construct two balanced bracket sequences $a$ and $b$ of length $n$ such that for all $1\le i\le n$:
if $s_i=1$, then $a_i=b_i$
if $s_i=0$, then $a_i\ne b_i$
If it is impossible, you should report about it.
-----Input-----
The first line contains a single integer $t$ ($1\le t\le 10^4$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$, $n$ is even).
The next line contains a string $s$ of length $n$, consisting of characters 0 and 1.
The sum of $n$ across all test cases does not exceed $2\cdot 10^5$.
-----Output-----
If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower).
If the answer is "YES", output the balanced bracket sequences $a$ and $b$ satisfying the conditions on the next two lines.
If there are multiple solutions, you may print any.
-----Examples-----
Input
3
6
101101
10
1001101101
4
1100
Output
YES
()()()
((()))
YES
()()((()))
(())()()()
NO
-----Note-----
In the first test case, $a=$"()()()" and $b=$"((()))". The characters are equal in positions $1$, $3$, $4$, and $6$, which are the exact same positions where $s_i=1$.
In the second test case, $a=$"()()((()))" and $b=$"(())()()()". The characters are equal in positions $1$, $4$, $5$, $7$, $8$, $10$, which are the exact same positions where $s_i=1$.
In the third test case, there is no solution.
|
for j in range(int(input())):
n = int(input())
s = input()
if s.count("0") % 2 != 0 or s[0] == "0" or s[-1] == "0":
print("NO")
else:
print("YES")
k = s.count("1")
r = ""
f = ""
t = 0
p = 0
i = 0
while i < n:
if s[i] == "1":
if t * 2 < k:
r += "("
f += "("
else:
r += ")"
f += ")"
t += 1
else:
if p == 0:
r += "("
f += ")"
else:
r += ")"
f += "("
p = (p + 1) % 2
i += 1
print(r)
print(f)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
c = a + b
k = 1
s = 0
while s + k <= c:
s += k
k += 1
x = []
border = -1
d = -1
for i in range(k - 1, 0, -1):
if i <= a:
a -= i
x.append(str(i))
elif i > a and a != 0:
d = a
x.append(str(a))
border = i
break
elif a == 0:
border = i
break
y = []
for i in range(border, 0, -1):
if i != d:
y.append(str(i))
print(len(x))
if len(x) != 0:
print(" ".join(x))
print(len(y))
if len(y) != 0:
print(" ".join(y))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
g = False
if b < a:
g = True
a, b = b, a
na = 0
nb = 0
n = 0
while a >= (na + 1) * na // 2:
na += 1
na -= 1
if g == False:
print(na)
sa = (na + 1) * na // 2
nb = na + 1
x = na + 1 - (a - sa)
f = False
if a - sa != 0 and b >= x:
f = True
b -= x
nb = na + 2
if g == False:
for i in range(na):
if i != x - 1:
print(i + 1, sep=" ", end=" ")
print(na + 1, sep=" ", end=" ")
print()
elif g == False:
for i in range(na):
print(i + 1, sep=" ", end=" ")
print()
h = nb
nb = 0
while b >= (2 * h + nb) * (nb + 1) // 2:
nb += 1
nb -= 1
if f == False:
print(nb + 1)
for i in range(na, h + nb):
print(i + 1, sep=" ", end=" ")
else:
print(nb + 2)
for i in range(na + 1, h + nb):
print(i + 1, sep=" ", end=" ")
print(x)
if g == True:
print(na)
if f == True:
for i in range(na):
if i != x - 1:
print(i + 1, sep=" ", end=" ")
print(na + 1, sep=" ", end=" ")
print()
else:
for i in range(na):
print(i + 1, sep=" ", end=" ")
print()
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = input().split()
a = int(a)
b = int(b)
v = 0
l = []
k = 0
s = 0
while s <= a + b:
k += 1
s += k
l.append(k)
del l[-1]
m = []
for i in range(k - 2, -1, -1):
if a >= l[i]:
a -= l[i]
m.append(l[i])
del l[i]
print(len(m))
print(*m)
print(len(l))
print(*l)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
from sys import stdin, stdout
def readlist():
a = [int(i) for i in stdin.readline().split()]
return a
def root(a):
p = (1 + 8 * a) ** 0.5 - 1
p = p / 2
return int(p)
c, d = readlist()
if c > d:
a = d
b = c
fl = 1
else:
b = d
a = c
fl = 0
p = root(a)
z = list(range(1, p + 1))
extra = a - p * (p + 1) // 2
i = len(z) - 1
while extra > 0:
z[i] = z[i] + 1
i = i - 1
extra = extra - 1
q = root(a + b)
z1 = list(range(1, q)) + [q + (a + b - q * (q + 1) // 2)]
z1 = list(set(z1) - set(z))
if sum(z1) != b:
z1.remove(max(z1))
if fl == 1:
if b == 0:
print(0)
print(" ")
else:
print(len(z1))
print(*z1)
if a == 0:
print(0)
print(" ")
else:
print(len(z))
print(*z)
else:
if a == 0:
print(0)
print(" ")
else:
print(len(z))
print(*z)
if b == 0:
print(0)
print(" ")
else:
print(len(z1))
print(*z1)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR LIST BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def print_result(arr):
print(len(arr))
for num in arr:
print(num, end=" ")
print()
arr = [int(x) for x in input().split()]
a, b = arr[0], arr[1]
s = a + b
used = 0
j = 1
while used + j <= s:
used += j
j += 1
j -= 1
A, B = [], []
for i in range(j, 0, -1):
if a >= i:
A.append(i)
a -= i
else:
assert b >= i
B.append(i)
b -= i
print_result(A)
print_result(B)
|
FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
array1 = []
array2 = []
array3 = []
array4 = []
l = 0
r = 10000000000
while r - l > 1:
m = (l + r) // 2
if (m + 1) / 2 * m > a + b:
r = m
else:
l = m
summ1 = 0
summ2 = 0
for i in range(l, 0, -1):
if a - summ1 >= i:
array1.append(i)
summ1 = summ1 + i
elif b - summ2 >= i:
array2.append(i)
summ2 = summ2 + i
summ1 = 0
summ2 = 0
for i in range(r, 0, -1):
if a - summ1 >= i:
array3.append(i)
summ1 = summ1 + i
elif b - summ2 >= i:
array4.append(i)
summ2 = summ2 + i
if len(array1) + len(array2) > len(array3) + len(array4):
print(len(array1))
print(*array1)
print(len(array2))
print(*array2)
else:
print(len(array3))
print(*array3)
print(len(array4))
print(*array4)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
max_lectures = a + b
n = 1
while n * (n + 1) / 2 <= a + b:
n = n + 1
n = n - 1
a_list = []
b_list = []
a_sum = 0
b_sum = 0
for i in range(n, 0, -1):
if a_sum + i <= a:
a_list.append(i)
a_sum = a_sum + i
elif b_sum + i <= b:
b_list.append(i)
b_sum = b_sum + i
print(len(a_list))
print(*a_list)
print(len(b_list))
print(*b_list)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def get_out(list):
print(len(list))
out = " ".join(list)
print(out)
arr = input().split()
a = int(arr[0])
b = int(arr[1])
s = a + b
temp = 0
i = 0
while temp <= s:
i += 1
temp += i
i -= 1
list_a = []
list_b = []
for x in range(i, 0, -1):
if a - x >= 0:
a -= x
list_a.append(str(x))
elif b - x >= 0:
b -= x
list_b.append(str(x))
get_out(list_a)
get_out(list_b)
|
FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
if a <= b:
l = 0
r = a + 1
while r - l > 1:
m = (l + r) // 2
if m * (m + 1) // 2 > a:
r = m
else:
l = m
n = l
a -= n * (n + 1) // 2
c = 1
N = [(i + 1) for i in range(n)]
if a > 0:
c = n + 1 - a
N.pop(c - 1)
N.append(c + a)
N[-1] = c + a
D = []
if a != 0:
b -= c
D = [c]
n = n + 1
n += 1
while b >= 0:
b -= n
D.append(n)
n += 1
D.pop(-1)
print(len(N))
if len(N) != 0:
print(*N)
print(len(D))
if len(D) != 0:
print(*D)
else:
c = a
a = b
b = c
l = 0
r = a + 1
while r - l > 1:
m = (l + r) // 2
if m * (m + 1) // 2 > a:
r = m
else:
l = m
n = l
a -= n * (n + 1) // 2
c = 1
N = [(i + 1) for i in range(n)]
if a > 0:
c = n + 1 - a
N.pop(c - 1)
N.append(c + a)
N[-1] = c + a
D = []
if a != 0:
b -= c
D = [c]
n = n + 1
n += 1
while b >= 0:
b -= n
D.append(n)
n += 1
D.pop(-1)
print(len(D))
if len(D) != 0:
print(*D)
print(len(N))
if len(N) != 0:
print(*N)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST IF VAR NUMBER VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST IF VAR NUMBER VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
n = None
for i in range(10**5):
if i * (i + 1) <= (a + b) * 2:
n = i
else:
break
s1 = 0
a1 = []
a2 = []
for i in range(1, n + 1):
if s1 + i <= a:
a1.append(i)
s1 += i
elif s1 < a:
x = s1 + i - a
a1.remove(x)
a1.append(i)
a2.append(x)
s1 = a
else:
a2.append(i)
print(len(a1))
print(*a1)
print(len(a2))
print(*a2)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
s = a + b
n = 0
k = 1
A = []
while n <= s:
A.append(k)
n += k
k += 1
n -= k - 1
k -= 2
A = A[:k]
P = []
Q = []
for i in range(k - 1, -1, -1):
if a - A[i] >= 0:
P.append(A[i])
a -= A[i]
else:
Q.append(A[i])
b -= A[i]
print(len(P))
print(*P)
print(len(Q))
print(*Q)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def main():
a, b = map(int, input().split())
if a + b == 0:
print(0)
print(0)
return
_sum = 0
last = 0
for i in range(1, a + b + 1):
_sum += i
if _sum == a + b:
last = i
break
elif _sum > a + b:
_sum -= i
last = i - 1
break
first = 1
current = last
used = set()
q_1 = min(a, b)
q = q_1
if q <= last:
if q == 0:
pass
else:
used.add(q)
else:
while q >= current:
used.add(current)
q -= current
current -= 1
if q != 0:
used.add(q)
if q_1 == a:
print(len(used))
print(*used)
print(last - len(used))
print(*(used ^ {i for i in range(1, last + 1)}))
return
else:
print(last - len(used))
print(*(used ^ {i for i in range(1, last + 1)}))
print(len(used))
print(*used)
return
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
arr = []
sum_ = a + b
k = 1
while sum_ >= k:
arr.append(k)
sum_ -= k
k += 1
a1, b1 = [], []
for i in range(len(arr) - 1, -1, -1):
if a >= arr[i]:
a -= arr[i]
a1.append(arr[i])
elif b >= arr[i]:
b -= arr[i]
b1.append(arr[i])
print(len(a1))
print(" ".join(map(str, a1)))
print(len(b1))
print(" ".join(map(str, b1)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
n, m = list(map(int, input().split()))
basis = []
day2 = []
day1 = []
day1sum = 0
iterator = 1
suma = 0
a = n + m
while suma + iterator <= a:
basis.append(iterator)
suma += iterator
iterator += 1
for i in range(len(basis) - 1, -1, -1):
if n - basis[i] >= 0:
n -= basis[i]
day1.append(basis[i])
else:
day2.append(basis[i])
print(len(day1))
print(" ".join(map(str, day1)))
print(len(day2))
print(" ".join(map(str, day2)))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
t = a
x = a + b
i = 0
while i * (i + 1) // 2 <= x:
i += 1
n = i - 1
x = []
y = []
k = []
i = 0
p = 0
while i < n:
k += [i + 1]
i += 1
i = n - 1
h = 0
while i > -1:
if a >= k[i]:
a -= k[i]
x += [k[i]]
h += 1
else:
if a != 0:
p = 1
x += [k[a - 1]]
del k[a - 1]
h += 1
break
i -= 1
if p == 1:
i -= 1
while i > -1:
y += [k[i]]
i -= 1
print(h)
for i in x:
print(i, end=" ")
if t != 0:
print()
print(n - h)
for i in y:
print(i, end=" ")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR LIST BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR LIST VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR LIST VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR LIST VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
from sys import setcheckinterval, setrecursionlimit, stdin
setcheckinterval(1000)
setrecursionlimit(10**7)
def iin():
return int(stdin.readline())
def lin():
return list(map(int, stdin.readline().split()))
a, b = lin()
A = a
ch = 1
ch1 = 1
while ch1 <= a + b:
ch += 1
ch1 += ch
a1 = []
a2 = []
for i in range(ch - 1, 0, -1):
if a - i >= 0:
a1.append(i)
a -= i
else:
a2.append(i)
print(len(a1))
print(*a1)
print(len(a2))
print(*a2)
|
EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
if a == 1 and b == 1:
print(1)
print(1)
print(0)
exit()
k = 0
p = 0
for i in range(1, 1000000):
k += i
if k >= a + b:
p = i
break
d = k - a - b
k1 = 0
p1 = 0
for i in range(1, 1000000):
k1 += i
if k1 >= a:
p1 = i
break
d1 = k1 - a
ans = []
ans1 = []
d3 = 0
d4 = 0
if d <= p1 and d != d1 and d != 0:
if p1 + 1 - d != d1:
ans1.append(p1 + 1)
d3 = p1 + 1 - d
d4 = p1 + 1
else:
ans1.append(p1 + 2)
d3 = p1 + 2 - d
d4 = p1 + 2
for i in range(1, p + 1):
if i != d and i != d4:
ans.append(i)
for i in range(1, p1 + 1):
if i != d1 and i != d and i != d3:
ans1.append(i)
print(len(ans1))
print(" ".join(map(str, ans1)))
ans1 = set(ans1)
ans2 = []
for i in range(len(ans)):
if ans[i] not in ans1:
ans2.append(ans[i])
print(len(ans2))
print(" ".join(map(str, ans2)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def findn(a, b):
s = a + b
left = 0
right = b
while left + 1 < right:
mid = (left + right) // 2
if mid**2 + mid < 2 * s:
left = mid
else:
right = mid
if right**2 + right > 2 * s:
return right - 1
return right
flag = True
a, b = map(int, input().split())
if b < a:
flag = False
a, b = b, a
n = findn(a, b)
tmpa = []
tmpb = []
while n > 0:
if a - n >= 0:
a -= n
tmpa.append(n)
else:
tmpb.append(n)
n -= 1
if flag:
print(len(tmpa))
print(" ".join(map(str, tmpa)))
print(len(tmpb))
print(" ".join(map(str, tmpb)))
else:
print(len(tmpb))
print(" ".join(map(str, tmpb)))
print(len(tmpa))
print(" ".join(map(str, tmpa)))
|
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
e = 1
while e * (e + 1) // 2 < a + b:
e += 1
if e * (e + 1) // 2 > a + b:
e -= 1
use = [0] * 1000000
q = []
p = []
i = e
s = 0
while True:
if i == 0:
break
if a >= s + i:
q.append(i)
use[i] = 1
s += i
else:
a -= s
if not a:
break
q.append(a)
use[a] = 1
break
i -= 1
for i in range(1, e + 1):
if not use[i]:
p.append(i)
print(len(q))
print(*q)
print(len(p))
print(*p)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
k = 0
while k * (k + 1) // 2 <= a + b:
k += 1
k -= 1
A = []
for i in range(1, k + 1):
A.append(i)
List_1 = []
for i in range(k - 1, -1, -1):
if A[i] <= a:
List_1.append(A[i])
a -= A[i]
A.pop(i)
print(len(List_1))
print(*List_1)
print(len(A))
print(*A)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
import sys
a, b = map(int, input().split())
f = 0
if b > a:
a, b = b, a
f = 1
cop = a
n = 1
fir = []
sec = []
while a >= n:
a -= n
fir.append(n)
n += 1
if b == 0:
if f == 0:
print(len(fir))
print(*fir, sep=" ")
print(0)
else:
print(0)
print(len(fir))
print(*fir, sep=" ")
sys.exit()
if a != 0:
fir.append(n)
s = sum(fir) - cop
fir.remove(s)
sec.append(s)
b -= s
n += 1
while b >= n:
b -= n
sec.append(n)
n += 1
if f == 1:
print(len(sec))
print(*sec, sep=" ")
print(len(fir))
print(*fir, sep=" ")
else:
print(len(fir))
print(*fir, sep=" ")
print(len(sec))
print(*sec, sep=" ")
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def shours(x):
return x * (1 + x) // 2
def solver(k):
if k in {0, 1}:
return k
a = 0
b = k
while b - a != 1:
m = (a + b) // 2
if shours(m) > k:
b = m
else:
a = m
return a
a, b = [int(x) for x in input().split()]
x = []
y = []
for text in list(range(solver(a + b), 0, -1)):
if a >= text:
a -= text
x += [text]
else:
y += [text]
print(len(x))
print(*x)
print(len(y))
print(*y)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_DEF IF VAR NUMBER NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR LIST VAR VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def f(n):
return n * (n + 1) // 2
def process(n, m):
x = n + m
start = 0
end = 2 * x
while start + 1 < end:
M = (start + end) // 2
if f(M) > x:
start, end = start, M
else:
start, end = M, end
a = []
s = start
b = set(range(1, start + 1))
while n > 0 and s > 0:
if n < s:
a.append(n)
b.remove(n)
n = 0
break
else:
a.append(s)
b.remove(s)
n -= s
s -= 1
return [a, b]
n, m = [int(x) for x in input().split()]
a, b = process(n, m)
print(len(a))
print(" ".join(map(str, a)))
print(len(b))
print(" ".join(map(str, b)))
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN LIST VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
t = a + b
cnt = 0
for i in range(10**9):
cnt += 1
if cnt * (cnt + 1) // 2 > t:
cnt -= 1
break
firstday = []
secondday = []
for x in range(cnt, 0, -1):
if a >= x:
firstday.append(x)
a -= x
else:
secondday.append(x)
b -= x
print(len(firstday))
print(*firstday)
print(len(secondday))
print(*secondday)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF 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 VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
i = 1
s = i
ind = [i]
sums = 0
sums1 = 0
u = []
p = []
while s < a + b:
i += 1
s += i
ind.append(i)
if s > a + b:
ind.remove(i)
if a <= b:
for j in range(-len(ind) + 1, 1):
if a - ind[-j] >= 0 and j <= 0:
sums += 1
u.append(ind[-j])
a -= ind[-j]
elif b > 0:
sums1 += 1
p.append(ind[-j])
b -= ind[-j]
else:
for j in range(-len(ind) + 1, 1):
if b - ind[-j] >= 0 and j <= 0:
sums1 += 1
p.append(ind[-j])
b -= ind[-j]
elif a > 0:
sums += 1
u.append(ind[-j])
a -= ind[-j]
u.reverse()
p.reverse()
print(sums)
print(*u)
print(sums1)
print(*p)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def count_2_days(a, b):
sumi = a + b
sum_ = 0
numbers = []
for i in range(1, sumi + 1):
if sum_ + 2 * i + 1 <= sumi:
sum_ += i
numbers.append(i)
elif sum_ + 2 * i + 1 > sumi:
numbers.append(sumi - sum_)
break
elif sum_ + i == sumi:
numbers.append(i)
sum_ += i
break
elif i == sumi:
numbers.append(i)
sum_ += i
break
new_a = a
new_b = b
note_a = []
note_b = []
for item in range(len(numbers) - 1, -1, -1):
if numbers[item] <= new_a:
note_a.append(numbers[item])
new_a -= numbers[item]
elif numbers[item] <= new_b:
note_b.append(numbers[item])
else:
note_a.append(numbers[item] - 1)
new_a -= numbers[item] - 1
print(len(note_a))
print(*note_a)
print(len(note_b))
print(*note_b)
a, b = map(int, input().split())
count_2_days(a, b)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def Binary(s):
L = 0
R = s + 1
while L <= R - 1:
c = (L + R) // 2
x = (1 + c) * c // 2
if s == x:
return c
elif x < s:
L = c + 1
else:
R = c
return L - 1
a, b = map(int, input().split())
s = a + b
C = list(range(1, Binary(s) + 1))
A = []
B = []
for i in range(len(C) - 1, -1, -1):
n = C[i]
if a - C[i] >= 0:
a -= C[i]
A.append(C[i])
else:
B.append(C[i])
print(len(A))
print(*A)
print(len(B))
print(*B)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
n = int((1 + (1 + 8 * (a + b)) ** 0.5) / 2 - 1)
con = [x for x in range(1, n + 1)]
con = con[::-1]
con1 = []
con2 = []
a1 = a
b1 = b
a = max(a, b)
b = min(a1, b1)
for i in range(0, len(con)):
if a - con[i] > 0:
con1.append(con[i])
a -= con[i]
con[i] = 0
elif a - con[i] == 0:
con1.append(con[i])
con[i] = 0
break
con2 = []
for i in con:
if i != 0:
con2.append(i)
a2 = len(con1)
b2 = len(con2)
huy = con1[::-1]
huy1 = con2[::-1]
if a1 <= b1:
print(b2)
print(*huy1)
print(a2)
print(*huy)
else:
print(a2)
print(*huy)
print(b2)
print(*huy1)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
k = 1
s = 1
while s + (k + 1) <= a + b:
k += 1
s += k
p = []
q = []
sp = 0
use = set()
for i in range(1, k + 1)[::-1]:
if sp + i <= a:
p.append(i)
sp += i
use.add(i)
sq = 0
for i in range(1, k + 1)[::-1]:
if not i in use:
if sq + i <= b:
sq += i
q.append(i)
print(len(p))
print(*p)
print(len(q))
print(*q)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
n = 0
l = []
m = []
while (n + 1) * (n + 2) // 2 <= a + b:
n = n + 1
for i in range(n, 0, -1):
if a >= i:
a -= i
l.append(i)
else:
m.append(i)
print(len(l))
print(*l)
print(len(m))
print(*m)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a = input()
a, b = a.split(" ")
a = int(a)
b = int(b)
def binary_search(val):
l, r, ans = 1, val, -1
while l <= r:
mid = (l + r) // 2
if mid * (mid + 1) <= 2 * val:
ans = mid
l = mid + 1
else:
r = mid - 1
return ans
val = binary_search(a + b)
lista = []
listb = []
vis = [0] * (val + 1)
t = val
while a > 0 and t > 0:
if a >= t:
vis[t] = 1
lista.append(t)
a -= t
t -= 1
else:
vis[a] = 1
lista.append(a)
a = 0
t = 1
while b > 0:
if b < t:
break
elif vis[t] == 1:
t += 1
else:
b -= t
listb.append(t)
t += 1
print(len(lista))
for x in lista:
print(x, end=" ")
print("\n")
print(len(listb))
for x in listb:
print(x, end=" ")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
def numbers(n):
resp = []
curr = 1
while n >= curr:
resp.append(curr)
n -= curr
curr += 1
return resp
num = numbers(a + b)
anum = set()
for x in num[::-1]:
if a >= x:
a -= x
anum.add(x)
print(len(anum))
for x in anum:
print(x, end=" ")
print()
bnum = set(num) - anum
print(len(bnum))
for x in bnum:
print(x, end=" ")
print()
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
s = a + b
best = 0
for i in range(1, s + 1):
if i * (i + 1) // 2 <= s:
best = i
else:
break
save_best = best
first_day = set()
second_day = set()
while a != 0 and best != 0:
nxt = min(a, best)
best -= 1
first_day.add(nxt)
a -= nxt
for i in range(1, save_best + 1):
if i not in first_day:
second_day.add(i)
print(len(first_day))
print(" ".join(map(str, sorted(first_day))))
print(len(second_day))
print(" ".join(map(str, sorted(second_day))))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = [int(x) for x in input().split()]
s = 0
k = 0
m = []
while s <= a + b:
k += 1
s += k
m.append(k)
del m[k - 1]
d = a + b - s
p = []
for i in range(k - 2, -1, -1):
if a >= m[i]:
p.append(m[i])
a -= m[i]
del m[i]
print(len(p))
print(*p, sep=" ")
print(len(m))
print(*m, sep=" ")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
c = []
e = []
i = 1
s = 1
c.append(i)
e.append(i)
while s <= a + b:
i += 1
s += i
c.append(i)
e.append(i)
i = i - 1
c.pop()
e.pop()
i -= 1
j = -1
d = []
while j < i:
if c[i] <= a:
d.append(c[i])
a -= c[i]
e.pop(i)
i -= 1
print(len(d))
for i in d:
print(i, end=" ")
print()
print(len(e))
for i in e:
print(i, end=" ")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def ans_1():
print(len(day1))
for j in day1:
print(j, end=" ")
def ans_2():
print(i - len(day1) - 1 - 1)
for j in range(i - 2, 0, -1):
if j not in day1:
print(j, end=" ")
a, b = map(int, input().split())
c, d = a, b
a, b = min(a, b), max(a, b)
total = a + b
count = 0
i = 1
pre = 0
while count <= total:
count += i
pre = i
i += 1
pre -= 1
day1 = set()
adda = 0
last = 0
while adda < a:
adda += pre
day1.add(pre)
last = pre
pre -= 1
if day1:
day1.remove(last)
day1.add(last - (adda - a))
if c < d:
ans_1()
print()
ans_2()
else:
ans_2()
print()
ans_1()
|
FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
left, right = 0, 10**5
while left != right - 1:
mid = (left + right) // 2
a1, b1 = min(a, b), max(a, b)
for k in range(mid, 0, -1):
if k <= a1:
a1 -= k
else:
b1 -= k
if min(a1, b1) < 0:
right = mid
else:
left = mid
a1, b1 = min(a, b), max(a, b)
x, y = [], []
for k in range(left, 0, -1):
if k <= a1:
a1 -= k
x.append(k)
else:
b1 -= k
y.append(k)
if a > b:
x, y = y, x
print(len(x))
print(*x)
print(len(y))
print(*y)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
from sys import exit
def f1(a):
d = int((1 + 8 * a) ** 0.5)
fst = (d - 1) // 2
if fst != 0:
ost = a - fst * (fst + 1) // 2
p = ost // fst
ls1 = p + 1
lf1 = p + fst - ost % fst
ls2 = lf1 + 2
lf2 = fst + p + 1
return ls1, lf1, ls2, lf2
else:
return 1, 0, 1, 0
def f2(poss):
for pos in poss:
for i in range(pos[0], pos[1] + 1):
print(i, end=" ")
print()
def main():
a, b = map(int, input().split())
ls1, lf1, ls2, lf2 = f1(a)
print(lf1 - ls1 + 1 + lf2 - ls2 + 1)
f2(((ls1, lf1), (ls2, lf2)))
s = 0
i = 1
arr = []
while True:
if ls1 <= i <= lf1:
i = lf1
elif ls2 <= i <= lf2:
i = lf2
elif s + i <= b:
s += i
arr.append(str(i))
else:
break
i += 1
print(len(arr))
print(" ".join(arr))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR VAR VAR RETURN NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def print_set(n):
print(len(n))
n = [str(i) for i in n]
print(" ".join(n))
a, b = map(int, input().split())
s = a + b
used = 0
k = 1
A = []
B = []
while used + k <= s:
used += k
k += 1
k -= 1
while k > 0:
if k <= a:
A.append(k)
a -= k
else:
b -= k
B.append(k)
k -= 1
print_set(A)
print_set(B)
|
FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
total = a + b
s = 0
e = 10000000000.0
while s != e:
g = (s + e + 1) // 2
if g * (g + 1) // 2 > total:
e = g - 1
else:
s = g
total_book = int(s)
books = [i for i in range(1, total_book + 1)]
first_day = []
sec_day = []
k = len(books)
if a >= b:
while k != 0 and a != 0:
if a in books:
first_day.append(a)
c = a
a -= books[c - 1]
del books[c - 1]
else:
a -= books[-1]
first_day.append(books[-1])
del books[-1]
k = len(books)
sec_day = books[:]
else:
while k != 0 and b != 0:
if b in books:
sec_day.append(b)
c = b
b -= books[c - 1]
del books[c - 1]
else:
b -= books[-1]
sec_day.append(books[-1])
del books[-1]
k = len(books)
first_day = books[:]
print(len(first_day))
for book in first_day:
print(book, end=" ")
print()
print(len(sec_day))
for book in sec_day:
print(book, end=" ")
print()
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
inp = input().split()
a = int(inp[0])
b = int(inp[1])
x = 1
while (x + 1) * (x + 2) / 2 <= a + b:
x += 1
choice_map = [(False) for _ in range(x)]
choice_a = []
choice_b = []
aux_a = a
aux_b = b
for _i in range(x):
i = x - 1 - _i
if i + 1 <= aux_a and not choice_map[i]:
choice_a.append(i + 1)
aux_a -= i + 1
choice_map[i] = True
for _i in range(x):
i = x - 1 - _i
if i + 1 <= aux_b and not choice_map[i]:
choice_b.append(i + 1)
aux_b -= i + 1
choice_map[i] = True
print(len(choice_a))
for i in choice_a:
print(i, end=" ")
print("")
print(len(choice_b))
for i in choice_b:
print(i, end=" ")
print("")
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = input().split()
a, b = int(a), int(b)
c = a + b
i = 0
resa = []
resb = []
while c > 0:
i += 1
c -= i
if c < 0:
i -= 1
for j in range(i, 0, -1):
if a - j >= 0:
a -= j
resa.append(j)
else:
b -= j
resb.append(j)
print(len(resa))
for j in range(len(resa)):
print(resa[j], end=" ")
print("\n" + str(len(resb)))
for j in range(len(resb)):
print(resb[j], end=" ")
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
sum = a + b
m = 1
s = 0
while s + m <= sum:
s += m
m += 1
m -= 1
al = []
bl = []
for i in range(m, 0, -1):
if a - i >= 0:
al.append(i)
a -= i
elif b - i >= 0:
bl.append(i)
b -= i
print(len(al))
print(" ".join(map(str, al)))
print(len(bl))
print(" ".join(map(str, bl)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
curr = a
ind = 1
f = []
s = []
while curr >= ind:
f.append(ind)
curr -= ind
ind += 1
extra = -1
if curr and ind - curr <= ind:
f.append(ind)
extra = ind - curr
ind += 1
curr = b
while curr >= ind:
s.append(ind)
curr -= ind
ind += 1
if extra != -1:
print(len(f) - 1)
for i in f:
if i != extra:
print(i, end=" ")
print("")
if curr >= extra:
print(len(s) + 1)
print(extra, end=" ")
for i in s:
print(i, end=" ")
else:
print(len(s))
for i in s:
print(i, end=" ")
print("")
else:
print(len(f))
for i in f:
print(i, end=" ")
print("")
print(len(s))
for i in s:
print(i, end=" ")
print("")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split())
limit = 1
s = a + b
num = 0
while s >= num + limit:
num += limit
limit += 1
limit -= 1
a_array = []
b_array = []
for i in range(limit, 0, -1):
if i <= a:
a_array.append(i)
a -= i
elif i <= b:
b_array.append(i)
b -= i
print(len(a_array))
print(*a_array)
print(len(b_array))
print(*b_array)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
def main():
a, b = map(int, input().split())
mx = max(a, b)
mn = min(a, b)
s = mx + mn
k = int(0.5 * ((1 + 8 * s) ** 0.5 - 1))
rk = range(k, 0, -1)
st = {i: (True) for i in rk}
r1, r2 = mn, mx
xe, ie = 0, 0
for k in rk:
if k <= r1:
st[k] = "min"
ie += 1
r1 -= k
else:
st[k] = "max"
xe += 1
r2 -= k
if a == mx:
a_k, b_k = "max", "min"
a_q, b_q = xe, ie
else:
a_k, b_k = "min", "max"
a_q, b_q = ie, xe
print(a_q)
for e in st:
if st[e] == a_k:
print(e, end=" ")
print()
print(b_q)
for e in st:
if st[e] == b_k:
print(e, end=" ")
print()
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR STRING VAR NUMBER VAR VAR ASSIGN VAR VAR STRING VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = list(map(int, input().split()))
x = a + b
n = int((1 + 8 * x) ** 0.5 / 2 - 0.5)
flag = 0
if a > b:
a, b = b, a
flag = 1
ar1 = []
num1 = 0
for i in range(n, 0, -1):
if a - num1 >= i:
ar1.append(i)
num1 += i
ar2 = []
for i in range(1, n + 1):
if i not in ar1:
ar2.append(i)
if flag == 0:
print(len(ar1))
print(" ".join(map(str, ar1)))
print(len(ar2))
print(" ".join(map(str, ar2)))
else:
print(len(ar2))
print(" ".join(map(str, ar2)))
print(len(ar1))
print(" ".join(map(str, ar1)))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
A, B = map(int, input().split())
s = A + B
c = 0
k = 0
while c <= s:
k += 1
c += k
k -= 1
n = list()
m = list()
if A < B:
while k:
if A >= k:
n.append(k)
A -= k
else:
m.append(k)
k -= 1
else:
while k:
if B >= k:
m.append(k)
B -= k
else:
n.append(k)
k -= 1
print(len(n))
print(*n)
print(len(m))
print(*m)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR WHILE VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
capacity = [int(i) for i in input().split()]
x = 0
while x * (x + 1) // 2 <= sum(capacity):
x += 1
x -= 1
reading_list = [[], []]
cur_size = [0, 0]
for i in range(x, 0, -1):
for j in range(2):
if cur_size[j] + i <= capacity[j]:
cur_size[j] += i
reading_list[j].append(i)
break
for j in range(2):
print(len(reading_list[j]))
print(*reading_list[j])
|
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST LIST LIST ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = map(int, input().split(" "))
s = 0
k = 0
c = "1"
q = 0
while s < a + b:
k = k + 1
s += k
c = c + "0"
n = k
if s > a + b:
c = c[: s - a - b] + "1" + c[s - a - b + 1 :]
n = k - 1
l = k
m = 0
while m < a:
if c[l] == "0":
c = c[:l] + "2" + c[l + 1 :]
m = m + l
q += 1
l = l - 1
c = c[: l + 1] + "0" + c[l + 2 :]
c = c[: a - m + l + 1] + "2" + c[a - m + l + 2 :]
print(q)
for i in range(1, k + 1):
if c[i] == "2":
print(i, end=" ")
print()
if n - q > 0:
print(n - q)
for i in range(1, k + 1):
if c[i] == "0":
print(i, end=" ")
else:
print(0)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER
|
In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.
Lesha knows that today he can study for at most $a$ hours, and he will have $b$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $k$ in $k$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.
Thus, the student has to fully read several lecture notes today, spending at most $a$ hours in total, and fully read several lecture notes tomorrow, spending at most $b$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and whichΒ β in the second?
-----Input-----
The only line of input contains two integers $a$ and $b$ ($0 \leq a, b \leq 10^{9}$)Β β the number of hours Lesha has today and the number of hours Lesha has tomorrow.
-----Output-----
In the first line print a single integer $n$ ($0 \leq n \leq a$)Β β the number of lecture notes Lesha has to read in the first day. In the second line print $n$ distinct integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq a$), the sum of all $p_i$ should not exceed $a$.
In the third line print a single integer $m$ ($0 \leq m \leq b$)Β β the number of lecture notes Lesha has to read in the second day. In the fourth line print $m$ distinct integers $q_1, q_2, \ldots, q_m$ ($1 \leq q_i \leq b$), the sum of all $q_i$ should not exceed $b$.
All integers $p_i$ and $q_i$ should be distinct. The sum $n + m$ should be largest possible.
-----Examples-----
Input
3 3
Output
1
3
2
2 1
Input
9 12
Output
2
3 6
4
1 2 4 5
-----Note-----
In the first example Lesha can read the third note in $3$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $3$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.
In the second example Lesha should read the third and the sixth notes in the first day, spending $9$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $12$ hours in total.
|
a, b = [int(i) for i in input().split()]
x = 0
while x * (x + 1) // 2 <= a + b:
x += 1
x -= 1
Alist = []
Blist = []
curA = 0
curB = 0
for i in range(x, 0, -1):
if curA + i <= a:
curA += i
Alist.append(i)
elif curB + i <= b:
curB += i
Blist.append(i)
print(len(Alist))
print(*Alist)
print(len(Blist))
print(*Blist)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
p = int(input())
print((p // 2) ** 2 + p // 2 * (p % 2))
for i in range(p // 2):
for j in range(p // 2, p):
print(i + 1, j + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
a = int(input())
l, r = a // 2, (a + 1) // 2
print(l * r)
for i in range(0, l):
for j in range(0, r):
print(i + 1, j + l + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
n = int(input())
ans = 0
for i in range(2, n + 1):
ans += 1
for j in range(i - 3, 0, -2):
ans += 1
print(ans)
for i in range(2, n + 1):
print(i, i - 1)
for j in range(i - 3, 0, -2):
print(i, j)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
n = int(input())
if n == 1:
print(0)
elif n == 2:
print(1)
print(1, 2)
else:
fh = []
sh = []
for i in range(1, (n - 2) // 2 + 1):
fh.append(i + 2)
for i in range(3 + (n - 2) // 2, n + 1):
sh.append(i)
total = 1 + len(fh) * len(sh) + len(fh) + len(sh)
print(total)
print(1, 2)
for elm in fh:
print(1, elm)
for elm in sh:
print(2, elm)
for elm1 in fh:
for elm2 in sh:
print(elm1, elm2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
import sys
n = int(sys.stdin.readline())
print(n**2 // 4)
for i in range(n // 2):
for j in range(n // 2, n):
print(str(i + 1) + " " + str(j + 1))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
n = int(input())
a = list(range(1, n + 1))
edge = []
used = []
for i, u in enumerate(a):
for j in range(1, n, 2):
if i + j >= n:
continue
ind = i + j
edge.append([u, a[ind]])
print(len(edge))
for u, v in edge:
print("{} {}".format(u, v))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
import sys
input = sys.stdin.readline
n = int(input())
if n == 1:
print(0)
quit()
if n == 2:
print(1)
print(1, 2)
quit()
if n % 2 == 0:
k = (n - 2) // 2
l = (n - 2) // 2
z = k * l + l + k + 1
print(z)
l1 = []
l2 = []
print(1, 2)
for i in range(3, 3 + k):
l1.append(i)
for i in range(3 + k, 3 + k + l):
l2.append(i)
for i in l1:
print(1, i)
for i in l2:
print(2, i)
for i in l1:
for j in l2:
print(i, j)
quit()
k = (n - 2) // 2
l = n - 2 - k
z = k * l + l + k + 1
print(z)
l1 = []
l2 = []
print(1, 2)
for i in range(3, 3 + k):
l1.append(i)
for i in range(3 + k, 3 + k + l):
l2.append(i)
for i in l1:
print(1, i)
for i in l2:
print(2, i)
for i in l1:
for j in l2:
print(i, j)
quit()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
n = int(input())
a = range(1, n // 2 + 1)
b = range(n // 2 + 1, n + 1)
print(n // 2 * (n - n // 2))
for i in a:
for j in b:
print(i, j)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
def do():
n = int(input())
ln = n >> 1
res = []
for i in range(1, ln + 1):
for j in range(ln + 1, n + 1):
res.append((i, j))
return res
res = do()
print(len(res))
for x, y in res:
print(str(x) + " " + str(y))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
|
During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three cities from each of which one can get to any other one directly. That is, there was no cycle exactly as long as 3. Unfortunately, the road map has not been preserved till nowadays. Now the scientists are interested how much developed a country Ancient Berland was. Help them - find, what maximal number of roads could be in the country. You also have to restore any of the possible road maps.
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of cities in Berland.
Output
On the first line must be printed number m β the maximal number of roads in Berland. Then print m lines containing two numbers each β the numbers of cities that the given road joins. The cities are numbered with integers from 1 to n. If there are several variants of solving the problem, print any of them.
Examples
Input
3
Output
2
1 2
2 3
Input
4
Output
4
1 2
2 3
3 4
4 1
|
n = int(input())
adj = [([0] * (n + 1)) for i in range(n + 1)]
if n <= 3:
if n == 1:
print(0)
elif n == 2:
print(1)
print(1, 2)
else:
print(2)
print(1, 2)
print(2, 3)
exit(0)
m = 0
ans = []
for i in range(1, n):
ans.append([i, i + 1])
adj[i][i + 1] = 1
adj[i + 1][i] = 1
for i in range(1, n + 1):
for j in range(1, n + 1):
if i == j:
continue
elif adj[i][j] == 1 or adj[j][i] == 1:
continue
else:
f = 1
for k in range(1, n + 1):
if adj[i][k] == 1 and adj[j][k] == 1:
f = 0
break
if f == 1:
adj[i][j] = 1
adj[j][i] = 1
ans.append([i, j])
print(len(ans))
for i in range(len(ans)):
print(ans[i][0], ans[i][1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
try:
t = 1
t = int(input())
while t > 0:
n = int(input())
if n == 2:
print(0)
elif n % 2 == 1:
print((n - 1) // 2 * ((n + 1) // 2) - 1)
elif n % 2 == 0:
if (n // 2 - 1) % 2 == 1:
print((n // 2 - 1) * (n // 2 + 1) - 1)
else:
print((n // 2 - 2) * (n // 2 + 2) - 1)
except:
pass
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
for _ in range(int(input())):
n = int(input())
if n < 3:
print(0)
else:
if n % 2 == 1:
ret = (n + 1) // 2 * ((n - 1) // 2) - 1
elif n // 2 % 2 == 0:
ret = (n + 2) // 2 * ((n - 2) // 2) - 1
else:
ret = (n + 4) // 2 * ((n - 4) // 2) - 1
print(ret)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
ans = []
for _ in range(int(input())):
N = int(input())
N2 = N // 2
if N == 2:
an = 0
elif not N % 2:
if not N2 % 2:
an = N2**2 - 2
else:
an = N2**2 - 5
else:
an = (N - N2) * N2 - 1
ans.append(an)
print(*ans, sep="\n")
|
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
t = int(input())
for i in range(t):
n = int(input())
if n == 2:
print(0)
elif n % 2 == 0:
a = n // 2 - 1
b = a + 2
if a % 2 != 0 and b % 2 != 0:
print(a * b - 1)
else:
a -= 1
b += 1
print(a * b - 1)
else:
a = n // 2
b = a + 1
print(a * b - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return a / gcd(a, b) * b
for _ in range(int(input())):
n = int(input())
l = []
if n == 2:
print(0)
elif n % 2 == 1:
n = n + 1
n = int(n / 2)
l.append(n - 1)
l.append(n)
print(n * (n - 1) - 1)
else:
n1 = int(n / 2)
if n1 % 2 == 0:
l.append(n1 - 1)
l.append(n1 + 1)
print((n1 - 1) * (n1 + 1) - 1)
else:
n1 = int(n / 2)
l.append(n1 - 2)
l.append(n1 + 2)
print((n1 - 2) * (n1 + 2) - 1)
|
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
for _ in range(int(input())):
n = int(input())
ans = 0
if n & 1:
ans = (n // 2 + 1) * (n // 2) - 1
else:
if n == 2:
print(0)
continue
if n // 2 & 1:
m = n // 2
ans = (m - 2) * (m + 2) - 1
else:
m = n // 2
ans = (m - 1) * (m + 1) - 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
t = int(input())
def solve(x):
if x == 2:
return 0
t = x // 2
if x & 1 == 1:
return t * (t + 1) - 1
elif t % 2 == 0:
return (t - 1) * (t + 1) - 1
else:
return (t - 2) * (t + 2) - 1
for _ in range(t):
n = int(input())
print(solve(n))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
t = int(input())
for j in range(t):
n = int(input())
if n & 1:
a = int(n / 2)
b = int((n + 1) / 2)
print(a * b - 1)
elif n == 2:
print(0)
elif n == 4:
print(2)
elif n == 6:
print(4)
else:
k = int(n / 2)
if k & 1:
a = k - 1
b = k + 1
else:
a = k - 2
b = k + 2
x2 = 0
x1 = (a - 1) * (b + 1) - 1
if a + 1 != b - 1:
x2 = (a + 1) * (b - 1) - 1
print(max(x1, x2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum value of f(a, b) over all pairs (a, b) such that a and b are positive integers, and a + b = N?
------ Input Format ------
- The first line of input will contain an integer T β the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N, as described in the problem statement.
------ Output Format ------
For each test case, output the maximum value of f(a, b) that can be obtained while satisfying the conditions on a and b.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$2 β€ N β€ 10^{9}$
----- Sample Input 1 ------
3
3
4
6
----- Sample Output 1 ------
1
2
4
----- explanation 1 ------
Test case $1$: There are two possible pairs of $(a, b)$: $(1, 2)$ and $(2, 1)$. For both of these pairs, we have $\text{lcm}(a, b) = 2$ and $\gcd(a, b) = 1$, which gives $f(a, b) = 1$.
Test case $2$: For $(1, 3)$, we have $\text{lcm}(1, 3) = 3$ and $\gcd(1, 3) = 1$, giving $f(1, 3) = 3 - 1 = 2$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
Test case $3$: For $(1, 5)$, we have $\text{lcm}(1, 5) = 5$ and $\gcd(1, 5) = 1$, giving $f(1, 5) = 5 - 1 = 4$. It can be shown that this is the maximum possible value of $f(a, b)$ that can be obtained while satisfying the above conditions.
|
def gcd(m, n):
if n == 0:
return m
else:
return gcd(n, m % n)
t = int(input())
while t:
n = int(input())
if n == 2:
print(0)
elif n % 2 == 0:
if n // 2 % 2 == 0:
x = gcd(n // 2 - 1, n // 2 + 1)
l = (n // 2 - 1) * (n // 2 + 1) // x
print(l - x)
else:
x = gcd(n // 2 - 2, n // 2 + 2)
l = (n // 2 - 2) * (n // 2 + 2) // x
print(l - x)
else:
print(n // 2 * (n // 2 + 1) - 1)
t -= 1
|
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.