description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = [int(x) for x in input().split()]
n = a + b + c + d
if a > b + 1 or d > c + 1:
print("NO")
elif a == b + 1:
if c > 0 or d > 0:
print("NO")
else:
ls = [0, 1] * b + [0]
print("YES")
print(*ls)
elif d == c + 1:
if a > 0 or b > 0:
print("NO")
else:
ls = [3, 2] * c + [3]
print("YES")
print(*ls)
else:
ls1 = [0, 1] * a
ls2 = [2, 3] * d
b -= a
c -= d
if b == c:
print("YES")
print(*ls1, *([2, 1] * c), *ls2)
elif b > c:
if b == c + 1:
print("YES")
print(1, *ls1, *([2, 1] * c), *ls2)
else:
print("NO")
elif c == b + 1:
print("YES")
print(*ls1, *([2, 1] * b), *ls2, 2)
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR LIST NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR LIST NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP LIST NUMBER NUMBER VAR VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP LIST NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def find_ans(a, b, c, d):
if a == 0 and b == 0:
if d == c + 1:
str_ = "2 3 " * c
str_ = "3 " + str_
print("YES")
print(str_)
return
elif d == 0 and c == 0:
if a - 1 == b:
str_ = "0 1 " * b
str_ = str_ + "0"
print("YES")
print(str_)
return
if a > b or d > c:
print("NO")
return
str_left = "0 1 " * a
b = b - a
str_right = "2 3 " * d
c = c - d
str_val = "2 1 " * min(b, c)
b, c = b - min(b, c), c - min(b, c)
if b > 1 or c > 1:
print("NO")
return
if b == 1:
str_left = "1 " + str_left
if c == 1:
str_right += "2 "
result = str_left + str_val + str_right
print("YES")
print(result)
def main():
values = input()
values = values.split(" ")
find_ans(int(values[0]), int(values[1]), int(values[2]), int(values[3]))
main() | FUNC_DEF IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR IF VAR NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def printres(res):
print("YES")
print(" ".join(map(str, res)))
def main():
cc = [int(a) for a in input().split()]
nz = []
for i, c in enumerate(cc):
if c > 0:
nz.append(i)
if len(nz) == 1:
if cc[nz[0]] == 1:
printres([nz[0]])
else:
print("NO")
return
elif len(nz) == 2:
if nz[1] != nz[0] + 1:
print("NO")
return
df = cc[nz[1]] - cc[nz[0]]
if abs(df) > 1:
print("NO")
return
if df == 1:
printres([nz[1]] + [nz[0], nz[1]] * cc[nz[0]])
elif df == 0:
printres([nz[0], nz[1]] * cc[nz[0]])
else:
printres([nz[0], nz[1]] * cc[nz[1]] + [nz[0]])
return
elif len(nz) == 3:
if nz[2] != nz[1] + 1 or nz[1] != nz[0] + 1:
print("NO")
return
df = cc[nz[0]] + cc[nz[2]] - cc[nz[1]]
if abs(df) > 1:
print("NO")
return
if df == 1:
printres(
[nz[0], nz[1]] * cc[nz[0]] + [nz[2], nz[1]] * (cc[nz[2]] - 1) + [nz[2]]
)
elif df == 0:
printres([nz[0], nz[1]] * cc[nz[0]] + [nz[2], nz[1]] * cc[nz[2]])
else:
printres([nz[1]] + [nz[0], nz[1]] * cc[nz[0]] + [nz[2], nz[1]] * cc[nz[2]])
return
else:
df = cc[0] - cc[1] + cc[2] - cc[3]
if abs(df) > 1:
print("NO")
return
y = min(cc[1] - cc[0], cc[2] - cc[3])
if y < 0:
print("NO")
return
base = [0, 1] * cc[0] + [2, 1] * y + [2, 3] * cc[3]
if df == 1:
printres(base + [2])
elif df == 0:
printres(base)
else:
printres([1] + base)
return
main() | FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR NUMBER BIN_OP LIST VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST VAR NUMBER VAR NUMBER VAR VAR NUMBER LIST VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP LIST VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP LIST VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER LIST VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP LIST VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST VAR NUMBER BIN_OP LIST VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP LIST VAR NUMBER VAR NUMBER VAR VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER NUMBER VAR NUMBER BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR LIST NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR RETURN EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def main():
freq = [int(s) for s in input().split()]
for first in range(4):
f = [_ for _ in freq]
if f[first] == 0:
continue
res = [first]
f[first] -= 1
while True:
add = 0
while add < 4 and (f[add] == 0 or res[-1] - add not in {-1, 1}):
add += 1
if add == 4:
if sum(f) == 0:
print("YES\n" + " ".join(map(str, res)))
return
break
res.append(add)
f[add] -= 1
print("NO")
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep="\n")
def solve():
g = nl()
n = sum(g)
for i in range(4):
x = i
f = g[:]
l = list()
while True:
if not f[x]:
break
f[x] -= 1
l.append(x)
if x in (0, 3) or f[x ^ 1]:
x ^= 1
else:
x = 3 - x
if len(l) == n:
print("YES")
print(*l)
break
else:
print("NO")
return
solve() | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | n0, n1, n2, n3 = map(int, input().split())
num = []
if n0 - n1 >= 2 or n3 - n2 >= 2:
print("NO")
exit(0)
t1 = n1 - n0
t2 = n2 - n3
if t1 == -1:
if n2 == 0 and n3 == 0:
print("YES")
for i in range(n1):
print("0 1", end=" ")
print(0)
exit(0)
else:
print("NO")
exit(0)
if t2 == -1:
if n0 == 0 and n1 == 0:
print("YES")
for i in range(n2):
print("3 2", end=" ")
print(3)
exit(0)
else:
print("NO")
exit(0)
if t1 == t2:
print("YES")
for i in range(n0):
print("0 1", end=" ")
for i in range(t1):
print("2 1", end=" ")
for i in range(n3):
print("2 3", end=" ")
print("")
elif t1 == t2 + 1:
print("YES")
for i in range(n0):
print("1 0", end=" ")
print(1, end=" ")
for i in range(t2):
print("2 1", end=" ")
for i in range(n3):
print("2 3", end=" ")
elif t1 + 1 == t2:
print("YES")
for i in range(n0):
print("0 1", end=" ")
for i in range(t1):
print("2 1", end=" ")
for i in range(n3):
print("2 3", end=" ")
print(2)
else:
print("NO")
exit(0) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | from sys import stdin
def rl():
return [int(w) for w in stdin.readline().split()]
a, b, c, d = rl()
class Fail(Exception):
pass
def go(x):
s = [a, b, c, d]
r = []
while sum(s) > 0:
r.append(x)
s[x] -= 1
if s[x] < 0:
return
if x == 0:
x = 1
elif x == 1:
if s[0] < s[1] or s[0] == 0:
x = 2
else:
x = 0
elif x == 2:
if s[3] < s[2] or s[3] == 0:
x = 1
else:
x = 3
elif x == 3:
x = 2
return r
for start in range(4):
r = go(start)
if r:
print("YES")
print(*r)
break
else:
print("NO") | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST VAR VAR VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER RETURN IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = [int(x) for x in input().split(" ")]
if abs(a + c - b - d) > 1:
print("NO")
elif d > c:
if d - c > 1:
print("NO")
elif a != 0 or b != 0:
print("NO")
else:
print("YES")
for i in range(c):
print(3, 2, sep=" ", end=" ")
print(3)
elif a > b:
if a - b > 1:
print("NO")
elif c != 0 or d != 0:
print("NO")
else:
print("YES")
for i in range(b):
print(0, 1, sep=" ", end=" ")
print(0)
else:
print("YES")
if a + c >= b + d:
for i in range(a):
print(0, 1, sep=" ", end=" ")
for i in range(b - a):
print(2, 1, sep=" ", end=" ")
for i in range(d):
print(2, 3, sep=" ", end=" ")
for i in range(a + c - b - d):
print(2)
else:
print(1, end=" ")
for i in range(a):
print(0, 1, sep=" ", end=" ")
for i in range(b - a - 1):
print(2, 1, sep=" ", end=" ")
for i in range(d):
print(2, 3, sep=" ", end=" ") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def solve(a, e):
if not a[e]:
return False, []
a = list(a[:])
ans = [e]
a[e] -= 1
for i in range(sum(a)):
if ans[-1] - 1 >= 0 and a[ans[-1] - 1] > 0:
v = ans[-1] - 1
ans.append(v)
a[v] -= 1
elif ans[-1] + 1 <= 3 and a[ans[-1] + 1] > 0:
v = ans[-1] + 1
ans.append(v)
a[v] -= 1
else:
return False, []
return True, ans
def main():
a = list(map(int, input().split()))
for i in range(4):
r, b = solve(a, i)
if r:
print("YES")
print(*b)
return
print("NO")
main() | FUNC_DEF IF VAR VAR RETURN NUMBER LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN NUMBER LIST RETURN NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
reader = (map(int, line.split()) for line in sys.stdin)
input = reader.__next__
def beatSeq(a, b, c, d):
left = []
while a > 0 and b > 0:
left.append(0)
left.append(1)
a -= 1
b -= 1
if a > 1:
return None
elif a == 1:
if c + d > 0:
return None
else:
left.append(0)
return left
right = []
while d > 0 and c > 0:
right.append(3)
right.append(2)
d -= 1
c -= 1
if d > 1:
return None
elif d == 1:
if left or a + b > 0:
return None
else:
right.append(3)
return right
while b > 0 and c > 0:
left.append(2)
left.append(1)
b -= 1
c -= 1
if max(b, c) > 1:
return None
elif b > 0:
left = [1] + left
elif c > 0:
right = [2] + right
return left + [r for r in reversed(right)]
a, b, c, d = input()
ans = beatSeq(a, b, c, d)
if ans is None:
print("NO")
else:
print("YES")
print(*ans) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NONE IF VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NONE EXPR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NONE IF VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER RETURN NONE EXPR FUNC_CALL VAR NUMBER RETURN VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER RETURN NONE IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR RETURN BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
def weave(a, b, na, nb):
aNext = True
arr = []
while True:
if aNext:
if a == 0:
break
arr.append(na)
a -= 1
else:
if b == 0:
break
arr.append(nb)
b -= 1
aNext = not aNext
return arr
def main():
a, b, c, d = readIntArr()
A, B, C, D = a, b, c, d
left = weave(a, b, 0, 1)
rightReversed = weave(d, c, 3, 2)
for x in left:
if x == 0:
a -= 1
else:
b -= 1
for x in rightReversed:
if x == 2:
c -= 1
else:
d -= 1
if len(left) == 0 and a == 0 and b == 0:
if d > 0:
print("NO")
return
if c == 1:
rightReversed.insert(0, 2)
c -= 1
if c == 0:
print("YES")
oneLineArrayPrint(rightReversed)
else:
print("NO")
return
if len(rightReversed) == 0 and c == 0 and d == 0:
if a > 0:
print("NO")
return
if b == 1:
left.insert(0, 1)
b -= 1
if b == 0:
print("YES")
oneLineArrayPrint(left)
else:
print("NO")
return
if len(left) == 0 or left[-1] != 1:
if b == 0:
print("NO")
return
left.append(1)
b -= 1
if len(rightReversed) == 0 or rightReversed[-1] != 2:
if c == 0:
print("NO")
return
rightReversed.append(2)
c -= 1
if abs(b - c) > 2:
print("NO")
return
if b - c > 0:
if left[0] == 0:
left.insert(0, 1)
b -= 1
if b - c > 0:
if rightReversed[0] == 2:
rightReversed.insert(0, 1)
b -= 1
if c - b > 0:
if left[0] == 1:
left.insert(0, 2)
c -= 1
if c - b > 0:
if rightReversed[0] == 3:
rightReversed.insert(0, 2)
c -= 1
if c != b:
print("NO")
return
for _ in range(b):
left.append(2)
left.append(1)
ans = left + list(reversed(rightReversed))
print("YES")
oneLineArrayPrint(ans)
assert (
A == ans.count(0)
and B == ans.count(1)
and C == ans.count(2)
and D == ans.count(3)
)
return
input = lambda: sys.stdin.readline().rstrip("\r\n")
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print("\n".join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print("\n".join([" ".join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
def makeArr(defaultVal, dimensionArr):
dv = defaultVal
da = dimensionArr
if len(da) == 1:
return [dv for _ in range(da[0])]
else:
return [makeArr(dv, da[1:]) for _ in range(da[0])]
def queryInteractive(x, y):
print("? {} {}".format(x, y))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print("! {}".format(ans))
sys.stdout.flush()
inf = float("inf")
MOD = 10**9 + 7
for _abc in range(1):
main() | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE NUMBER IF VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
ip = lambda: sys.stdin.readline().rstrip()
a, b, c, d = map(int, ip().split())
ans = [-1] * (a + b + c + d)
if a - b > 1 or d - c > 1:
print("NO")
elif a - b == 1:
if c or d:
print("NO")
else:
print("YES")
print("0 1 " * b, end="")
print("0")
elif d - c == 1:
if a or b:
print("NO")
else:
print("YES")
print("3 2 " * c, end="")
print("3")
else:
ct1, ct2 = b - a, c - d
if abs(ct1 - ct2) > 1:
print("NO")
sys.exit(0)
else:
print("YES")
end = ""
if ct1 > ct2:
print("1 ", end="")
ct1 -= 1
elif ct2 > ct1:
end = "2"
print("0 1 " * a, end="")
print("2 1 " * ct1, end="")
print("2 3 " * d, end="")
print(end) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING STRING VAR NUMBER IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
arr = []
for i in range(c):
arr.append(-1)
arr.append(2)
for i in range(a):
arr.append(-1)
arr.append(0)
arr.append(-1)
la = len(arr)
i = 0
while d > 0 and i < la:
if arr[i] == -1:
if i > 0 and i != la - 1 and arr[i - 1] == 2 and arr[i + 1] == 2:
arr[i] = 3
d -= 1
elif i == 0 and i != la - 1 and arr[i + 1] == 2:
arr[i] = 3
d -= 1
elif i == la - 1 and i != 0 and arr[i - 1] == 2:
arr[i] = 3
d -= 1
elif la - 1 == 0:
arr[i] = 3
d -= 1
i += 1
else:
i += 1
i = la - 1
while i >= 0 and b > 0:
if arr[i] == -1:
arr[i] = 1
b -= 1
i -= 1
flag = 0
for i in range(1, la):
if arr[i] == -1:
if (
i > 0
and i != la - 1
and arr[i - 1] == 2
and arr[i + 1] == 2
and flag == 0
and arr[0] != -1
):
arr[i], arr[0] = arr[0], arr[i]
flag = 1
elif flag == 1 or flag == 0:
arr[i], arr[-1] = arr[-1], arr[i]
flag = 2
elif i != la - 1:
flag = 777
ans = []
if arr.count(-1) <= 2 and b == 0 and d == 0 and flag != 777:
for i in arr:
if i != -1:
ans.append(i)
flag = 0
for i in range(1, len(ans)):
if abs(ans[i] - ans[i - 1]) != 1:
flag = 777
if flag == 0 and ans:
print("YES")
print(*ans)
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
if a == b and b == 0:
if abs(c - d) > 1:
print("NO")
else:
print("YES")
if c > d:
for i in range(d):
print("2 3", end=" ")
print("2")
elif d > c:
for i in range(c):
print("3 2", end=" ")
print("3")
else:
for i in range(c):
print("3 2", end=" ")
print()
elif b == c and c == d and d == 0:
if a == 1:
print("YES")
print(0)
else:
print("NO")
elif a == c and c == d and d == 0:
if b == 1:
print("YES")
print(1)
else:
print("NO")
elif a == b and b == d and d == 0:
if c == 1:
print("YES")
print(2)
else:
print("NO")
elif a == b and b == c and c == 0:
if d == 1:
print("YES")
print(3)
else:
print("NO")
else:
ans = ""
flag = True
flag_1 = False
if b >= a:
if b > a:
ans += "1 "
flag = False
flag_1 = True
for i in range(a):
ans += "0 1 "
flag = False
b -= a + 1
if b <= 0:
if d == c - 1 or d == c:
for i in range(d):
ans += "2 3 "
if d == c - 1:
ans += "2"
print("YES")
print(ans)
elif d + 2 == c and flag_1:
for i in range(d):
ans += "2 3 "
print("YES")
print("2 " + ans + "2")
elif flag:
if d == c + 1:
for i in range(c):
ans += "3 2 "
ans += "3"
print("YES")
print(ans)
else:
print("NO")
elif c >= b:
for i in range(b):
ans += "2 1 "
c -= b
if c >= 1:
ans += "2 "
c -= 1
if d >= c:
if d == c or d == c + 1:
print("YES")
for i in range(c):
ans += "3 2 "
if d == c + 1:
ans += "3"
print(ans)
else:
print("NO")
elif d == 0 and c == 1:
print("YES")
print("2 " + ans)
elif d + 1 == c:
print("YES")
for i in range(d):
ans += "3 2 "
print("2 " + ans)
else:
print("NO")
else:
print("NO")
elif c == d and d == 0:
if a == b + 1:
print("YES")
print("0", end=" ")
for i in range(b):
print("1 0", end=" ")
print()
else:
print("NO")
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR STRING IF VAR IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER IF VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = list(map(int, input().split()))
b -= a
c -= d
arr = []
k = True
if b >= 0 and c >= 0:
if a == 0 and b == 0 and c == 1:
print("YES")
arr.append(2)
for i in range(d):
arr.append(3)
arr.append(2)
print(*arr, sep=" ")
k = False
elif d == 0 and c == 0 and b == 1:
print("YES")
arr.append(1)
for i in range(a):
arr.append(0)
arr.append(1)
print(*arr, sep=" ")
k = False
elif b == c and k:
print("YES")
if b == 0:
for i in range(a):
arr.append(0)
arr.append(1)
for i in range(d):
arr.append(2)
arr.append(3)
else:
for i in range(a):
arr.append(1)
arr.append(0)
for i in range(b):
arr.append(1)
arr.append(2)
for i in range(d):
arr.append(3)
arr.append(2)
print(*arr, sep=" ")
elif c - b == 1 and k:
print("YES")
if a > 0:
for i in range(a - 1):
arr.append(0)
arr.append(1)
arr.append(0)
arr.append(1)
arr.append(2)
else:
arr.append(2)
for i in range(c - 1):
arr.append(1)
arr.append(2)
for i in range(d):
arr.append(3)
arr.append(2)
print(*arr, sep=" ")
elif b - c == 1 and k:
print("YES")
for i in range(a):
arr.append(1)
arr.append(0)
for i in range(b - 1):
arr.append(1)
arr.append(2)
arr.append(1)
if d > 0:
arr.append(2)
for i in range(d - 1):
arr.append(3)
arr.append(2)
arr.append(3)
print(*arr, sep=" ")
else:
print("NO")
elif b == -1 and d == 0 and c == 0:
print("YES")
for i in range(a - 1):
arr.append(0)
arr.append(1)
arr.append(0)
print(*arr, sep=" ")
elif a == 0 and b == 0 and c == -1:
print("YES")
for i in range(d - 1):
arr.append(3)
arr.append(2)
arr.append(3)
print(*arr, sep=" ")
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
if abs(a + c - b - d) <= 1 and b >= a and c >= d:
print("YES")
if a + c > b + d:
for i in range(a):
print(0, 1, end=" ")
for i in range(b - a):
print(2, 1, end=" ")
for i in range(d):
print(2, 3, end=" ")
print(2)
elif a + c == b + d:
for i in range(a):
print(0, 1, end=" ")
for i in range(b - a):
print(2, 1, end=" ")
for i in range(d):
print(2, 3, end=" ")
elif a + c < b + d:
for i in range(d):
print(3, 2, end=" ")
for i in range(c - d):
print(1, 2, end=" ")
for i in range(a):
print(1, 0, end=" ")
print(1)
elif a == 0 and b == 0 and d - c == 1:
print("YES")
for i in range(c):
print(3, 2, end=" ")
print(3)
elif d == 0 and c == 0 and a - b == 1:
print("YES")
for i in range(b):
print(0, 1, end=" ")
print(0)
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING IF BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | g = list(map(int, input().split()))
v = [-1, 1, 0, 0, 1, -1]
g.insert(0, 0)
g.append(0)
for i in range(1, 5, 1):
if g[i] == 0:
continue
s = [i]
c = g.copy()
c[i] -= 1
while c[1] + c[2] + c[3] + c[4] > 0:
a = s[-1] - 1
b = s[-1] + 1
if v[b] > v[a]:
a, b = b, a
if c[a] == 0:
a = b
if c[a] == 0:
break
c[a] -= 1
s.append(a)
if c[1] + c[2] + c[3] + c[4] > 0:
continue
flag = True
for i in range(g[1] + g[2] + g[3] + g[4] - 1):
if abs(s[i + 1] - s[i]) != 1:
flag = False
break
if flag:
def f(a):
return str(a - 1)
print("YES")
print(" ".join(list(map(f, s))))
exit()
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
n = a + b + c + d
if n == 1 and a == 1:
print("YES")
print(0)
elif n == 2 and b == 2:
print("NO")
elif a == 0 and b == 0:
if c == 0:
if d == 1:
print("YES")
print(3)
else:
print("NO")
elif d == c - 1 or d == c or d == c + 1:
print("YES")
if d == c + 1:
print(3, end=" ")
n = n - 1
for i in range(n):
if i % 2 == 0:
print(2, end=" ")
else:
print(3, end=" ")
else:
print("NO")
elif d > c:
print("NO")
elif d == 0 and c == 0:
if b < a - 1 or b > a + 1:
print("NO")
else:
print("YES")
if b == a + 1:
print(1, end=" ")
n = n - 1
for i in range(n):
if i % 2 == 0:
print(0, end=" ")
else:
print(1, end=" ")
else:
nee = a + max(0, c - d - 1)
if b < nee or b > nee + 2:
print("NO")
elif b < a:
print("NO")
else:
print("YES")
if nee + 2 == b or b == nee + 1:
print(1, end=" ")
b = b - 1
for i in range(n - 1):
if i % 2 == 0 and a != 0:
print(0, end=" ")
a -= 1
elif i % 2 == 0 and c != 0:
print(2, end=" ")
c -= 1
elif b != 0:
print(1, end=" ")
b -= 1
else:
print(3, end=" ")
else:
for i in range(n):
if i % 2 == 0 and a != 0:
print(0, end=" ")
a -= 1
elif i % 2 == 0 and c != 0:
print(2, end=" ")
c -= 1
elif b != 0:
print(1, end=" ")
b -= 1
else:
print(3, end=" ") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def main():
A, B, C, D = map(int, input().split())
N = A + B + C + D
ans = [0] * N
a, b, c, d = A - 1, B, C, D
prev = 0
ok = 1
for i in range(1, N):
if a < 0 or b < 0 or c < 0 or d < 0:
ok = 0
break
if prev == 0:
b -= 1
ans[i] = 1
prev = 1
elif prev == 3:
c -= 1
ans[i] = 2
prev = 2
elif prev == 1:
if a:
a -= 1
ans[i] = 0
prev = 0
else:
c -= 1
ans[i] = 2
prev = 2
elif prev == 2:
if b:
b -= 1
ans[i] = 1
prev = 1
else:
d -= 1
ans[i] = 3
prev = 3
if a < 0 or b < 0 or c < 0 or d < 0:
ok = 0
if ok:
print("YES")
print(*ans)
exit()
ans = [0] * N
ans[0] = 1
a, b, c, d = A, B - 1, C, D
prev = 1
ok = 1
for i in range(1, N):
if a < 0 or b < 0 or c < 0 or d < 0:
ok = 0
break
if prev == 0:
b -= 1
ans[i] = 1
prev = 1
elif prev == 3:
c -= 1
ans[i] = 2
prev = 2
elif prev == 1:
if a:
a -= 1
ans[i] = 0
prev = 0
else:
c -= 1
ans[i] = 2
prev = 2
elif prev == 2:
if b:
b -= 1
ans[i] = 1
prev = 1
else:
d -= 1
ans[i] = 3
prev = 3
if a < 0 or b < 0 or c < 0 or d < 0:
ok = 0
if ok:
print("YES")
print(*ans)
exit()
ans = [0] * N
ans[0] = 2
a, b, c, d = A, B, C - 1, D
prev = 2
ok = 1
for i in range(1, N):
if a < 0 or b < 0 or c < 0 or d < 0:
ok = 0
break
if prev == 0:
b -= 1
ans[i] = 1
prev = 1
elif prev == 3:
c -= 1
ans[i] = 2
prev = 2
elif prev == 1:
if c:
c -= 1
ans[i] = 2
prev = 2
else:
a -= 1
ans[i] = 0
prev = 0
elif prev == 2:
if d:
d -= 1
ans[i] = 3
prev = 3
else:
b -= 1
ans[i] = 1
prev = 1
if a < 0 or b < 0 or c < 0 or d < 0:
ok = 0
if ok:
print("YES")
print(*ans)
exit()
ans = [0] * N
ans[0] = 3
a, b, c, d = A, B, C, D - 1
prev = 3
ok = 1
for i in range(1, N):
if a < 0 or b < 0 or c < 0 or d < 0:
ok = 0
break
if prev == 0:
b -= 1
ans[i] = 1
prev = 1
elif prev == 3:
c -= 1
ans[i] = 2
prev = 2
elif prev == 1:
if c:
c -= 1
ans[i] = 2
prev = 2
else:
a -= 1
ans[i] = 0
prev = 0
elif prev == 2:
if d:
d -= 1
ans[i] = 3
prev = 3
else:
b -= 1
ans[i] = 1
prev = 1
if a < 0 or b < 0 or c < 0 or d < 0:
ok = 0
if ok:
print("YES")
print(*ans)
else:
print("NO")
main() | FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
def main():
a, b, c, d = get_ints()
if a + b + c + d == 1:
print("YES")
if a == 1:
print(0)
return
if b == 1:
print(1)
return
if c == 1:
print(2)
return
if d == 1:
print(3)
return
def quit():
print("NO")
exit(0)
ans = []
if b > a:
ans.append(1)
b -= 1
while a > 0 and b > 0:
ans.append(0)
ans.append(1)
a -= 1
b -= 1
if a > 0 and c != 0 and d != 0:
quit()
while b > 0 and c > 0:
ans.append(2)
ans.append(1)
c -= 1
b -= 1
if b > 0:
quit()
if c == 0 and d != 0:
quit()
while c > 0 and d > 0:
ans.append(2)
ans.append(3)
c -= 1
d -= 1
if c:
ans.append(2)
c -= 1
if c == 1 and ans[0] == 1:
ans.insert(0, 2)
c -= 1
if d == 1 and ans[0] == 2:
ans.insert(0, 3)
d -= 1
if a == 1 and b == 0 and c == 0 and d == 0:
a -= 1
ans.append(0)
for i in range(1, len(ans)):
if abs(ans[i - 1] - ans[i]) != 1:
quit()
if a or b or c or d:
quit()
print("YES")
print(*ans)
get_array = lambda: list(map(int, sys.stdin.readline().split()))
get_ints = lambda: map(int, sys.stdin.readline().split())
input = lambda: sys.stdin.readline().strip()
main() | IMPORT FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
input = sys.stdin.readline
a, b, c, d = map(int, input().split())
res = 0
str1 = []
str2 = []
str3 = []
if a > 0:
str1.append("0 ")
a -= 1
if d > 0:
str2.append("3 ")
d = d - 1
res = 0
while a > 0:
if b > 0:
str1.append("1 0 ")
a -= 1
b -= 1
else:
res = -1
break
while d > 0:
if c > 0:
str2.append("2 3 ")
c -= 1
d -= 1
else:
res = -1
break
if len(str1) != 0 and len(str2) != 0 and (b == 0 or c == 0):
res = -1
if len(str1) == 0 and len(str2) != 0 and (c == 0 and b != 0):
res = -1
if len(str1) != 0 and len(str2) == 0 and (b == 0 and c != 0):
res = -1
while b > 0 and c > 0:
str3.append("1 2 ")
b -= 1
c -= 1
if b > 0:
if len(str1) != 0:
str4 = ["1 "]
str4.extend(str1)
str1 = str4
b -= 1
if b > 0 and len(str3) == 0:
str1.append("1 ")
b -= 1
if b > 0:
if len(str2) == 0 and len(str3) != 0:
str3.append("1 ")
b -= 1
if b > 0:
res = -1
if c > 0:
if len(str2) != 0:
str2.append("2 ")
c -= 1
if len(str3) == 0 and c > 0:
str3.append("2 ")
c -= 1
if c > 0:
if len(str1) == 0 and len(str3) != 0 and str3[0] != "2 ":
str4 = ["2 "]
str4.extend(str3)
str3 = str4
c -= 1
if c > 0:
res = -1
ans = ""
if res == 0:
str1.extend(str3)
str1.extend(str2)
print("YES")
ans = ans.join(str1)
print(ans)
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR LIST STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = [int(x) for x in input().split()]
dn = {(0): a, (1): b, (2): c, (3): d}
total = a + b + c + d
flag = 1
for i in range(4):
if dn[i] == 0:
continue
soln = []
soln.append(i)
td = dn.copy()
td[i] -= 1
last = i
for j in range(total - 1):
if td.get(last - 1, 0):
soln.append(last - 1)
td[last - 1] -= 1
last = last - 1
elif td.get(last + 1, 0):
soln.append(last + 1)
td[last + 1] -= 1
last = last + 1
else:
break
if len(soln) == total:
print("YES")
for i in soln:
print(i, end=" ")
print()
flag = 0
break
if flag:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a = list(map(int, input().split()))
s = a[0] + a[1] + a[2] + a[3]
out = []
if s == 1:
for i in range(4):
if a[i] > 0:
print("YES")
print(i)
return
for i in range(3):
fst, snd = i, i + 1
if a[fst] == a[snd]:
check = True
for j in range(4):
if j != fst and j != snd:
if a[j] != 0:
check = False
if check:
out = [i, i + 1] * a[fst]
print("YES")
print(" ".join(list(map(str, out))))
return
if a[fst] == a[snd] + 1:
check = True
for j in range(4):
if j != fst and j != snd:
if a[j] != 0:
check = False
if check:
out = [i, i + 1] * a[snd] + [i]
print("YES")
print(" ".join(list(map(str, out))))
return
if a[fst] + 1 == a[snd]:
check = True
for j in range(4):
if j != fst and j != snd:
if a[j] != 0:
check = False
if check:
out = [i + 1] + [i, i + 1] * a[fst]
print("YES")
print(" ".join(list(map(str, out))))
return
if a[1] < a[0]:
print("NO")
return
if a[2] < a[3]:
print("NO")
return
left = [0, 1] * a[0]
right = [2, 3] * a[3]
a[1] -= a[0]
a[2] -= a[3]
if a[1] == a[2] + 1:
out = [1] + left + [2, 1] * a[2] + right
print("YES")
print(" ".join(list(map(str, out))))
return
if a[1] == a[2]:
out = left + [2, 1] * a[1] + right
print("YES")
print(" ".join(list(map(str, out))))
return
if a[1] + 1 == a[2]:
out = left + [2, 1] * a[1] + right + [2]
print("YES")
print(" ".join(list(map(str, out))))
return
print("NO")
return | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP LIST VAR BIN_OP VAR NUMBER VAR VAR LIST VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP LIST VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP LIST NUMBER NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP LIST NUMBER NUMBER VAR NUMBER VAR LIST NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR STRING RETURN |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def make(num, a, b):
arr = [(a if i % 2 == 0 else b) for i in range(2 * num)]
return arr
def is_valid(a, n):
for i in range(1, n):
if abs(a[i] - a[i - 1]) != 1:
return False
return True
def solve(a):
ans = []
n = len(a)
flg = True
for i in range(n - 1):
if a[i] == 0:
continue
if a[i + 1] < a[i] - 1:
return False, None
break
arr = make(a[i] - 1, i, i + 1)
arr.append(i)
ans.extend(arr)
a[i + 1] -= a[i] - 1
a[i] = 0
if a[-1] not in [0, 1]:
return False, None
elif a[-1] == 1:
ans.append(n - 1)
flg = is_valid(ans, len(ans))
if flg == False:
return flg, None
return flg, ans
a = list(map(int, input().split()))
cur = 0
while a[0] == 0:
a.pop(0)
cur += 1
b = [x for x in a]
flg, ans = solve(a)
if flg == False:
if len(b) > 1 and b[1] > 0:
b[1] -= 1
flg, ans = solve(b)
if flg == False:
print("NO")
else:
print("YES")
ans = [1] + ans
print(" ".join([str(x + cur) for x in ans]))
else:
print("YES")
print(" ".join([str(x + cur) for x in ans])) | FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER RETURN NUMBER NONE ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER LIST NUMBER NUMBER RETURN NUMBER NONE IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR NONE RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR VAR VAR VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = [int(x) for x in input().split()]
if b >= a and c >= d:
b2 = b - a
c2 = c - d
if abs(c2 - b2) <= 1:
print("YES")
if c2 == b2:
print(" ".join("01" * a + "21" * c2 + "23" * d))
elif c2 == b2 - 1:
print(" ".join("1" + "01" * a + "21" * (b2 - 1) + "23" * d))
elif c2 == b2 + 1:
print(" ".join("2" + "32" * d + "12" * (c2 - 1) + "10" * a))
else:
print("NO")
elif d == c + 1 and a == 0 and b == 0:
print("YES")
print(" ".join("32" * c + "3"))
elif a == b + 1 and c == 0 and d == 0:
print("YES")
print(" ".join("01" * b + "0"))
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP STRING VAR STRING IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
x1 = b - a
x2 = c - d
if b == 0 and a == 0 and abs(c - d) <= 1:
if c <= d:
print("YES")
if d == 1 and c == 0:
ans = [3]
else:
ans = [3, 2] * c + [3] * (d - c)
print(*ans)
else:
print("YES")
if c == 1 and d == 0:
ans = [2]
else:
ans = [2, 3] * d + [2] * (c - d)
print(*ans)
elif c == 0 and d == 0 and abs(a - b) <= 1:
if a <= b:
print("YES")
if b == 1 and a == 0:
ans = [1]
else:
ans = [1, 0] * a + [1] * (b - a)
print(*ans)
else:
print("YES")
if a == 1 and b == 0:
ans = [0]
else:
ans = [0, 1] * b + [0] * (a - b)
print(*ans)
elif b < a or c < d:
print("NO")
elif a == b and c == d:
print("YES")
ans = [0, 1] * a + [2, 3] * c
print(*ans)
elif x1 == x2:
print("YES")
ans = [1, 0] * a + [1, 2] * x1 + [3, 2] * d
print(*ans)
elif x1 == x2 + 1:
print("YES")
ans = [1] + [0, 1] * a + [2, 1] * x2 + [2, 3] * d
print(*ans)
elif x1 + 1 == x2:
print("YES")
ans = [0, 1] * a + [2, 1] * x1 + [2, 3] * d + [2]
print(*ans)
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR LIST NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = list(map(int, input().split()))
try:
assert abs(a - b + c - d) < 2
ans = []
if not d:
ans = [1, 0] * a + [1, 2] * c
if a + c < b:
ans.append(1)
if a + c > b:
ans.pop(0)
elif not a:
ans = [2, 3] * d + [2, 1] * b
if d + b < c:
ans.append(2)
if d + b > c:
ans.pop(0)
elif a + c > b + d:
while a:
ans.append(0)
ans.append(1)
a -= 1
b -= 1
assert b >= 0
while b:
ans.append(2)
ans.append(1)
b -= 1
c -= 1
assert c >= 0
while c:
ans.append(2)
ans.append(3)
c -= 1
d -= 1
ans.pop()
else:
while d:
ans.append(3)
ans.append(2)
c -= 1
d -= 1
assert c >= 0
while c:
ans.append(1)
ans.append(2)
b -= 1
c -= 1
assert b >= 0
while b:
ans.append(1)
ans.append(0)
a -= 1
b -= 1
if a:
ans.pop()
print("YES")
print(*ans)
except AssertionError:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR LIST IF VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR WHILE VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
for st in range(4):
list = [a, b, c, d]
path = []
while True:
if list[st] == 0:
break
list[st] -= 1
path.append(st)
if st == 0:
st = 1
elif st == 3:
st = 2
elif st == 1:
if list[0] == 0:
st += 1
else:
st = 0
elif list[3] == 0:
st -= 1
else:
st += 1
if max(list) == 0:
print("YES")
for i in range(len(path)):
print(path[i], end="")
if i != len(path) - 1:
print(" ", end="")
else:
print("")
exit(0)
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR ASSIGN VAR LIST WHILE NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
sol = []
if a == 0 and b == 0:
if abs(c - d) <= 1:
if c == d:
for i in range(c):
sol.append(2)
sol.append(3)
elif c == d + 1:
for i in range(d):
sol.append(2)
sol.append(3)
sol.append(2)
elif d == c + 1:
for i in range(c):
sol.append(3)
sol.append(2)
sol.append(3)
print("YES")
print(*sol)
else:
print("NO")
elif c == 0 and d == 0:
if abs(a - b) <= 1:
if a == b:
for i in range(a):
sol.append(0)
sol.append(1)
elif a == b + 1:
for i in range(b):
sol.append(0)
sol.append(1)
sol.append(0)
elif b == a + 1:
for i in range(a):
sol.append(1)
sol.append(0)
sol.append(1)
print("YES")
print(*sol)
else:
print("NO")
else:
b1, b2, c1, c2 = -1, -1, -1, -1
found = False
for i in range(0, min(b, c) + 1):
b2 = i
c1 = i
b1 = b - b2
c2 = c - c1
if (a == b1 or a + 1 == b1) and (d == c2 or d + 1 == c2):
found = True
break
if found:
if a == b1:
for i in range(a):
sol.append(0)
sol.append(1)
else:
for i in range(a):
sol.append(1)
sol.append(0)
sol.append(1)
for i in range(b2):
sol.append(2)
sol.append(1)
if c2 == d:
for i in range(d):
sol.append(2)
sol.append(3)
else:
for i in range(d):
sol.append(2)
sol.append(3)
sol.append(2)
print("YES")
print(*sol)
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def getAns(a, b, c, d):
if a > b:
if a - b == 1 and c == 0 and d == 0:
print("YES")
li = []
li.append(0)
for i in range(b):
li.append(1)
li.append(0)
print(*li)
return
print("NO")
return
elif d > c:
if d - c == 1 and a == 0 and b == 0:
print("YES")
li = []
li.append(3)
for i in range(c):
li.append(2)
li.append(3)
print(*li)
return
print("NO")
return
ogB = b
ogC = c
b -= a
c -= d
li = []
diff = abs(b - c)
if diff <= 1:
print("YES")
for i in range(d):
li.append(3)
li.append(2)
for i in range(a):
li.append(1)
li.append(0)
if b > c:
for i in range(c):
li.append(1)
li.append(2)
li.append(1)
else:
for i in range(b):
li.append(1)
li.append(2)
if c > b:
li.insert(0, 2)
print(*li)
else:
print("NO")
asdf = [int(x) for x in input().split(" ")]
getAns(asdf[0], asdf[1], asdf[2], asdf[3]) | FUNC_DEF IF VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = list(map(int, input().split()))
n1 = a
n2 = b
n3 = c
n4 = d
l = list()
a1 = a
a2 = b
c1 = 0
c2 = 1
k = 0
f = 1
g1 = 1
g2 = 1
ans1 = 1
for i in range(0, a + b + c + d):
if a == 0 and g1:
g1 = 0
a = c
c1 = 2
if b == 0 and g2:
g2 = 0
b = d
c2 = 3
if i % 2 == 0:
if a == 0:
ans1 = 0
l.append(c1)
k = k + 1
a = a - 1
else:
if b == 0:
ans1 = 0
l.append(c2)
k = k + 1
b = b - 1
for i in range(0, k - 1):
if abs(l[i + 1] - l[i]) != 1:
f = 0
break
if f and ans1 == 1:
print("YES")
print(*l)
exit()
else:
ans1 = 0
ans2 = 1
a = n1
b = n2
c = n3
d = n4
l = list()
a1 = a
a2 = b
b, a = a, b
c1 = 1
c2 = 0
k = 0
f = 1
g1 = 1
g2 = 1
for i in range(0, a + b + c + d):
if a == 0 and g1:
g1 = 0
a = d
c1 = 3
if b == 0 and g2:
g2 = 0
b = c
c2 = 2
if i % 2 == 0:
if a == 0:
ans2 = 0
l.append(c1)
k = k + 1
a = a - 1
else:
if b == 0:
ans2 = 0
l.append(c2)
k = k + 1
b = b - 1
for i in range(0, k - 1):
if abs(l[i + 1] - l[i]) != 1:
f = 0
break
if f and ans2 == 1:
print("YES")
print(*l)
exit()
else:
ans2 = 0
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
def rint():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline().rstrip("\n")
def oint():
return int(input())
a, b, c, d = rint()
tot = a + b + c + d
ans = []
if a > b + 1 or d > c + 1:
print("NO")
exit()
if a == b + 1:
if c != 0 or d != 0:
print("NO")
exit()
print("YES")
for i in range(tot):
ans.append(i % 2)
print(*ans)
exit()
if d == c + 1:
if a != 0 or b != 0:
print("NO")
exit()
print("YES")
for i in range(tot):
ans.append((i + 1) % 2 + 2)
print(*ans)
exit()
while a > 0:
ans.append(0)
ans.append(1)
a -= 1
b -= 1
ans2 = []
while d > 0:
ans2.append(2)
ans2.append(3)
d -= 1
c -= 1
ans3 = []
while b > 0 and c > 0:
ans3.append(2)
ans3.append(1)
b -= 1
c -= 1
if b > 1 or c > 1:
print("NO")
exit()
if b == 1:
ans = [1] + ans
if c == 1:
ans2 = ans2 + [2]
ans4 = ans + ans3 + ans2
print("YES")
print(*ans4) | IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
input = sys.stdin.readline
A, B, C, D = map(int, input().split())
if A + C == B + D:
if B >= A and C >= D:
print("YES")
ans = []
for _ in range(D):
ans.append(3)
ans.append(2)
for _ in range(C - D):
ans.append(1)
ans.append(2)
for _ in range(A):
ans.append(1)
ans.append(0)
print(" ".join([str(a) for a in ans]))
else:
print("NO")
elif A + C == B + D + 1:
if B >= A and C >= D + 1:
print("YES")
ans = []
for _ in range(A):
ans.append(0)
ans.append(1)
for _ in range(B - A):
ans.append(2)
ans.append(1)
for _ in range(D):
ans.append(2)
ans.append(3)
ans.append(2)
print(" ".join([str(a) for a in ans]))
elif A == B + 1 and C == 0 and D == 0:
print("YES")
ans = []
for _ in range(B):
ans.append(0)
ans.append(1)
ans.append(0)
print(" ".join([str(a) for a in ans]))
else:
print("NO")
elif B + D == A + C + 1:
if B >= A + 1 and C >= D:
print("YES")
ans = []
for _ in range(D):
ans.append(3)
ans.append(2)
for _ in range(C - D):
ans.append(1)
ans.append(2)
for _ in range(A):
ans.append(1)
ans.append(0)
ans.append(1)
print(" ".join([str(a) for a in ans]))
elif D == C + 1 and A == 0 and B == 0:
print("YES")
ans = []
for _ in range(C):
ans.append(3)
ans.append(2)
ans.append(3)
print(" ".join([str(a) for a in ans]))
else:
print("NO")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
if not -1 <= a + c - b - d <= 1:
print("NO")
exit()
if a + b and d - c > 0 or c + d and a - b > 0:
print("NO")
exit()
if not a + b:
ansls = [2] * (c > d) + [3, 2] * min(c, d) + [3] * (d > c)
print("YES")
print(*ansls)
elif not c + d:
ansls = [1] * (b > a) + [0, 1] * min(a, b) + [0] * (a > b)
print("YES")
print(*ansls)
elif a and a + c >= b + d:
ansls = [0, 1] * (a - 1) + [0]
b -= a - 1
if b:
ansls.extend([1, 2] * (b - 1) + [1])
c -= b - 1
if c:
ansls.extend([2, 3] * (c - 1) + [2])
d -= c - 1
if d:
ansls.append(3)
print("YES")
print(*ansls)
elif d and b + d >= a + c:
ansls = [3, 2] * (d - 1) + [3]
c -= d - 1
if c:
ansls.extend([2, 1] * (c - 1) + [2])
b -= c - 1
if b:
ansls.extend([1, 0] * (b - 1) + [1])
a -= b - 1
if a:
ansls.append(0)
print("YES")
print(*ansls)
elif a:
ansls = [1, 0] * a
b -= a
if b:
ansls.extend([1, 2] * c)
b -= c
if b:
ansls.append(1)
print("YES")
print(*ansls)
elif d:
ansls = [2, 3] * d
c -= d
if c:
ansls.extend([2, 1] * b)
c -= b
if c:
ansls.append(2)
print("YES")
print(*ansls)
else:
ansls = [1] * (b > c) + [2, 1] * min(b, c) + [2] * (c > b)
print("YES")
print(*ansls) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER LIST NUMBER VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = [int(x) for x in input().split()]
res = [(0) for _ in range(a)]
res += [(2) for _ in range(c)]
if a + c < b + d:
ind = 0
else:
ind = 1
while b > 0:
res.insert(ind, 1)
ind += 2
b -= 1
while d > 0:
res.insert(ind, 3)
ind += 2
d -= 1
tr = True
for i in range(1, len(res)):
if abs(res[i - 1] - res[i]) != 1:
print("NO")
tr = False
break
if tr:
print("YES")
print(*res) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | n0, n1, n2, n3 = map(int, input().split())
if n2 + n3 == 0:
if n0 == n1:
print("YES")
for i in range(n0):
print(0, 1, end=" ")
elif abs(n0 - n1) == 1:
print("YES")
if n0 < n1:
print(1, end=" ")
for i in range(n0):
print(0, 1, end=" ")
else:
print(0, end=" ")
for i in range(n1):
print(1, 0, end=" ")
else:
print("NO")
elif n0 + n1 == 0:
if n2 == n3:
print("YES")
for i in range(n2):
print(2, 3, end=" ")
elif abs(n2 - n3) == 1:
print("YES")
if n2 < n3:
print(3, end=" ")
for i in range(n2):
print(2, 3, end=" ")
else:
print(2, end=" ")
for i in range(n3):
print(3, 2, end=" ")
else:
print("NO")
elif n0 + n3 == 0:
if n1 == n2:
print("YES")
for i in range(n1):
print(2, 1, end=" ")
elif abs(n2 - n1) == 1:
print("YES")
if n2 < n1:
print(1, end=" ")
for i in range(n2):
print(2, 1, end=" ")
else:
print(2, end=" ")
for i in range(n1):
print(1, 2, end=" ")
else:
print("NO")
elif n0 <= n1 and n3 <= n2 and n1 - n0 == n2 - n3:
print("YES")
for j in range(n0):
print(0, 1, end=" ")
for k in range(n1 - n0):
print(2, 1, end=" ")
for l in range(n3):
print(2, 3, end=" ")
elif n0 <= n1 and n3 <= n2 and n1 - n0 == n2 - n3 + 1:
print("YES")
print(1, end=" ")
for j in range(n0):
print(0, 1, end=" ")
for k in range(n2 - n3):
print(2, 1, end=" ")
for l in range(n3):
print(2, 3, end=" ")
elif n0 <= n1 and n3 <= n2 and n1 - n0 + 1 == n2 - n3:
print("YES")
for j in range(n0):
print(0, 1, end=" ")
for k in range(n1 - n0):
print(2, 1, end=" ")
for l in range(n3):
print(2, 3, end=" ")
print(2)
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING IF VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
readline = sys.stdin.readline
def check(A, B, C, D):
N = A + B + C + D
if not (A + C == N // 2 or A + C == -(-N // 2)):
return False
even = [2] * C + [0] * A
odd = [3] * D + [1] * B
ans = [None] * N
flag = B + D == -(-N // 2)
for i in range(N):
if (i % 2 == 0) == flag:
ans[i] = odd[i // 2]
else:
ans[i] = even[i // 2]
if all(abs(a2 - a1) == 1 for a1, a2 in zip(ans, ans[1:])):
return ans
return False
A, B, C, D = map(int, readline().split())
ans = check(A, B, C, D)
if ans == False:
print("NO")
else:
print("YES")
print(*ans) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
input = sys.stdin.readline
a, b, c, d = map(int, input().split())
if a > b + 1:
print("NO")
elif a == b + 1:
if c == d == 0:
print("YES")
arr = [0] + [1, 0] * b
print(*arr)
else:
print("NO")
elif d > c + 1:
print("NO")
elif d == c + 1:
if a == b == 0:
print("YES")
arr = [3] + [2, 3] * c
print(*arr)
else:
print("NO")
elif a == b:
arr = [0, 1] * a
if c == d:
print("YES")
arr.extend([2, 3] * c)
print(*arr)
elif c == d + 1:
print("YES")
arr.extend([2, 3] * d + [2])
print(*arr)
else:
print("NO")
elif c == d:
if b == a + 1:
print("YES")
arr = [1, 0] * a + [1] + [2, 3] * c
print(*arr)
else:
print("NO")
elif b - a == c - d:
print("YES")
arr = [0, 1] * a + [2, 1] * (b - a) + [2, 3] * d
print(*arr)
elif b - a == c - 1 - d:
print("YES")
arr = [0, 1] * a + [2, 1] * (b - a) + [2, 3] * d + [2]
print(*arr)
elif b - 1 - a == c - d:
print("YES")
arr = [1] + [0, 1] * a + [2, 1] * (b - 1 - a) + [2, 3] * d
print(*arr)
elif b - 1 - a == c - 1 - d:
print("YES")
arr = [1] + [0, 1] * a + [2, 1] * (b - 1 - a) + [2, 3] * d + [2]
print(*arr)
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR LIST NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER NUMBER VAR LIST NUMBER BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER BIN_OP VAR VAR BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER BIN_OP VAR VAR BIN_OP LIST NUMBER NUMBER VAR LIST NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER NUMBER VAR BIN_OP LIST NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP LIST NUMBER NUMBER VAR LIST NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | _count = list(map(int, input().split()))
num = "0 1 2 3".split()
for pos in range(4):
count = _count[:]
ans = []
for i in range(sum(count)):
ans.append(num[pos])
count[pos] -= 1
if pos == 1:
if count[0] > 0:
pos = 0
else:
pos = 2
elif pos == 2:
if count[3] > 0:
pos = 3
else:
pos = 1
elif pos == 0:
pos = 1
elif pos == 3:
pos = 2
if max(count) == min(count) == 0:
print("YES")
print(*ans)
exit()
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def printit(s):
print("YES")
print(*s)
exit()
def solve(j, i):
tt = sum(j)
jj = []
for nn in j:
jj.append(nn)
s = []
while 1:
if i == 4 or jj[i] == 0:
break
s.append(i)
jj[i] -= 1
if i > 0 and jj[i - 1] > 0:
i -= 1
else:
i += 1
if len(s) == tt:
printit(s)
l = list(map(int, input().split()))
for i in range(0, 4):
solve(l, i)
print("NO") | FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
def Solve1(A, s, t):
seq = list(range(s, t + 1))
for i in seq:
A[i] -= 1
if any(A[i] < 0 for i in range(4)):
return None
if any(A[i] > 0 for i in range(4)):
lo = min(i for i in range(4) if A[i] > 0)
hi = max(i for i in range(4) if A[i] > 0)
if any(A[i] == 0 for i in range(lo, hi)):
return None
k = s
while k > lo:
if A[k - 1] == 0 or A[k] == 0:
return None
j = seq.index(k)
seq[j:j] = [k, k - 1]
A[k] -= 1
A[k - 1] -= 1
k -= 1
k = t
while k < hi:
if A[k] == 0 or A[k + 1] == 0:
return None
j = seq.index(k)
seq[j:j] = [k, k + 1]
A[k] -= 1
A[k + 1] -= 1
k += 1
ops = [0, 0, 0]
ops[0] = A[0]
ops[1] = A[1] - ops[0]
ops[2] = A[2] - ops[1]
for x in ops:
if x < 0:
return None
if ops[2] != A[3]:
return None
ans = []
for x in seq:
ans.append(x)
if x < 3 and ops[x] > 0:
ans.extend([x + 1, x] * ops[x])
ops[x] = 0
elif x > 0 and ops[x - 1] > 0:
ans.extend([x - 1, x] * ops[x - 1])
ops[x - 1] = 0
return ans
def Solve(A):
if A[1] == 0 and A[0] > 0 and A[2] + A[3] > 0:
return None
if A[2] == 0 and A[3] > 0 and A[0] + A[1] > 0:
return None
for s in range(4):
for t in range(s, 4):
att = Solve1(A[:], s, t)
if att is not None:
return att
return None
def SolvePrint(A):
ans = Solve(A)
if ans is None:
print("NO")
else:
print("YES")
print(" ".join(str(x) for x in ans))
def Test():
for i in range(10000):
t = i
a = []
for _ in range(4):
a.append(t % 10)
t //= 10
print(a, end=": ")
SolvePrint(a)
print("Done")
def Main():
A = list(map(int, sys.stdin.readline().split()))
SolvePrint(A)
Main() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER RETURN NONE IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR RETURN NONE ASSIGN VAR VAR WHILE VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR NUMBER RETURN NONE IF VAR NUMBER VAR NUMBER RETURN NONE ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP LIST BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN NONE IF VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN NONE FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NONE RETURN VAR RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def sexy(a):
a.append(0)
k = sum(a)
b = a[:]
s0 = []
s1 = []
i = 0
j = 1
c = 0
while True:
if c % 2 == 0:
while a[i] == 0 and i < 4:
i += 1
if i == 4:
break
if i == j:
i += 1
while a[i] == 0 and i < 4:
i += 1
if i == 4:
break
s0.append(i)
a[i] -= 1
else:
while a[j] == 0 and j < 4:
j += 1
if j == 4:
break
if i == j:
j += 1
while a[j] == 0 and j < 4:
j += 1
if j == 4:
break
s0.append(j)
a[j] -= 1
c += 1
i = 1
j = 0
c = 0
while True:
if c % 2 == 0:
while b[i] == 0 and i < 4:
i += 1
if i == 4:
break
if i == j:
i += 1
while b[i] == 0 and i < 4:
i += 1
if i == 4:
break
s1.append(i)
b[i] -= 1
else:
while b[j] == 0 and j < 4:
j += 1
if j == 4:
break
if i == j:
j += 1
while b[j] == 0 and j < 4:
j += 1
if j == 4:
break
s1.append(j)
b[j] -= 1
c += 1
if k == 1:
print("YES")
return [s0 if len(s0) == 1 else s1, True]
ok1 = True
ok2 = True
for i in range(1, len(s0)):
if abs(s0[i] - s0[i - 1]) != 1:
ok1 = False
break
if len(s0) != k:
ok1 = False
for i in range(1, len(s1)):
if abs(s1[i] - s1[i - 1]) != 1:
ok2 = False
break
if len(s1) != k:
ok2 = False
if ok1:
print("YES")
return [s0, True]
elif ok2:
print("YES")
return [s1, True]
else:
return [[], False]
def main():
a = list(map(int, input().split()))
b = a[:]
p = sexy(b)
if p[1]:
print(*p[0])
return
else:
a = a[::-1]
p = sexy(a)
if not p[1]:
print("NO")
return
for i in range(len(p[0])):
p[0][i] = 3 - p[0][i]
print(*p[0])
return
main() | FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN LIST FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING RETURN LIST VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING RETURN LIST VAR NUMBER RETURN LIST LIST NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
if a > b + 1 or b > a + c + 1 or c > b + d + 1 or d > c + 1:
print("NO")
else:
d1 = d
d2 = d
L1 = ["k"]
L2 = ["k"]
for i in range(a):
L1.append(0)
L1.append("k")
L2.append(0)
L2.append("k")
for i in range(c):
L1.append(2)
L1.append("k")
L2.append(2)
L2.append("k")
ptr1 = 0
for i in range(b):
if ptr1 >= len(L1):
break
L1[ptr1] = 1
ptr1 += 2
for i in range(ptr1, len(L1), 2):
L1[i] = 3
d1 -= 1
ptr2 = 2
for i in range(b):
if ptr2 >= len(L2):
break
L2[ptr2] = 1
ptr2 += 2
for i in range(ptr2, len(L2), 2):
L2[i] = 3
d2 -= 1
if len(L1) > 0 and L1[-1] == "k" or d1 == -1:
L1 = L1[: len(L1) - 1]
if len(L1) > 0 and L1[0] == "k":
L1 = L1[1:]
if len(L2) > 0 and L2[-1] == "k" or d2 == -1:
L2 = L2[: len(L2) - 1]
if len(L2) > 0 and L2[0] == "k":
L2 = L2[1:]
flag = 0
if (
L1.count(0) != a
or L1.count(1) != b
or L1.count(2) != c
or L1.count(3) != d
or L1.count("k") > 0
):
flag = 1
if flag == 0:
for i in range(0, len(L1) - 1):
if abs(L1[i] - L1[i + 1]) != 1:
flag = 1
break
if flag == 0:
print("YES")
print(*L1)
else:
if (
L2.count(0) != a
or L2.count(1) != b
or L2.count(2) != c
or L2.count(3) != d
or L2.count("k") > 0
):
flag = 2
if flag == 1:
for i in range(0, len(L2) - 1):
if abs(L2[i] - L2[i + 1]) != 1:
flag = 2
break
if flag == 1:
print("YES")
print(*L2)
if flag == 2:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST STRING ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
from sys import stdin, stdout
def ispossible(a, b, c, d):
if (
b >= a - 1
and c >= d - 1
and (b - a == c - d or b - a + 1 == c - d or b - a == c - d + 1)
):
return True
else:
return False
A = stdin.readline().strip().split()
a = int(A[0])
b = int(A[1])
c = int(A[2])
d = int(A[3])
if not ispossible(a, b, c, d):
print("NO")
sys.exit()
res = []
rng = a + b + c + d
pre = -1
for i in range(a + b + c + d):
if (pre == 1 or pre == -1) and a > 0 and ispossible(a - 1, b, c, d):
a -= 1
res.append(0)
pre = 0
elif (pre == 0 or pre == 2 or pre == -1) and b > 0 and ispossible(a, b - 1, c, d):
b -= 1
res.append(1)
pre = 1
elif (pre == 1 or pre == 3 or pre == -1) and c > 0 and ispossible(a, b, c - 1, d):
c -= 1
res.append(2)
pre = 2
elif (pre == 2 or pre == -1) and d > 0 and ispossible(a, b, c, d - 1):
d -= 1
res.append(3)
pre = 3
else:
print("NO")
sys.exit()
print("YES")
print(" ".join(map(str, res))) | IMPORT FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | from sys import stdin
input = stdin.readline
a, b, c, d = map(int, input().split())
if abs(a + c - b - d) > 1:
print("NO")
exit(0)
ans = [-1]
for i in range(a + c):
if i < c:
ans.append(2)
ans.append(-1)
else:
ans.append(0)
ans.append(-1)
def check(lst):
pre = -1
for i in lst:
if pre != -1 and abs(pre - i) != 1:
return False
pre = i
return True
if a + c <= b + d:
i = 0
while i // 2 < b + d:
if i // 2 < d:
ans[i] = 3
else:
ans[i] = 1
i += 2
if check(ans[: a + b + c + d]):
print("YES")
print(*ans[: a + b + c + d])
else:
print("NO")
else:
i = 2
while i // 2 - 1 < b + d:
if i // 2 - 1 < d:
ans[i] = 3
else:
ans[i] = 1
i += 2
if check(ans[1 : a + b + c + d + 1]):
print("YES")
print(*ans[1 : a + b + c + d + 1])
else:
print("NO") | ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR RETURN NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
input = sys.stdin.readline
a, b, c, d = map(int, input().split())
for start in range(4):
ANS = []
now = start
A = [a, b, c, d]
if A[now] == 0:
continue
while True:
A[now] -= 1
ANS.append(now)
if now == 0:
if A[1] != 0:
now = 1
else:
break
elif now == 1:
if A[0] != 0:
now = 0
elif A[2] != 0:
now = 2
else:
break
elif now == 2:
if A[3] != 0:
now = 3
elif A[1] != 0:
now = 1
else:
break
elif A[2] != 0:
now = 2
else:
break
if max(A) == 0:
print("YES")
print(*ANS)
sys.exit()
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR IF VAR VAR NUMBER WHILE NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
if a > b and (d != 0 or c != 0):
print("NO")
elif a == 1 and b == 0 and c == 0 and d == 0:
print("YES")
print(0)
elif a == 0 and b == 1 and c == 0 and d == 0:
print("YES")
print(1)
elif a == 0 and b == 0 and c == 1 and d == 0:
print("YES")
print(2)
elif a == 0 and b == 0 and c == 0 and d == 1:
print("YES")
print(3)
elif a == 0 and b == 0:
ans = []
if d == c:
for i in range(c):
ans.append(2)
ans.append(3)
print("YES")
print(*ans)
elif c - d == 1:
for i in range(d):
ans.append(2)
ans.append(3)
ans.append(2)
print("YES")
print(*ans)
elif d - c == 1:
for i in range(c):
ans.append(3)
ans.append(2)
ans.append(3)
print("YES")
print(*ans)
else:
print("NO")
elif a == b:
ans = []
if d == c or d == c - 1:
for i in range(a):
ans.append(0)
ans.append(1)
for i in range(d):
ans.append(2)
ans.append(3)
if d == c - 1:
ans.append(2)
print("YES")
print(*ans)
else:
print("NO")
else:
ans = []
if b - a > c - d:
for i in range(a):
ans.append(1)
ans.append(0)
ans.append(1)
if c >= b - a - 1:
for i in range(b - a - 1):
ans.append(2)
ans.append(1)
if d == c - (b - a - 1) or d == c - (b - a - 1) - 1:
for i in range(d):
ans.append(2)
ans.append(3)
if d == c - (b - a - 1) - 1:
ans.append(2)
print("YES")
print(*ans)
else:
print("NO")
else:
print("NO")
else:
for i in range(min(a, b)):
ans.append(0)
ans.append(1)
if c >= b - a and c != 0:
for i in range(b - a):
ans.append(2)
ans.append(1)
if d == c - (b - a) or d == c - (b - a) - 1:
for i in range(d):
ans.append(2)
ans.append(3)
if d == c - (b - a) - 1:
ans.append(2)
print("YES")
print(*ans)
else:
print("NO")
elif a - b == 1:
ans.append(0)
print("YES")
print(*ans)
else:
print("NO") | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR LIST IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST IF BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
length = min(a, b)
a, b = a - length, b - length
answer = [0, 1] * length
length = min(c, d)
c, d = c - length, d - length
answer.extend([2, 3] * length)
length = min(b, c)
b, c = b - length, c - length
answer.extend([2, 1] * length)
if a > 0:
answer.append(0)
a -= 1
if b > 0:
answer.insert(0, 1)
b -= 1
if c > 0:
answer.append(2)
c -= 1
if d > 0:
answer.insert(0, 3)
d -= 1
is_right = True
for i in range(0, len(answer) - 1):
if abs(answer[i] - answer[i + 1]) != 1:
is_right = False
break
if not is_right or a + b + c + d:
print("NO")
else:
print("YES")
print(*answer) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | a, b, c, d = map(int, input().split())
if a > b + 1 or d > c + 1:
print("NO")
elif a == b + 1:
if c == d == 0:
print("YES")
print("0 1 " * b + " 0")
else:
print("NO")
elif d == c + 1:
if a == b == 0:
print("YES")
print("3 2 " * c + " 3")
else:
print("NO")
else:
b -= a
c -= d
k = min(b, c)
if abs(b - c) >= 2:
print("NO")
else:
xb, xc = b - k, c - k
ans = "1" * xb + "01" * a + "21" * k + "23" * d + "2" * xc
print("YES")
print(" ".join(ans)) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR STRING VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | def find_start_old(freq):
largest = max(freq)
if freq.count(largest) == 1 or freq[0] == largest:
return freq.index(largest)
if freq[-1] == largest:
return 3
if freq[0] > freq[-1]:
return 2
return 1
def find_start(freq):
temp = [0] + freq + [0]
diff = [(temp[i] - temp[i - 1] - temp[i + 1]) for i in range(1, len(temp) - 1)]
return diff.index(max(diff))
def populate(freq, start):
result = []
while freq.count(0) != 4:
if freq[start] == 0:
return False, []
result.append(str(start))
freq[start] -= 1
if start == 0 or start == 1 and freq[0] == 0 or start == 2 and freq[3] != 0:
start += 1
else:
start -= 1
return True, " ".join(result)
freq = [int(i) for i in input().split()]
for i in range(4):
exists, string = populate(freq[:], i)
if exists:
print("YES")
print(string)
break
if not exists:
print("NO") | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR RETURN FUNC_CALL VAR VAR IF VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST WHILE FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER RETURN NUMBER LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING |
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \leq i \leq n - 1$.
Trans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
-----Input-----
The only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \leq 10^5$).
-----Output-----
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.
If there are multiple answers, you can print any of them.
-----Examples-----
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
-----Note-----
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | import sys
a, b, c, d = map(int, input().split())
x = []
y = []
for i in range(a):
x.append(0)
for i in range(b):
y.append(1)
for i in range(c):
x.append(2)
for i in range(d):
y.append(3)
p = []
if len(x) < len(y):
x, y = y, x
i = 0
j = 0
if len(x) != len(y):
p.append(x[0])
j += 1
x, y = y, x
while i < len(x) and j < len(y):
p.append(x[i])
p.append(y[j])
i += 1
j += 1
if len(p) != a + b + c + d:
print("NO")
sys.exit(0)
for t in range(len(p) - 1):
if p[t] - p[t + 1] != 1 and p[t] - p[t + 1] != -1:
print("NO")
sys.exit(0)
print("YES")
print(*p) | IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | import sys
def main():
input = sys.stdin
if len(sys.argv) >= 2:
input = open(sys.argv[1], "r")
n = int(input.readline().strip())
for i in range(n):
input.readline()
size = int(input.readline().strip())
mtrx = [[int(t) for t in input.readline().strip()] for i in range(size)]
countOnesOnDiag = lambda idx, m, sz: sum(
[m[(idx + k) % size][k] for k in range(sz)]
)
OnesOnDiag = [countOnesOnDiag(i, mtrx, size) for i in range(size)]
tmax = max(OnesOnDiag)
tsum = sum(OnesOnDiag)
print(size - tmax + tsum - tmax)
main() | IMPORT FUNC_DEF ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | def minburles(matrix):
n = len(matrix)
num1 = 0
numd = 0
for j0 in range(n):
j = j0
cnt = 0
for i in range(n):
if matrix[i][j] == 1:
cnt += 1
num1 += 1
j += 1
j %= n
numd = max(numd, cnt)
return n + num1 - 2 * numd
t = int(input())
for _ in range(t):
_ = input()
n = int(input())
matrix = []
for i in range(n):
matrix.append([int(x) for x in input()])
print(minburles(matrix)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | def intlist():
return [int(i) for i in input()]
def solve():
pp = input()
n = int(input())
l = []
oness = 0
for i in range(n):
ll = intlist()
oness += ll.count(1)
l.append(ll + ll)
ma = 0
for i in range(0, n):
d = 0
for j in range(0, n):
d += l[j][i + j]
if d > ma:
ma = d
ans = oness - ma + (n - ma)
return ans
t = input()
for tt in range(int(t)):
print(solve()) | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | for _ in range(int(input())):
input()
n = int(input())
x = 0
mat = []
ans = 0
for i in range(n):
temp = input()
mat.append(temp)
x += temp.count("1")
for i in range(n):
cur = 0
for j in range(n):
if mat[j][(j + i) % n] == "1":
cur += 1
ans = max(ans, cur)
print(x - ans + (n - ans)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | for i in range(int(input())):
input()
ans, size = 0, int(input())
matrix = [list(map(int, list(input()))) for line in range(size)]
diagonals = []
for x in range(size):
diagonals.append(sum(matrix[y][(x + y) % size] for y in range(size)))
best = sorted(diagonals)[-1]
print(str(size - best + sum(diagonals) - best)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | def solution():
newline = input()
n = int(input())
A = []
count_one = 0
for _ in range(n):
row = [int(i) for i in input()]
A.append(row)
count_one += sum(row)
max_one = 0
for i in range(n):
record = 0
for j in range(n):
record += A[j][(i + j) % n]
max_one = max(max_one, record)
zero_to_one = n - max_one
one_to_zero = count_one - max_one
print(zero_to_one + one_to_zero)
t = int(input())
for _ in range(t):
solution() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | def solve():
input()
n = int(input())
matrix = tuple(tuple(int(i) for i in iter(input())) for _ in range(n))
cached = tuple(sum(matrix[k][k + i - n] for k in range(n)) for i in range(n))
print(sum(cached) + n - 2 * max(cached))
for _ in range(int(input())):
solve() | FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | T = int(input())
while T > 0:
T -= 1
input()
n = int(input())
arr = []
for i in range(n):
tmp = input()
arr.append(tmp)
ans = 0
cnt = 0
for i in range(n):
tmp = 0
for j in range(n):
if arr[j][(i + j) % n] == "1":
tmp += 1
cnt += 1
ans = max(ans, tmp)
print(cnt + n - ans - ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | t = int(input())
while t:
n = input()
if n != "":
n = int(n)
ones = [0] * n
for turn in range(n):
s = input()
for i in range(n):
if s[i] == "1":
ones[i - turn] = ones[i - turn] + 1
print(sum(ones) - max(ones) + n - max(ones))
else:
continue
t = t - 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | for _ in range(int(input())):
input()
n = int(input())
a = [list(map(int, input())) for _ in range(n)]
s = sum(map(sum, a))
u = max(sum(a[i][(i + d) % n] for i in range(n)) for d in range(n))
print(n - u + (s - u)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | def count(b, n):
l = []
for i in range(n):
c = 0
for j in range(n):
if b[j][j - i] == "1":
c += 1
l.append(c)
return l
for i in range(int(input())):
s = input()
n = int(input())
p = []
for j in range(n):
p.append(input())
s = count(p, n)
print(n - 2 * max(s) + sum(s)) | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | T = int(input())
q = []
for i in range(T):
input()
n = int(input())
m = []
for i in range(n):
c = input()
m.append(c)
q.append((n, m))
def solve(n, mat):
max_long = 0
id = -1
counter = []
for r in range(n):
tot = 0
for j in range(n):
c = (r + j) % n
if mat[j][c] == "1":
tot += 1
if tot > max_long:
max_long = tot
id = i
counter.append(tot)
counter.remove(max_long)
print(n - max_long + sum(counter))
for n, mat in q:
solve(n, mat) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | t = int(input())
for _ in range(t):
input()
n = int(input())
sum_per_diagonal = [0] * n
for i in range(n):
digits = input()
for j, digit in enumerate(digits):
sum_per_diagonal[(n + j - i) % n] += digit == "1"
print(sum(sum_per_diagonal) + n - 2 * max(sum_per_diagonal)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | def solve():
ans = 0
for s in range(n):
i = 0
j = s
diag = 0
while i < n:
if matrix[i][j] == "1":
diag += 1
i += 1
j += 1
if j == n:
j = 0
ans = max(ans, diag)
return ans
for _ in range(int(input())):
a = input()
n = int(input())
matrix = []
ones = 0
for _ in range(n):
matrix.append(input())
ones += matrix[-1].count("1")
print(ones - 2 * solve() + n) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR |
You are given a binary matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. The element located at the intersection of row $i$ and column $j$ is called $A_{ij}$. Consider a set of $4$ operations:
Cyclically shift all rows up. The row with index $i$ will be written in place of the row $i-1$ ($2 \le i \le n$), the row with index $1$ will be written in place of the row $n$.
Cyclically shift all rows down. The row with index $i$ will be written in place of the row $i+1$ ($1 \le i \le n - 1$), the row with index $n$ will be written in place of the row $1$.
Cyclically shift all columns to the left. The column with index $j$ will be written in place of the column $j-1$ ($2 \le j \le n$), the column with index $1$ will be written in place of the column $n$.
Cyclically shift all columns to the right. The column with index $j$ will be written in place of the column $j+1$ ($1 \le j \le n - 1$), the column with index $n$ will be written in place of the column $1$.
The $3 \times 3$ matrix is shown on the left before the $3$-rd operation is applied to it, on the right — after.
You can perform an arbitrary (possibly zero) number of operations on the matrix; the operations can be performed in any order.
After that, you can perform an arbitrary (possibly zero) number of new xor-operations:
Select any element $A_{ij}$ and assign it with new value $A_{ij} \oplus 1$. In other words, the value of $(A_{ij} + 1) mod 2$ will have to be written into element $A_{ij}$.
Each application of this xor-operation costs one burl. Note that the $4$ shift operations — are free. These $4$ operations can only be performed before xor-operations are performed.
Output the minimum number of burles you would have to pay to make the $A$ matrix unitary. A unitary matrix is a matrix with ones on the main diagonal and the rest of its elements are zeros (that is, $A_{ij} = 1$ if $i = j$ and $A_{ij} = 0$ otherwise).
-----Input-----
The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.
The descriptions of the test cases follow. Before each test case, an empty line is written in the input.
The first line of each test case contains a single number $n$ ($1 \le n \le 2000$)
This is followed by $n$ lines, each containing exactly $n$ characters and consisting only of zeros and ones. These lines describe the values in the elements of the matrix.
It is guaranteed that the sum of $n^2$ values over all test cases does not exceed $4 \cdot 10^6$.
-----Output-----
For each test case, output the minimum number of burles you would have to pay to make the $A$ matrix unitary. In other words, print the minimum number of xor-operations it will take after applying cyclic shifts to the matrix for the $A$ matrix to become unitary.
-----Examples-----
Input
4
3
010
011
100
5
00010
00001
10000
01000
00100
2
10
10
4
1111
1011
1111
1111
Output
1
0
2
11
-----Note-----
In the first test case, you can do the following: first, shift all the rows down cyclically, then the main diagonal of the matrix will contain only "1". Then it will be necessary to apply xor-operation to the only "1" that is not on the main diagonal.
In the second test case, you can make a unitary matrix by applying the operation $2$ — cyclic shift of rows upward twice to the matrix. | for _ in range(int(input())):
thousandminusseven = input()
n = int(input())
a = [input() for _ in range(n)]
for i in range(1, n):
a[i] = a[i][i:n] + a[i][:i]
cnt = sum(sum(c == "1" for c in t) for t in a)
bans = n**2
mxc = max(sum(a[i][j] == "1" for i in range(n)) for j in range(n))
print(cnt + n - 2 * mxc) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
ret = []
for ii in range(t):
n = int(input())
d = list(map(int, input().split()))
ans = 10**18
for i in range(3):
for j in range(3):
some3 = 0
flg = True
for k in range(n):
if d[k] == 1 and i == 0:
flg = False
break
now = d[k]
now -= i * 1 + j * 2
if now < 0:
if i >= 1 or now % 2 == 0:
continue
else:
some3 = max(1, some3)
elif now % 3 == 0:
some3 = max(some3, now // 3)
elif now % 3 == 1:
if i >= 2 or j >= 1:
some3 = max(some3, now // 3 + 1)
else:
flg = False
break
elif i >= 1:
some3 = max(some3, now // 3 + 1)
elif j >= 2:
some3 = max(some3, now // 3 + 2)
else:
flg = False
break
if flg:
ans = min(ans, i + j + some3)
ret.append(ans)
print(*ret, sep="\n") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
def get_sum_3(count):
return count[3] + min(count[2], count[1]) + max(0, count[1] - count[2]) // 3
for i in range(t):
count = [0, 0, 0, 0]
n = int(input())
a = [int(x) for x in input().split(" ")]
a.sort()
a = a[::-1]
may3 = 0
for j in range(n):
div = a[j] // 3
res = a[j] % 3
if res == 0 and may3 == 0:
may3 = div
if get_sum_3(count) < div:
count[3] += div - get_sum_3(count)
if res > 0 and count[res] == 0:
count[res] = 1
if a[0] % 3 == 0 and count[1] and count[2]:
count[3] = max(count[3] - 1, 0)
elif (
a[0] % 3 == 1
and count[1]
and count[2]
and a[-1] != 1
and (may3 == 0 or may3 <= count[3] - 1)
):
count[3] -= 1
count[1] -= 1
count[2] += 1
print(count[3] + count[2] + count[1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | def find(n, L):
if n == 1:
return int((L[0] - 1) / 3) + 1
r0 = []
r1 = []
r2 = []
for elem in L:
r = elem % 3
if r == 0:
r0.append(elem)
elif r == 1:
r1.append(elem)
else:
r2.append(elem)
x = max(L)
if x % 3 == 0:
if len(r1) == 0 and len(r2) == 0:
return int(x / 3)
else:
return int(x / 3) + 1
elif x % 3 == 2:
if len(r1) == 0:
return int(x / 3) + 1
else:
return int(x / 3) + 2
elif len(r2) == 0:
return int(x / 3) + 1
elif 1 in r1:
return int(x / 3) + 2
elif len(r0) == 0:
return int(x / 3) + 1
elif max(r0) + 1 < x:
return int(x / 3) + 1
else:
return int(x / 3) + 2
cases = int(input())
for _ in range(cases):
n = int(input())
line = input().split()
L = []
for elem in line:
L.append(int(elem))
print(find(n, L)) | FUNC_DEF IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF NUMBER VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER 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 LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | def solve():
N = int(input())
A = list(map(int, input().split()))
mA = max(A)
sA = set(a % 3 for a in A)
sA2 = set(A)
if len(sA) == 1:
if mA % 3 == 0:
print(mA // 3)
else:
print(mA // 3 + 1)
elif len(sA) == 2:
if 0 in sA and 1 in sA:
print(mA // 3 + 1)
elif 0 in sA and 2 in sA:
print(mA // 3 + 1)
else:
if mA % 3 == 1:
if not 1 in sA2:
print(mA // 3 + 1)
else:
print(mA // 3 + 2)
if mA % 3 == 2:
print(mA // 3 + 2)
elif mA % 3 == 0:
print(mA // 3 + 1)
elif mA % 3 == 1:
if not 1 in sA2 and not mA - 1 in sA2:
print(mA // 3 + 1)
else:
print(mA // 3 + 2)
else:
print(mA // 3 + 2)
T = int(input())
for i in range(T):
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER IF NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | import sys
t = int(sys.stdin.readline())
for _ in range(t):
n = int(sys.stdin.readline())
st = set(map(int, sys.stdin.readline().split()))
mx = max(st)
if mx == 1:
print(1)
continue
arr = set(x % 3 for x in st)
if mx % 3 == 0:
print(mx // 3 + int(1 in arr or 2 in arr))
elif mx % 3 == 1:
cnt = mx // 3
add = 0
if 1 in st or mx - 1 in st:
add += 1
if 2 in arr:
add += 1
cnt += max(add, 1)
print(cnt)
else:
cnt = mx // 3 + 1
if 1 in arr:
cnt += 1
print(cnt) | 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | from sys import stdin
input = stdin.readline
def check(x, y, z):
for i in range(n):
if 3 * x + 2 * y + z < a[i]:
return False
take = a[i] // 3
yes = False
for req in range(max(0, take - 2), min(x + 1, take + 1)):
for j in range(y + 1):
for k in range(z + 1):
if 3 * req + j * 2 + k == a[i]:
yes = True
break
if not yes:
return False
return True
def answer():
m = 0
for i in range(n):
m = max(m, a[i] // 3)
ans = m + 2
for x in range(max(0, m - 3), m + 1):
for y in range(3):
for z in range(3):
if check(x, y, z):
ans = min(ans, x + y + z)
return ans
for T in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
print(answer()) | ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR 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 IF BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
for i in range(t):
n = int(input())
lst = list(map(int, input().split()))
m = max(lst)
c1 = 0
c2 = 0
for j in lst:
if j % 3 == 1:
c1 += 1
elif j % 3 == 2:
c2 += 1
if m % 3 == 0:
if c1 == 0 and c2 == 0:
print(m // 3)
else:
print(m // 3 + 1)
elif m % 3 == 1:
if m == 1:
print(1)
else:
if 1 in lst or m - 1 in lst:
ans1 = (m - 4) // 3 + 3
else:
ans1 = (m - 4) // 3 + 2
if c2 > 0:
ans2 = (m - 1) // 3 + 2
else:
ans2 = (m - 1) // 3 + 1
print(min(ans1, ans2))
elif c1 > 0:
print(m // 3 + 2)
else:
print(m // 3 + 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | import sys
tokens = "".join(sys.stdin.readlines()).split()[::-1]
def next():
return tokens.pop()
def nextInt():
return int(next())
def nextFloat():
return float(next())
def getIntArray(n):
return [nextInt() for _ in range(n)]
def getFloatArray(n):
return [nextFloat() for _ in range(n)]
def getStringArray(n):
return [next() for _ in range(n)]
def isPossible(s, ones, twos, threes):
if s == 0:
return True
elif ones * 1 + twos * 2 + threes * 3 < s:
return False
elif s <= 15:
return recurse(s, 0, [ones, twos, min(threes, 5)])
req = (s - 10) // 3
if threes < req:
return False
threes -= req
s -= req * 3
return isPossible(s, ones, twos, threes)
def recurse(s, idx, counts):
if s == 0:
return True
elif idx == len(counts):
return False
for i in range(counts[idx] + 1):
counts[idx] -= i
if recurse(s - i * (idx + 1), idx + 1, counts):
return True
counts[idx] += i
return False
testcase = True
def solve(testcase=1):
N = nextInt()
A = getIntArray(N)
threes = max(i // 3 for i in A)
ans = 999999999999999999999999999999999999999999999999999999
for dth in range(4):
for dtw in range(4):
for do in range(4):
if all(isPossible(ele, do, dtw, threes - dth) for ele in A):
ans = min(ans, do + dtw + threes - dth)
print(ans)
if testcase is None:
testcaseCount = 1
while tokens:
solve(testcaseCount)
testcaseCount += 1
else:
testcaseCount = nextInt() if testcase else 1
for tc in range(testcaseCount):
solve(tc + 1)
assert not tokens | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL STRING FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR 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 VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER LIST VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN NUMBER VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | def solve():
N = int(input())
a = list(map(int, input().split()))
r = [0, 0, 0]
M = max(a)
for i in range(N):
r[a[i] % 3] |= 1
if M % 3 == 0:
if r[1] | r[2] == 1:
print(M // 3 + 1)
else:
print(M // 3)
elif M % 3 == 1:
if r[2] == 0 or M == 1:
print(M // 3 + 1)
else:
ok = True
for i in range(N):
if a[i] % 3 == 0 and a[i] // 3 <= M // 3 - 1:
continue
if not (a[i] >= 2 and (a[i] - 2) % 3 == 0) and not (
a[i] >= 4 and (a[i] - 4) % 3 == 0
):
ok = False
if ok:
print(M // 3 + 1)
else:
print(M // 3 + 2)
elif r[1] == 1:
print(M // 3 + 2)
else:
print(M // 3 + 1)
T = int(input())
while T > 0:
T -= 1
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
for q in range(t):
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
suslis = [(i % 3) for i in lis]
maxi = max(lis)
if maxi % 3 == 0:
if suslis == [(0) for i in lis]:
print(maxi // 3)
else:
print(maxi // 3 + 1)
elif maxi % 3 == 1:
if 2 in suslis and (maxi - 1 in lis or 1 in lis):
print(maxi // 3 + 2)
else:
print(maxi // 3 + 1)
elif 1 in suslis:
print(maxi // 3 + 2)
else:
print(maxi // 3 + 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
for c in range(t):
n = int(input())
a = sorted(list(set(map(int, input().split()))))
m = a[-1]
k = max([(x // 3) for x in a])
mod3s = sorted(list(set([(x % 3) for x in a])))
if mod3s == [0]:
ans = k
elif mod3s == [1]:
ans = k + 1
elif mod3s == [2]:
ans = k + 1
elif mod3s == [0, 1]:
ans = k + 1
elif mod3s == [0, 2]:
ans = k + 1
elif mod3s == [1, 2] or mod3s == [0, 1, 2]:
if m % 3 == 0:
ans = k + 1
elif m % 3 == 1:
if a[-2] == m - 1 or a[0] == 1:
ans = k + 2
else:
ans = k + 1
else:
ans = k + 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR LIST NUMBER ASSIGN VAR VAR IF VAR LIST NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER NUMBER VAR LIST NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | import sys
inpu = sys.stdin.readline
prin = sys.stdout.write
I = lambda: [*map(int, inpu().split())]
t = I()[0]
for _ in range(t):
(n,) = I()
a = I()
m = max(a)
x = m % 3
if x == 0:
bad = False
for guy in a:
if guy % 3 != 0:
bad = True
break
if bad:
print(m // 3 + 1)
else:
print(m // 3)
elif x == 1:
two = False
one = False
for guy in a:
if guy % 3 == 2:
two = True
elif guy == 1 or guy == m - 1:
one = True
if two and one:
print(m // 3 + 2)
else:
print(m // 3 + 1)
else:
one = False
for guy in a:
if guy % 3 == 1:
one = True
break
if one:
print(m // 3 + 2)
else:
print(m // 3 + 1) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = [0, 0, 0, 0]
sum = 0
ma = 0
for x in a:
ma = max(ma, x)
if x == 1:
b[3] = 1
b[x % 3] = 1
sum = max(sum, x // 3)
if (b[1] == 1) & (b[2] == 1):
bb = 0
for x in a:
if x == ma - 1:
bb = 1
if (ma % 3 < 2) & (b[3] == 0) & (bb == 0):
sum += 1
elif ma % 3 == 0:
sum += 1
else:
sum += b[1] + b[2]
else:
sum += b[1] + b[2]
print(sum) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
while t > 0:
t = t - 1
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0, 0, 0]
for i in range(n):
b[a[i] % 3] += 1
if a[n - 1] % 3 == 0:
if b[1] == 0 and b[2] == 0:
print(a[n - 1] // 3)
else:
print(a[n - 1] // 3 + 1)
elif a[n - 1] % 3 == 1:
if b[2] == 0 or a.count(1) == 0 and a.count(a[n - 1] - 1) == 0:
print(a[n - 1] // 3 + 1)
else:
print(a[n - 1] // 3 + 2)
elif b[1] == 0:
print(a[n - 1] // 3 + 1)
else:
print(a[n - 1] // 3 + 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l6 = all([(x < 6) for x in l])
b = 2000000000.0
for i in range(7):
for j in range(4):
for k in range(3):
ok = [
True,
i > 0,
i >= 2 or j >= 1,
k >= 1 or i >= 1 and j >= 1 or i >= 3,
k >= 1 and i >= 1 or j >= 2 or j >= 1 and i >= 2 or i >= 4,
k >= 1
and i >= 2
or k >= 1
and j >= 1
or j >= 2
and i >= 1
or j >= 1
and i >= 3
or i >= 5,
i + 2 * j + 3 * k == 6,
]
if i + 2 * j + 3 * k > 6:
continue
s = i + j + k
if l6:
if any([(not ok[x]) for x in l]):
continue
b = min(b, s)
else:
no = False
m = 0
for x in l:
yes = False
for I in range(min(6, x), -1, -1):
if ok[I] and (x - I) % 3 == 0:
yes = True
m = max(m, (x - I) // 3)
break
if not yes:
no = True
break
if no:
continue
b = min(b, s + m)
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
ans = []
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
k1 = 0
k2 = 0
for elem in a:
if elem % 3 == 1:
k1 = 1
elif elem % 3 == 2:
k2 = 1
if m % 3 == 0:
if k1 or k2:
ans.append(m // 3 + 1)
else:
ans.append(m // 3)
elif k1 and k2:
if m % 3 == 1 and 1 not in a and m - 1 not in a:
ans.append(m // 3 + 1)
else:
ans.append(m // 3 + 2)
else:
ans.append(m // 3 + 1)
for elem in ans:
print(elem) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
for case in range(t):
n = int(input())
stuff = [int(x) for x in input().split(" ")]
needs1 = 0
needs2 = 0
all3 = True
mini = float("inf")
maxi = 0
anothercondition = 0
has3 = False
for x in stuff:
if x % 3 == 1:
needs1 = 1
all3 = False
elif x % 3 == 2:
needs2 = 1
all3 = False
if x > maxi:
anothercondition = maxi
maxi = x
elif anothercondition < x < maxi:
anothercondition = x
if x < mini:
mini = x
if x == 3:
has3 = True
if all3:
print(maxi // 3)
elif maxi % 3 == 0:
print(maxi // 3 + 1)
elif mini == 1:
print(maxi // 3 + needs1 + needs2)
elif maxi % 3 == 1:
if maxi - anothercondition == 1:
print(maxi // 3 + needs1 + needs2)
else:
print(maxi // 3 + 1)
else:
print(maxi // 3 + needs1 + needs2) | 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 FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
mods = [0, 0, 0]
for i in arr:
mods[i % 3] += 1
m = max(arr)
if m % 3 == 0:
if mods[1] == 0 and mods[2] == 0:
print(m // 3)
else:
print(m // 3 + 1)
if m % 3 == 1:
if m == 1:
print(1)
elif 1 in arr:
if mods[2] == 0:
print(m // 3 + 1)
else:
print(m // 3 + 2)
elif m - 1 in arr:
if mods[2] == 0:
print(m // 3 + 1)
else:
print(m // 3 + 2)
else:
print(m // 3 + 1)
if m % 3 == 2:
if mods[1] == 0:
print(m // 3 + 1)
else:
print(m // 3 + 2) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
for _ in range(t):
n = int(input())
m = list(map(int, input().split()))
m.sort()
m1 = 0
m2 = 0
m3 = 0
m1m = 0
m2m = 0
for i in m:
m3 = i // 3
if i == 1:
m1m = 1
if i == 2:
m2m = 1
if i % 3 == 1:
m1 = 1
if i % 3 == 2:
m2 = 1
if m[-1] % 3 == 0 and m1 == 1 and m2 == 1:
m3 -= 1
elif m[-1] % 3 == 1 and m1m == 0 and m2 == 1 and m1 == 1:
m3 -= 1
i = n - 2
while 2 > m[i + 1] - m[i] >= 0:
if m[i + 1] - m[i] == 1:
m3 += 1
break
elif m[i + 1] - m[i] == 0:
i -= 1
if i == -1:
break
print(m1 + m2 + m3) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | from sys import maxsize
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
ok1, ok2, ok3, ok4, ok5 = 0, 0, 0, 0, 0
v = maxsize
for i in range(n):
if l[i] % 3 != 0:
ok1 = v
break
ok1 = max(ok1, l[i] // 3)
for i in range(n):
if l[i] % 3 == 2:
ok2 = v
break
ok2 = max(ok2, l[i] // 3)
for i in range(n):
if l[i] % 3 == 1:
ok3 = v
break
ok3 = max(ok3, l[i] // 3)
for i in range(n):
if l[i] % 3 == 0:
ok4 = max(ok4, l[i] // 3 - 1)
else:
ok4 = max(ok4, l[i] // 3)
for i in range(n):
if l[i] == 1:
ok5 = v
break
if l[i] % 3 == 1:
ok5 = max(ok5, (l[i] - 4) // 3)
else:
ok5 = max(ok5, l[i] // 3)
ok2 += 1
ok3 += 1
ok5 += 2
ok4 += 2
print(min(ok1, ok2, ok3, ok4, ok5)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | ans = []
for p in range(int(input())):
cnt = 0
price = []
u = int(input())
mas = input().split()
for i in range(u):
mas[i] = int(mas[i])
ost1 = 0
ost2 = 0
for i in mas:
if i % 3 == 1:
ost1 = 1
if ost2 == 1:
break
if i % 3 == 2:
ost2 = 1
if ost1 == 1:
break
if 1 in mas:
if max(mas) == 2:
cnt = 2
else:
cnt = max(mas) // 3 + ost1 + ost2
if max(mas) % 3 == 0 and ost2 == 1:
cnt -= 1
elif max(mas) == 2:
cnt = 1
elif max(mas) == 4:
cnt = 2
if 3 in mas and 2 in mas:
cnt += 1
else:
cnt = max(mas) // 3 + ost1 + ost2
if (
ost1 + ost2 == 2
and max(mas) % 3 == 1
and not max(mas) - 1 in mas
or ost1 + ost2 == 2
and max(mas) % 3 == 0
):
cnt -= 1
ans.append(cnt)
for i in ans:
print(i) | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | import sys
t = int(sys.stdin.readline())
while t:
t -= 1
n = int(input())
dat = list(set(list(map(int, sys.stdin.readline().split()))))
dat.sort()
res = []
for i in range(len(dat)):
res.append(dat[i] % 3)
ost = dat[-1] % 3
ans = dat[-1] // 3
if ost == 0:
if 1 in res or 2 in res:
ans += 1
print(ans)
elif ost == 1:
ans += 1
if 2 in res and (dat[-1] - 1 in dat or 1 in dat):
ans += 1
print(ans)
else:
ans += 1
if 1 in res:
ans += 1
print(ans) | IMPORT 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
mc = max(l)
if mc == 1:
ans = 1
else:
hasone = 1 in l
extras = set(num % 3 for num in l if num != mc)
extras.discard(0)
q, r = divmod(mc, 3)
closecall = any(mc > num >= 3 * q for num in l)
if len(extras) == 0:
ans = q + (not not r)
elif len(extras) == 1:
if r in extras:
ans = q + 1
elif r == 1:
if closecall:
ans = q + 2
else:
ans = q + 1
elif r == 2:
ans = q + 2
else:
ans = q + 1
elif r == 2:
ans = q + 2
elif r == 1:
if hasone:
ans = q + 2
elif closecall:
ans = q + 2
else:
ans = q + 1
else:
ans = q + 1
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | def solver():
n = int(input())
for _ in range(n):
n_flavors = int(input())
cost_flavors = list(reversed(sorted(list(map(int, input().split())))))
final = {}
checker = True
for i in cost_flavors:
if checker:
final[3] = final.get(3, 0) + i // 3
checker = False
if i % 3 == 2:
final[2] = 1
elif i % 3 == 1:
final[1] = 1
if final.get(3, 0) != 0 and final.get(1, 5) != 5 and final.get(2, 5) != 5:
if cost_flavors[0] % 3 == 0:
final[3] = final[3] - 1
if cost_flavors[0] % 3 == 1 and cost_flavors[0] - 1 not in cost_flavors:
final[3] = final[3] - 1
final[2] = 2
final[1] = 0
if 1 in cost_flavors:
final[1] = 1
print(final.get(3, 0) + final.get(2, 0) + final.get(1, 0))
solver() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | import sys
def exact_change(n, a):
a.sort()
_1 = 0
_2 = 0
for ai in a:
r = ai % 3
if r == 1:
_1 = 1
elif r == 2:
_2 = 1
r = a[-1] % 3
if r == 0:
if _1 == 1 or _2 == 1:
return a[-1] // 3 + 1
return a[-1] // 3
if r == 2:
if _1 == 0:
return a[-1] // 3 + 1
return a[-1] // 3 + 2
if r == 1:
if _2 == 0:
return a[-1] // 3 + 1
if a[0] == 1:
return a[-1] // 3 + 2
j = 2
while j < n:
if a[-1] - a[-j] == 1:
return a[-1] // 3 + 2
if a[-1] - a[-j] > 1:
break
j += 1
return a[-1] // 3 + 1
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
sys.stdout.write(f"{exact_change(n, a)}\n") | IMPORT FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER RETURN BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | def mincoin(arr):
zero = 0
num3 = max(arr) // 3 - 1
mid = num3 * 3 + 3
lower = [0, 0, 0]
upper = [0, 0]
for i in arr:
if i < mid:
lower[i % 3] = 1
elif i == mid:
zero = 1
else:
upper[i % 3 - 1] = 1
lower[0] = zero
if sum(upper) == 2:
return num3 + 3
elif sum(upper) == 0:
return min(2, sum(lower)) + num3
elif upper[0] == 1:
if num3 < 0:
return sum(upper)
elif min(arr) == 1:
return num3 + 2 + lower[2]
else:
return num3 + 2 + (lower[0] and lower[2] == 1)
elif lower[1] == 1:
return num3 + 3
else:
return num3 + 2
r = int(input())
res = []
for i in range(r):
input()
arr = list(map(int, input().split()))
res.append(mincoin(arr))
for i in res:
print(i) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | for _ in range(int(input())):
n = int(input())
nums = list(map(int, input().split()))
nums.sort()
max_num = nums[-1]
remainder_1, remainder_2 = False, False
for num in nums:
if num % 3 == 1:
remainder_1 = True
if num % 3 == 2:
remainder_2 = True
if max_num % 3 == 0:
res = max_num // 3
if remainder_1 or remainder_2:
res += 1
print(res)
elif max_num % 3 == 1:
res = max_num // 3 + 1
just_below = True if max_num - 1 in nums else False
if remainder_2 and just_below or remainder_2 and 1 in nums:
res += 1
print(res)
elif max_num % 3 == 2:
res = max_num // 3 + 1
if remainder_1:
res += 1
print(res) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | def possible2(ai, c1, c2, c3):
for cc1 in range(c1 + 1):
for cc2 in range(c2 + 1):
if cc1 + 2 * cc2 > ai:
continue
if (ai - cc1 - 2 * cc2) % 3 == 0 and (ai - cc1 - 2 * cc2) // 3 <= c3:
return True
return False
def possible(a, c1, c2, c3):
for ai in a:
if not possible2(ai, c1, c2, c3):
return False
return True
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
result = 10 * (m // 3 + 100)
for c1 in [0, 1, 2]:
for c2 in [0, 1, 2]:
c3 = max((m - c1 - 2 * c2 + 2) // 3, 0)
if possible(a, c1, c2, c3) == True:
result = min(result, c1 + c2 + c3)
print(result) | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR LIST NUMBER NUMBER NUMBER FOR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | import sys
def ec(n, l1):
ans1 = 0
ans2 = 0
ans3 = 0
i = 0
while i < len(l1):
if l1[i] % 3 != 0:
ans1 = sys.maxsize
break
i = i + 1
if i == len(l1):
ans1 = max(l1) // 3
i = 0
while i < len(l1):
if l1[i] % 3 == 2:
ans2 = sys.maxsize
break
i = i + 1
if i == len(l1):
ans2 = max(l1) // 3 + 1
i = 0
while i < len(l1):
if l1[i] % 3 == 1:
ans3 = sys.maxsize
break
i = i + 1
if i == len(l1):
ans3 = max(l1) // 3 + 1
i = 0
ans4 = 0
while i < len(l1):
if l1[i] % 3 == 1:
ans4 = max(ans4, l1[i] // 3)
elif l1[i] % 3 == 2:
ans4 = max(ans4, l1[i] // 3)
else:
ans4 = max(ans4, l1[i] // 3 - 1)
i = i + 1
ans4 = ans4 + 2
i = 0
ans5 = 0
while i < len(l1):
if l1[i] == 1:
ans5 = sys.maxsize
break
elif l1[i] % 3 == 1:
ans5 = max(ans5, l1[i] // 3 - 1)
else:
ans5 = max(ans5, l1[i] // 3)
i = i + 1
ans5 = ans5 + 2
return min(ans1, ans2, ans3, ans4, ans5)
t = int(input())
l = []
for x in range(t):
n = int(input())
s = str(input())
l.append([s, n])
la = []
for x in l:
lt = x[0].split(" ")
l1 = []
for y in lt:
l1.append(int(y))
n = x[1]
assert n == len(l1)
ans = ec(n, l1)
la.append(ans)
for x in la:
print(x) | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | import sys
input = lambda: sys.stdin.readline().rstrip()
INF = 10**19
def solve():
n = int(input())
a = list(map(int, input().split()))
ans = INF
cnt = 0
for i in range(n):
if a[i] % 3 != 0:
cnt = INF
break
cnt = max(cnt, a[i] // 3)
ans = min(cnt, ans)
cnt = 0
for i in range(n):
if a[i] % 3 == 2:
cnt = INF
break
cnt = max(cnt, a[i] // 3)
ans = min(cnt + 1, ans)
cnt = 0
for i in range(n):
cnt = max(cnt, a[i] // 3)
ans = min(cnt + 2, ans)
cnt = 0
for i in range(n):
if a[i] % 3 == 1:
cnt = INF
break
cnt = max(cnt, a[i] // 3)
ans = min(cnt + 1, ans)
cnt = 0
for i in range(n):
if a[i] == 1:
cnt = INF
break
elif a[i] % 3 == 1:
cnt = max(cnt, a[i] // 3 - 1)
else:
cnt = max(cnt, a[i] // 3)
ans = min(cnt + 2, ans)
cnt = 0
for i in range(n):
if a[i] % 3 == 0:
cnt = max(cnt, a[i] // 3 - 1)
else:
cnt = max(cnt, a[i] // 3)
ans = min(cnt + 2, ans)
print(ans)
t = int(input())
for _ in range(t):
solve() | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | import sys
input = sys.stdin.readline
test = int(input())
for i in range(test):
count = int(input())
price = list(map(int, input().split()))
max_ = 0
mod = [False, False, False]
for i in range(count):
if price[i] > max_:
max_ = price[i]
mod[price[i] % 3] = True
if mod == [True, False, False]:
print(max_ // 3)
elif mod == [False, True, False] or mod == [False, False, True]:
print(max_ // 3 + 1)
elif mod == [True, True, True]:
if max_ % 3 == 0:
print(max_ // 3 + 1)
elif max_ % 3 == 1:
if 1 in price or max_ - 1 in price:
print(max_ // 3 + 2)
else:
print(max_ // 3 + 1)
else:
print(max_ // 3 + 2)
elif mod == [True, True, False] or mod == [True, False, True]:
print(max_ // 3 + 1)
elif max_ % 3 == 1:
if 1 in price:
print(max_ // 3 + 2)
else:
print(max_ // 3 + 1)
else:
print(max_ // 3 + 2) | IMPORT ASSIGN VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR LIST NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR LIST NUMBER NUMBER NUMBER VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
x = max(a)
r = []
for i in range(n):
r.append(a[i] % 3)
rx = x % 3
ans = x // 3
if rx == 0:
if 1 in r or 2 in r:
ans += 1
if rx == 1:
ans += 1
if 2 in r and (x - 1 in a or 1 in a):
ans += 1
if rx == 2:
ans += 1
if 1 in r:
ans += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | def p(v, x, y, z):
for i in range(x + 1):
for j in range(y + 1):
if i + 2 * j > v:
continue
if (v - i - 2 * j) % 3 != 0:
continue
if (v - i - 2 * j) / 3 <= z:
return True
return False
def possible(a, x, y, z):
for v in a:
if not p(v, x, y, z):
return False
return True
def solve():
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
ans = 1000000000.0
m = max(arr)
for i in range(3):
for j in range(3):
k = max(0, (m - i - 2 * j + 2) / 3)
assert i + 2 * j + 3 * k >= m
if possible(arr, i, j, k):
ans = min(ans, i + j + k)
print(int(ans))
solve() | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
One day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of $n$ different flavors. A bag of the $i$-th flavor costs $a_i$ burles.
The store may run out of some flavors, so you'll decide which one to buy after arriving there. But there are two major flaws in this plan:
you have only coins of $1$, $2$ and $3$ burles;
since it's morning, the store will ask you to pay in exact change, i. e. if you choose the $i$-th flavor, you'll have to pay exactly $a_i$ burles.
Coins are heavy, so you'd like to take the least possible number of coins in total. That's why you are wondering: what is the minimum total number of coins you should take with you, so you can buy a bag of chips of any flavor in exact change?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains the single integer $n$ ($1 \le n \le 100$) — the number of flavors in the store.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the cost of one bag of each flavor.
-----Output-----
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll choose in exact change.
-----Examples-----
Input
4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
Output
446
4
3
260
-----Note-----
In the first test case, you should, for example, take with you $445$ coins of value $3$ and $1$ coin of value $2$. So, $1337 = 445 \cdot 3 + 1 \cdot 2$.
In the second test case, you should, for example, take $2$ coins of value $3$ and $2$ coins of value $2$. So you can pay either exactly $8 = 2 \cdot 3 + 1 \cdot 2$ or $10 = 2 \cdot 3 + 2 \cdot 2$.
In the third test case, it's enough to take $1$ coin of value $3$ and $2$ coins of value $1$. | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
arr = list(set(arr))
a = []
zeroes, ones, twos = 0, 0, 0
for i in arr:
a.append(i // 3)
if i % 3 == 1:
ones += 1
elif i % 3 == 2:
twos += 1
else:
zeroes += 1
ans = max(a)
x = max(arr)
if x % 3 == 0:
if ones or twos:
ans += 1
elif x % 3 == 1:
ans += 1
if 3 * (ans - 1) in arr:
if twos:
ans += 1
elif 1 in arr:
if twos:
ans += 1
else:
ans += 1
if ones:
ans += 1
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER IF NUMBER VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.