description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h_1 and height of Abol is h_2. Each second, Mike waters Abol and Xaniar.
[Image]
So, if height of Xaniar is h_1 and height of Abol is h_2, after one second height of Xaniar will become $(x_{1} h_{1} + y_{1}) \operatorname{mod} m$ and height of Abol will become $(x_{2} h_{2} + y_{2}) \operatorname{mod} m$ where x_1, y_1, x_2 and y_2 are some integer numbers and $a \operatorname{mod} b$ denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a_1 and height of Abol is a_2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
-----Input-----
The first line of input contains integer m (2 β€ m β€ 10^6).
The second line of input contains integers h_1 and a_1 (0 β€ h_1, a_1 < m).
The third line of input contains integers x_1 and y_1 (0 β€ x_1, y_1 < m).
The fourth line of input contains integers h_2 and a_2 (0 β€ h_2, a_2 < m).
The fifth line of input contains integers x_2 and y_2 (0 β€ x_2, y_2 < m).
It is guaranteed that h_1 β a_1 and h_2 β a_2.
-----Output-----
Print the minimum number of seconds until Xaniar reaches height a_1 and Abol reaches height a_2 or print -1 otherwise.
-----Examples-----
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
-----Note-----
In the first sample, heights sequences are following:
Xaniar: $4 \rightarrow 0 \rightarrow 1 \rightarrow 2$
Abol: $0 \rightarrow 3 \rightarrow 4 \rightarrow 1$ | def main():
m, tt = int(input()), [0] * 4
for i in (0, 2):
h, a = map(int, input().split())
x, y = map(int, input().split())
ha = h, a
for t in range(1, m * 2):
h = (h * x + y) % m
if h in ha:
if h == ha[0]:
if tt[i]:
tt[i] = t - tt[i]
break
else:
tt[i] = t
elif tt[i + 1]:
tt[i] = t - tt[i + 1]
break
else:
tt[i + 1] = t
step1, shift1, step2, shift2 = tt if tt[0] > tt[2] else tt[2:] + tt[:2]
if shift1 == shift2 != 0:
print(shift1)
return
if (
step1
and not step2
and shift1
and shift1 <= shift2
and not (shift2 - shift1) % step1
):
print(shift2)
return
if all(tt):
if step2 == 1:
print(shift1 if shift1 >= shift2 else shift2 + (shift2 - shift1) % step1)
return
for t in range(shift1 - shift2, shift1 - shift2 + step1 * step2, step1):
if not t % step2:
print(t + shift2)
return
print(-1)
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER FOR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h_1 and height of Abol is h_2. Each second, Mike waters Abol and Xaniar.
[Image]
So, if height of Xaniar is h_1 and height of Abol is h_2, after one second height of Xaniar will become $(x_{1} h_{1} + y_{1}) \operatorname{mod} m$ and height of Abol will become $(x_{2} h_{2} + y_{2}) \operatorname{mod} m$ where x_1, y_1, x_2 and y_2 are some integer numbers and $a \operatorname{mod} b$ denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a_1 and height of Abol is a_2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
-----Input-----
The first line of input contains integer m (2 β€ m β€ 10^6).
The second line of input contains integers h_1 and a_1 (0 β€ h_1, a_1 < m).
The third line of input contains integers x_1 and y_1 (0 β€ x_1, y_1 < m).
The fourth line of input contains integers h_2 and a_2 (0 β€ h_2, a_2 < m).
The fifth line of input contains integers x_2 and y_2 (0 β€ x_2, y_2 < m).
It is guaranteed that h_1 β a_1 and h_2 β a_2.
-----Output-----
Print the minimum number of seconds until Xaniar reaches height a_1 and Abol reaches height a_2 or print -1 otherwise.
-----Examples-----
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
-----Note-----
In the first sample, heights sequences are following:
Xaniar: $4 \rightarrow 0 \rightarrow 1 \rightarrow 2$
Abol: $0 \rightarrow 3 \rightarrow 4 \rightarrow 1$ | import sys
__author__ = "kitkat"
def GetNext(h, x, y):
nonlocal m
return (x * h + y) % m
try:
while True:
m = int(input())
h1, a1 = list(map(int, input().split(" ")))
x1, y1 = list(map(int, input().split(" ")))
h2, a2 = list(map(int, input().split(" ")))
x2, y2 = list(map(int, input().split(" ")))
t1 = []
t2 = []
T = 0
for i in range(2 * m + 1):
if h1 == a1:
t1.append(T)
if h2 == a2:
t2.append(T)
T += 1
h1 = GetNext(h1, x1, y1)
h2 = GetNext(h2, x2, y2)
if len(t1) == 0 or len(t2) == 0:
print("-1")
continue
if t1[0] == t2[0]:
print(t1[0])
continue
elif len(t1) < 2 or len(t2) < 2:
if len(t1) == 1 and len(t2) == 1:
print(t1[0] if t1[0] == t2[0] else "-1")
elif len(t1) == 1:
if t1[0] in t2:
print(t1[0])
else:
print("-1")
elif len(t2) == 1:
if t2[0] in t1:
print(t2[0])
else:
print("-1")
continue
res1 = t1[0]
res2 = t2[0]
flag = False
for i in range(5000000):
if res1 == res2:
flag = True
print(res1)
break
elif res1 <= res2:
res1 += t1[1] - t1[0]
else:
res2 += t2[1] - t2[0]
if not flag:
print("-1")
except EOFError:
pass | IMPORT ASSIGN VAR STRING FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING VAR |
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h_1 and height of Abol is h_2. Each second, Mike waters Abol and Xaniar.
[Image]
So, if height of Xaniar is h_1 and height of Abol is h_2, after one second height of Xaniar will become $(x_{1} h_{1} + y_{1}) \operatorname{mod} m$ and height of Abol will become $(x_{2} h_{2} + y_{2}) \operatorname{mod} m$ where x_1, y_1, x_2 and y_2 are some integer numbers and $a \operatorname{mod} b$ denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a_1 and height of Abol is a_2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
-----Input-----
The first line of input contains integer m (2 β€ m β€ 10^6).
The second line of input contains integers h_1 and a_1 (0 β€ h_1, a_1 < m).
The third line of input contains integers x_1 and y_1 (0 β€ x_1, y_1 < m).
The fourth line of input contains integers h_2 and a_2 (0 β€ h_2, a_2 < m).
The fifth line of input contains integers x_2 and y_2 (0 β€ x_2, y_2 < m).
It is guaranteed that h_1 β a_1 and h_2 β a_2.
-----Output-----
Print the minimum number of seconds until Xaniar reaches height a_1 and Abol reaches height a_2 or print -1 otherwise.
-----Examples-----
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
-----Note-----
In the first sample, heights sequences are following:
Xaniar: $4 \rightarrow 0 \rightarrow 1 \rightarrow 2$
Abol: $0 \rightarrow 3 \rightarrow 4 \rightarrow 1$ | f = lambda: map(int, input().split())
m = int(input())
def g():
h, a = f()
x, y = f()
t = lambda: (h * x + y) % m
s, d = 0, 1
while h != a:
h = t()
s += 1
if s > m:
print(-1)
exit()
h = t()
while h != a:
h = t()
d += 1
if d > m:
return s, 0
return s, d
def h():
u, x = g()
v, y = g()
k = 0
while u != v:
if u < v:
u += x
else:
v += y
k += 1
if k > 2 * m:
return -1
return u
print(h()) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h_1 and height of Abol is h_2. Each second, Mike waters Abol and Xaniar.
[Image]
So, if height of Xaniar is h_1 and height of Abol is h_2, after one second height of Xaniar will become $(x_{1} h_{1} + y_{1}) \operatorname{mod} m$ and height of Abol will become $(x_{2} h_{2} + y_{2}) \operatorname{mod} m$ where x_1, y_1, x_2 and y_2 are some integer numbers and $a \operatorname{mod} b$ denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a_1 and height of Abol is a_2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
-----Input-----
The first line of input contains integer m (2 β€ m β€ 10^6).
The second line of input contains integers h_1 and a_1 (0 β€ h_1, a_1 < m).
The third line of input contains integers x_1 and y_1 (0 β€ x_1, y_1 < m).
The fourth line of input contains integers h_2 and a_2 (0 β€ h_2, a_2 < m).
The fifth line of input contains integers x_2 and y_2 (0 β€ x_2, y_2 < m).
It is guaranteed that h_1 β a_1 and h_2 β a_2.
-----Output-----
Print the minimum number of seconds until Xaniar reaches height a_1 and Abol reaches height a_2 or print -1 otherwise.
-----Examples-----
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
-----Note-----
In the first sample, heights sequences are following:
Xaniar: $4 \rightarrow 0 \rightarrow 1 \rightarrow 2$
Abol: $0 \rightarrow 3 \rightarrow 4 \rightarrow 1$ | mod = int(input())
h1, a1 = map(int, input().split())
x1, y1 = map(int, input().split())
h2, a2 = map(int, input().split())
x2, y2 = map(int, input().split())
q1 = 0
while h1 != a1:
h1 = (h1 * x1 + y1) % mod
q1 += 1
if q1 > 2 * mod:
print(-1)
return
q2 = 0
t2 = h2
while t2 != a2:
t2 = (t2 * x2 + y2) % mod
q2 += 1
if q2 > 2 * mod:
print(-1)
return
if q1 == q2:
print(q1)
return
c1 = 1
h1 = (a1 * x1 + y1) % mod
while h1 != a1:
h1 = (h1 * x1 + y1) % mod
c1 += 1
if c1 > 2 * mod:
print(-1)
return
c2 = 0
nx2 = 1
ny2 = 0
for i in range(c1):
nx2 = nx2 * x2 % mod
ny2 = (ny2 * x2 + y2) % mod
for i in range(q1):
h2 = (h2 * x2 + y2) % mod
while h2 != a2:
h2 = (h2 * nx2 + ny2) % mod
c2 += 1
if c2 > 2 * mod:
print(-1)
return
print(q1 + c1 * c2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(n):
if a[i] not in d:
d[a[i]] = []
d[a[i]].append(b[i])
res = 0
v = []
for i in d.keys():
if len(d[i]) > 1:
v.append(i)
res += sum(d[i])
for i in d.keys():
if len(d[i]) == 1:
for j in v:
if i & j == i:
v.append(i)
res += d[i][0]
break
print(res) | 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | n = int(input())
ta = list(map(int, input().split()))
a = []
tb = list(map(int, input().split()))
cnt = {}
for i in range(n):
if ta[i] not in cnt:
cnt[ta[i]] = 1
else:
cnt[ta[i]] += 1
s1 = []
for i in range(n):
if cnt[ta[i]] > 1:
s1.append(ta[i])
def bin(num):
s = set()
for j in range(61, -1, -1):
bit = num >> j
if bit > 0:
if bit & 1:
s.add(j)
return s
ans = 0
for i in range(n):
for j in s1:
if j | ta[i] == j:
ans += tb[i]
break
print(ans) | 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | n = int(input())
a = [0] * n
b = [0] * n
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
for i in range(n):
a[i] = [a[i], b[i]]
a.sort(reverse=True, key=lambda x: x[0])
same = []
comp = a[0][0]
count = 1
score = a[0][1]
for i in range(1, n):
if comp == a[i][0] and i == n - 1:
count += 1
score += a[i][1]
same.append([comp, score, i])
elif comp == a[i][0]:
count += 1
score += a[i][1]
elif count > 1:
same.append([comp, score, i - 1])
comp = a[i][0]
score = a[i][1]
count = 1
else:
comp = a[i][0]
score = a[i][1]
count = 1
relevant = []
if len(same) == 0:
print(0)
else:
f = same[0][0]
fscore = same[0][1]
findex = same[0][2]
for i in range(1, len(same)):
if f & same[i][0] != same[i][0]:
relevant.append(same[i][0])
for i in range(findex + 1, n):
if f & a[i][0] == a[i][0]:
fscore += a[i][1]
else:
for j in relevant:
if a[i][0] & j == a[i][0]:
fscore += a[i][1]
break
print(fscore) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | n = int(input())
lst1 = list(map(int, input().split()))[:n]
lst2 = list(map(int, input().split()))[:n]
dict = {}
for a in lst1:
if a in dict:
dict[a] += 1
else:
dict[a] = 1
ans = 0
grp = []
for k in dict:
if dict[k] > 1:
grp.append(k)
for i in range(n):
for k in grp:
if lst1[i] | k == k:
ans += lst2[i]
break
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | def bitcode(lis):
bc = []
for n in lis:
if lis[n] > 1:
bc.append(n)
return bc
n = int(input())
lis = {}
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for bc in a:
try:
lis[bc] += 1
except:
lis[bc] = 1
bcs = bitcode(lis)
if len(bcs) == 0:
print(0)
else:
bsum = 0
for i in range(n):
if lis[a[i]] > 1:
bsum += b[i]
continue
for bc in bcs:
if a[i] & ~bc == 0:
bsum += b[i]
break
print(bsum) | FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = {}
for i in range(len(a)):
if a[i] in d:
d[a[i]][0] += b[i]
d[a[i]][1] += 1
else:
d[a[i]] = [b[i], 1]
s = 0
currset = set()
countmax = 0
to = 0
for i in d:
if d[i][1] > 1:
s += d[i][0]
num, temp = bin(i)[2:], bin(i)[2:].count("1")
currset.add(("0" * (60 - len(num)) + num, temp))
countmax = max(countmax, temp)
to = 1
for i in range(len(a)):
a[i] = [a[i], b[i]]
for i in range(len(a)):
a[i], b[i] = a[i][0], a[i][1]
for i in range(len(a)):
if d[a[i]][1] == 1:
temp = bin(a[i])[2:]
temp = "0" * (60 - len(temp)) + temp
temp2 = temp.count("1")
if temp2 <= countmax:
for j in currset:
if j[1] >= temp2:
curr = 1
for k in range(60):
if j[0][k] == "0" and temp[k] == "1":
curr = 0
break
if curr:
s += b[i]
break
to += 1
print(s if to else 0) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lis = []
d = {}
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
ans = 0
for i in d:
if d[i] > 1:
lis.append(i)
for i in range(len(lis)):
for j in range(n):
if lis[i] == a[j]:
ans += b[j]
for i in range(n):
if d[a[i]] == 1:
c = 0
for j in range(len(lis)):
if a[i] & lis[j] == a[i]:
lis.append(a[i])
ans += b[i]
break
print(ans) | 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | n = int(input())
b = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
rev = {}
dic = {}
for i in range(n):
bb = b[i]
if bb in dic:
dic[bb].append(i)
else:
dic[bb] = [i]
neg1 = (1 << 60) - 1
ans = 0
mask = 0
dels = []
for bb in dic:
inds = dic[bb]
if len(inds) > 1:
for ind in inds:
ans += a[ind]
mask |= bb
dels.append(bb)
if ans == 0:
print(0)
exit()
dic2 = {}
l2 = []
heads = []
for bb in dels:
dic2[bb] = bin(bb).count("1")
l2.append(bb)
del dic[bb]
l2.sort(key=lambda q: dic2[q], reverse=True)
for l in l2:
subs = False
for h in heads:
if l | ~h & neg1 == neg1:
subs = True
break
if not subs:
heads.append(l)
for bb in dic:
subs = False
for h in heads:
if h | ~bb & neg1 == neg1:
subs = True
break
if subs:
ans += a[dic[bb][0]]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | def bit(used, b):
count = 0
for num in used:
for i in range(b.bit_length() + 1):
if 1 << i & num == 0 and 1 << i & b:
count += 1
break
if count == len(used):
return True
else:
return False
def f(a, b):
arr = list(zip(a, b))
d = {}
for i in arr:
d[i[0]] = d.get(i[0], []) + [i[1]]
cmax = -1
ans = 0
used = set()
for i in d:
if len(d[i]) >= 2:
ans += sum(d[i])
cmax = max(cmax, i)
used.add(i)
for i in d:
if i in used:
continue
if bit(used, i) == True:
continue
else:
ans += sum(d[i])
return ans
a = input()
l = list(map(int, input().strip().split()))
l2 = list(map(int, input().strip().split()))
print(f(l, l2)) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER LIST LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 7000$) β the number of students interested in the camp.
The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i < 2^{60}$).
The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
-----Output-----
Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
-----Examples-----
Input
4
3 2 3 6
2 8 5 10
Output
15
Input
3
1 2 3
1 2 3
Output
0
Input
1
0
1
Output
0
-----Note-----
In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset. | import sys
input = sys.stdin.readline
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return a * b / gcd(a, b)
def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
f = {}
for i in range(n):
if a[i] not in d:
d[a[i]] = b[i]
f[a[i]] = 1
else:
d[a[i]] += b[i]
f[a[i]] += 1
ans = 0
used = [0] * n
for i in list(f.keys()):
if f[i] > 1:
for j in range(n):
if i | a[j] == i and not used[j]:
used[j] = 1
for i in range(n):
if used[i]:
ans += b[i]
print(ans)
return
def __starting_point():
main()
__starting_point() | IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | data = [int(i) for i in input()]
n = len(data)
minval = [0] * n
minval[-1] = 2 * data[-1] - 1
for i in range(n - 2, -1, -1):
if data[i] == 1:
minval[i] = min(1, minval[i + 1] + 1)
else:
minval[i] = min(-1, minval[i + 1] - 1)
ans = [i for i in data]
for i in range(n - 1, -1, -1):
if minval[i] == 1:
ans[i] = 0
ans2 = [str(i) for i in ans]
print("".join(ans2)) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | a = input() + "1"
n = len(a) - 1
s = [0] * (n + 1)
for q in range(n - 1, -1, -1):
s[q] = s[q + 1]
if a[q] == "1":
s[q] += 1
d = [0] * (n + 1)
for q in range(n - 1, -1, -1):
d[q] = max(s[q], d[q + 1])
if a[q] == "0":
d[q] = max(d[q], d[q + 1] + 1)
t = []
for q in range(n):
if a[q] == "0":
t.append("0")
elif d[q] == d[q + 1] + 1:
t.append("0")
else:
t.append("1")
print("".join(t)) | ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | import sys
INF = 10**10
def main():
st = list(input())
stk = []
for index, i in enumerate(st):
if i == "0" and len(stk) > 0 and stk[-1][0] == "1":
stk.pop()
else:
stk.append([i, index])
for li in stk:
st[li[1]] = "0"
print("".join(st))
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
print(*out, sep="\n") | IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR VAR STRING |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = list(map(int, input()))
ans = [0] * len(s)
back = []
for i, c in enumerate(s):
if c == 0:
if back:
ans[back.pop()] = 1
else:
back.append(i)
print(*ans, sep="") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
n = len(s)
if n == 1:
print(0)
elif n == 2:
if s == "10":
print("10")
else:
print("00")
else:
s_lis = 0
s_max = 0
s_zero = 0
t_zero = 0
stack_01 = []
t = []
for i in range(n):
t.append("0")
t_zero += 1
if s[i] == "0":
s_zero += 1
if i > 0 and s[i - 1 : i + 1] == "10":
t[i - 1] = "1"
t_zero -= 1
stack_01.append(i - 2)
if s_max <= int(s[i]):
s_lis += 1
s_max = max(s_max, int(s[i]))
if s_lis <= s_zero:
s_lis = s_zero
s_max = 0
if s_lis < t_zero:
while (
t[stack_01[-1]] == "1"
or s[stack_01[-1]] == "0"
or t[stack_01[-1] - 1] == "1"
):
stack_01.pop()
t[stack_01[-1]] = "1"
t_zero -= 1
stack_01[-1] -= 1
print(*t, sep="") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR WHILE VAR VAR NUMBER STRING VAR VAR NUMBER STRING VAR BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER STRING VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | import sys
s = list(input())
l = len(s)
sun = 0
for i in range(l - 1, -1, -1):
if s[i] == "0":
sun += 1
elif s[i] == "1" and sun:
sun -= 1
else:
s[i] = "0"
print("".join(s)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
ans = list(s)
n = len(s)
dp = [0] * n
i = 0
j = 1
while j < n:
if s[i] == "1" and s[j] == "0":
dp[i] = 1
dp[j] = 1
if i > 0:
while dp[i] == 1 and i > 0:
i -= 1
j += 1
else:
j += 1
i = j - 1
for i in range(n):
if dp[i] == 0:
ans[i] = "0"
print("".join(ans)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | v, t = 0, ""
for c in input()[::-1]:
if c < "1" or v:
t += c
v += 1 - (c < "1") * 2
else:
t += "0"
print(t[::-1]) | ASSIGN VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR STRING VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR STRING NUMBER VAR STRING EXPR FUNC_CALL VAR VAR NUMBER |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()[::-1]
ans = ""
c = 0
for i in s:
if i == "0":
ans += "0"
c += 1
elif c > 0:
ans += "1"
c -= 1
else:
ans += "0"
print(ans[::-1]) | ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR NUMBER |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | import sys
sys.setrecursionlimit(10**5 + 1)
inf = int(10**20)
max_val = inf
min_val = -inf
RW = lambda: sys.stdin.readline().strip()
RI = lambda: int(RW())
RMI = lambda: [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda: [x for x in sys.stdin.readline().strip().split()]
given = input()[::-1]
zeros = 0
lens = len(given)
rets = ""
for i in range(lens):
if given[i] == "0":
zeros += 1
rets += "0"
elif zeros > 0:
zeros -= 1
rets += "1"
else:
rets += "0"
rets = rets[::-1]
print(rets) | IMPORT EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
n = len(s)
tot = 0
S = list(s)
for i in range(n - 1, -1, -1):
if s[i] == "0":
tot += 1
elif tot:
tot -= 1
else:
S[i] = "0"
print("".join(S)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = list(map(int, input()))
stack = []
for i in range(len(s)):
if s[i] == 1:
stack.append(i)
elif len(stack) != 0:
stack.pop()
for i in stack:
s[i] = 0
s = list(map(str, s))
print("".join(s)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
ans = ["0" for i in range(len(s))]
st = []
for i in range(len(s)):
if s[i] == "0":
if len(st):
ans[st.pop()] = "1"
else:
st.append(i)
print("".join(ans)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
pre = [(0) for i in range(111111)]
suf = [(0) for i in range(111111)]
lens = len(s)
index = 0
for i in s:
index += 1
t = 0
if i == "0":
t = 1
else:
t = -1
pre[index] = min(pre[index - 1] + t, t)
index = lens + 1
for i in reversed(s):
index -= 1
t = 0
if i == "0":
t = 1
else:
t = -1
suf[index] = max(suf[index + 1] + t, t)
x = 0
for index, i in enumerate(s):
if i == "0":
print(i, end="")
pre[index + 1] = min(pre[index] + 1, 1)
elif pre[index] >= 0 and suf[index + 2] <= 0:
print("0", end="")
pre[index + 1] = min(pre[index] + 1, 1)
else:
print("1", end="")
pre[index + 1] = min(pre[index] - 1, -1) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | import sys
input = sys.stdin.readline
def solve():
i = 0
s = list(input().strip())
st = []
for c in s:
if c == "1":
st.append(i)
elif len(st) > 0:
st.pop()
i += 1
for i in st:
s[i] = "0"
print("".join(s))
solve() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
t = [0] * len(s)
stack = []
for i in range(len(s)):
if s[i] == "1":
stack.append(i)
elif len(stack) > 0:
pos = stack.pop()
t[pos] = 1
print("".join(map(str, t))) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
res = ["0"] * len(s)
min_dif = 0
length = len(s)
for i in range(length):
if s[length - i - 1] == "0":
min_dif = min([-1, min_dif - 1])
else:
if min_dif < 0:
res[length - i - 1] = "1"
min_dif = min([1, min_dif + 1])
print("".join(res)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | def main():
s = input()
n = len(s)
st = []
flags = [(False) for i in range(n)]
for i in range(n):
if s[i] == "1":
st.append(i)
elif len(st) != 0:
st.pop()
for i in range(len(st)):
flags[st[i]] = True
for i in range(n):
if flags[i] == True:
print("0", end="")
else:
print(s[i], end="")
print()
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = list(map(int, input()))
ps = [0]
for i in s:
if i == 0:
ps.append(ps[-1] + 1)
else:
ps.append(ps[-1] - 1)
b = 0
maba = 0
sufmax = [-(10**9)]
for i in range(len(ps) - 1, 0, -1):
sufmax.append(max(sufmax[-1], ps[i]))
sufmax = sufmax[::-1]
ans = []
cnt = 0
if s[0] == 1:
cnt += 1
else:
ans.append("0")
for i in range(1, len(s)):
if s[i] == 0 and s[i - 1] == 0:
ans.append("0")
elif s[i] == 1:
cnt += 1
else:
maba = sufmax[i] - ps[i]
maba = min(maba, cnt)
for _ in range(cnt - maba):
ans.append("0")
for _ in range(maba):
ans.append("1")
cnt = 0
ans.append("0")
for _ in range(len(s) - len(ans)):
ans.append("0")
print("".join(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
t = ""
blockable_ones = 0
is_blockable = False
last_num = "1"
for i in range(1, len(s) + 1):
num = s[-i]
if num == "0":
t += num
blockable_ones += 1
is_blockable = True
elif blockable_ones > 0 and is_blockable:
blockable_ones -= 1
t += num
else:
t += "0"
last_num = num
print(t[::-1]) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
s = [*s]
c = m = 0
for i in range(len(s) - 1, -1, -1):
c += -1 if s[i] == "0" else 1
if c > m:
s[i] = "0"
m = c
print("".join(s)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR STRING NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
n = len(s)
b = [0] * n
x = 1
l = []
for i in range(n):
l.append(i)
while x == 1:
x = 0
for i in range(len(s) - 1):
if s[i] == "1" and s[i + 1] == "0":
x = 1
b[int(l[i])] = 1
l[i] = l[i + 1] = 1000000
s = s.replace("10", "")
l = list(set(l))
if x == 1:
l.remove(1000000)
print(*b, sep="") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
ans = []
for i in range(0, len(s)):
ans.append(s[i])
c0 = 0
c1 = 0
for i in range(len(ans) - 1, -1, -1):
if ans[i] == "0":
c0 += 1
elif ans[i] == "1" and c1 >= c0:
ans[i] = "0"
else:
c1 += 1
ans = "".join(ans)
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = list(map(int, input()))
ans = []
cnt = 0
if s[0] == 1:
cnt += 1
else:
ans.append("0")
for i in range(1, len(s)):
if s[i] == 0 and s[i - 1] == 0:
ans.append("0")
elif s[i] == 1:
cnt += 1
else:
maba = 0
b = 0
for x in range(i, len(s)):
if s[x] == 1:
b -= 1
else:
b += 1
maba = max(maba, b)
maba = min(maba, cnt)
for _ in range(cnt - maba):
ans.append("0")
for _ in range(maba):
ans.append("1")
cnt = 0
ans.append("0")
for _ in range(len(s) - len(ans)):
ans.append("0")
print("".join(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = str(input().strip())
t = list(s[::-1])
cnt = 0
for i, v in enumerate(t):
if v == "0":
cnt += 1
elif cnt:
cnt -= 1
else:
t[i] = "0"
print("".join(t[::-1])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
n = len(s)
b = [0] * n
l = []
m = []
j = 0
for i in s:
if len(l) == 0:
l.append(i)
m.append(j)
elif l[-1] == "1" and i == "0":
l.pop()
b[m.pop()] = 1
else:
l.append(i)
m.append(j)
j += 1
print(*b, sep="") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | pp = input()
if len(pp) == 1:
print("0")
return
z = 1 if pp[0] == "0" else 0
zc = [z]
l = 1
lndl = [l]
for p in pp[1:]:
l = max(z + 1, l + (1 if p == "1" else 0))
z += 1 if p == "0" else 0
lndl.append(l)
zc.append(z)
lnda = lndl[-1]
o = 1 if pp[-1] == "1" else 0
oc = [o]
l = 1
lndr = [l]
for p in reversed(pp[:-1]):
l = max(o + 1, l + (1 if p == "0" else 0))
o += 1 if p == "1" else 0
lndr.append(l)
oc.append(o)
oc.reverse()
lndr.reverse()
qq = []
ez = 0
if pp[0] == "1":
if max(oc[1], lndr[1] + 1) != lnda:
qq.append("1")
else:
qq.append("0")
ez += 1
else:
qq.append("0")
for p, l, o, z, r in zip(pp[1:-1], lndl, oc[2:], zc, lndr[2:]):
if p == "1":
if max(l + o, z + ez + 1 + r) != lnda:
qq.append("1")
else:
qq.append("0")
ez += 1
else:
qq.append("0")
qq.append("0")
print("".join(qq)) | ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR STRING NUMBER NUMBER VAR VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR STRING NUMBER NUMBER VAR VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | a = list(map(int, input()))
w = [0] * len(a)
q = []
for i in range(len(a)):
if a[i] == 1:
q.append(i)
elif len(q) > 0:
qw = q.pop()
w[qw] = 1
print(*w, sep="") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | S = input()
N = len(S)
p = q = 0
prv = S[0]
c = 0
C = []
if S[0] == "1":
C.append(0)
for ch in S:
if ch != prv:
C.append(c)
c = 1
prv = ch
else:
c += 1
C.append(c)
ans = []
r = 0
L = len(C)
for i in range(L - 1, -1, -1):
c = C[i]
if i % 2:
r += c
if i != L - 1:
m = max(min(c - 1, r), 0)
else:
m = max(min(c, r), 0)
if m:
r -= m
ans.append("0" * m + "1" * (c - m))
else:
ans.append("1" * c)
else:
r -= c
ans.append("0" * c)
ans.reverse()
print(*ans, sep="") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | S = list(map(int, input().strip()))
N = len(S)
stack = []
for i in range(N):
s = S[i]
if s == 0 and stack and stack[-1][0] == 1:
stack.pop()
else:
stack.append((s, i))
T = S[:]
for i in tuple(map(list, zip(*stack)))[1]:
T[i] = 0
print("".join(map(str, T))) | 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 ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | st = input().rstrip()
a = []
for item in st:
a.append(int(item))
a.reverse()
zero_count = 0
for i, item in enumerate(a):
if item == 0:
zero_count += 1
elif zero_count > 0:
zero_count -= 1
else:
a[i] = 0
a.reverse()
print("".join([str(item) for item in a])) | 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 ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
t = list(s)
stack = []
for i in range(len(s)):
if t[i] == "1":
stack.append(i)
elif len(stack):
stack.pop()
for i in range(len(stack)):
t[stack[i]] = "0"
print("".join(t)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
res = ["0"] * len(s)
stk = []
for i in range(len(s)):
if s[i] == "0":
if len(stk) > 0:
res[stk[-1]] = "1"
stk.pop()
else:
stk.append(i)
print("".join(res)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | from sys import stdin
s = stdin.readline().strip()
dp = [(0) for i in range(len(s) + 2)]
ons = [(0) for i in range(len(s) + 2)]
zs = [(0) for i in range(len(s) + 2)]
for i in range(len(s) - 1, -1, -1):
if s[i] == "1":
ons[i] += 1
if i != len(s) - 1:
ons[i] += ons[i + 1]
z = 0
for i in range(len(s) - 1, -1, -1):
if s[i] == "1":
dp[i] = max(1 + ons[i + 1], z)
else:
dp[i] = max(dp[i + 1] + 1, 1 + ons[i + 1])
z = dp[i]
zs[i] = z
ans = ""
for i in range(len(s)):
if s[i] == "1":
x = dp[i]
y = 1 + dp[i + 1]
if x == y:
ans += "0"
else:
ans += "1"
else:
ans += "0"
print(ans) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = str(input())
n = len(s)
ns = ["0" for i in range(n)]
st = []
for i in range(n):
if s[i] == "0":
if len(st):
ns[st.pop()] = "1"
else:
st.append(i)
print("".join(ns)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | import sys
input = sys.stdin.readline
s = list(input().rstrip())
n = len(s)
c = m = 0
for i in range(n)[::-1]:
c += -1 if s[i] == "0" else 1
if c > m:
s[i] = "0"
c = m
print("".join(s)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = [int(x) for x in list(input())]
n = len(s)
b = [0] * n
counter = 0
for i in range(n - 1, -1, -1):
if s[i] == 0:
counter += 1
elif counter > 0:
counter -= 1
else:
s[i] = 0
arr = ""
for item in s:
arr += str(item)
print(arr) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | import sys
def main():
import sys
input = sys.stdin.readline
s = [int(i) for i in input()[:-1]][::-1]
n = len(s)
dp = [([0] * n) for _ in range(n)]
for j in range(n):
tmp = [0, 0]
for i in range(j, n):
if s[i] == 0:
tmp[0] = max(tmp) + 1
dp[j][i] = tmp[0]
else:
tmp[1] += 1
dp[j][i] = tmp[1]
t = ""
dp2 = [([0] * n) for _ in range(n)]
tmp = [[0, 0] for _ in range(n)]
for j in range(n):
okay = 1
prev = [0] * (j + 1)
for i in range(j + 1):
prev[i] = tmp[i][0]
tmp[i][0] = max(tmp[i]) + 1
dp2[i][j] = tmp[i][0]
if dp2[i][j] != dp[i][j]:
okay = 0
if not okay:
for i in range(j + 1):
tmp[i][0] = prev[i]
tmp[i][1] += 1
dp2[i][j] = tmp[i][1]
t += "1"
else:
t += "0"
print(t[::-1])
return 0
main() | IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()[::-1]
count = 0
n = len(s)
s1 = ""
for i in range(n):
if s[i] == "0":
count += 1
s1 += "0"
elif count > 0:
count -= 1
s1 += "1"
else:
s1 += "0"
s1 = s1[::-1]
print(s1) | ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
s = list(s)
l = len(s) - 1
z = 0
for i in range(l, -1, -1):
if s[i] == "0":
z += 1
elif z:
z -= 1
else:
s[i] = "0"
s = "".join(s)
print(s) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s = input()
a, b, c = [], [], []
count = 0
for i in range(len(s) - 1, -1, -1):
a.append(s[i])
for i in range(len(a)):
if a[i] == "0":
count += 1
b.append("0")
elif a[i] == "1" and count > 0:
count -= 1
b.append("1")
elif a[i] == "1" and count == 0:
b.append("0")
for i in range(len(b) - 1, -1, -1):
c.append(b[i])
ans = "".join(c)
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | line = input()
res = []
zer = 0
one = 0
for i in range(len(line)):
ind = len(line) - 1 - i
if line[ind] == "0":
res.append("0")
zer += 1
else:
if zer <= one:
res.append("0")
zer += 1
else:
res.append("1")
one += 1
for i in range(len(res)):
print(res[len(res) - 1 - i], end="")
print("\n", end="") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR STRING STRING |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | s, cnt = list(input()), 0
for i in range(len(s) - 1, -1, -1):
if s[i] == "0":
cnt += 1
elif cnt:
cnt -= 1
else:
s[i] = "0"
print("".join(s)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | a = input()
a = list(a)
l = []
for i in range(0, len(a)):
l.append([a[i], i])
i = 1
while i < len(l):
if l[i][0] == "0" and l[i - 1][0] == "1":
l.pop(i)
l.pop(i - 1)
i -= 2
if i == -1:
i = 0
i += 1
for i in range(0, len(l)):
a[l[i][1]] = 0
print(*a, sep="") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING VAR BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING |
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:
For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
The number of zeroes in $t$ is the maximum possible.
A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.
If there are multiple substrings which satisfy the conditions, output any.
-----Input-----
The first line contains a binary string of length not more than $2\: 000$.
-----Output-----
Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.
-----Examples-----
Input
110
Output
010
Input
010
Output
010
Input
0001111
Output
0000000
Input
0111001100111011101000
Output
0011001100001011101000
-----Note-----
In the first example:
For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
The second example is similar to the first one. | inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True and False
def ddprint(x):
if DBG:
print(x)
s = input().strip()
n = len(s)
ones = []
stk = []
for i in range(n):
if len(stk) > 0 and stk[-1][0] == "1" and s[i] == "0":
ones.append(stk[-1][1])
stk.pop()
else:
stk.append((s[i], i))
ones.sort()
ans = ""
cur = 0
for i in ones:
for j in range(cur, i):
ans += "0"
ans += "1"
cur = i + 1
for j in range(cur, n):
ans += "0"
print(ans) | 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
arr = []
while t > 0:
t -= 1
n = int(input())
a = 0
maxi = 0
arr.clear()
inpArr = input().split(" ")
for i in range(len(inpArr)):
arr.append(int(inpArr[i]))
maxi = max(maxi, arr[i])
a += arr[i]
if n == 1:
print("T")
elif n == 2:
if arr[0] == arr[1]:
print("HL")
else:
print("T")
elif maxi > a - maxi:
print("T")
elif a % 2 == 1:
print("T")
else:
print("HL") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for _ in range(t):
n = input()
a = [int(i) for i in input().split()]
maxi = max(a)
s = sum(a)
if s < 2 * maxi or s % 2 == 1:
print("T")
else:
print("HL") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
t = sum(a)
flag = 0
for i in range(n):
if 2 * a[i] > t:
flag = 1
break
if t % 2 == 1:
flag = 1
if flag == 1:
print("T")
else:
print("HL") | 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 FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for i in range(t):
n = int(input())
data = list(map(int, input().split()))
data = sorted(data, reverse=True)
sd = sum(data[1:])
if data[0] > sd:
print("T")
elif data[0] == sd:
print("HL")
else:
temp = sd - data[0]
if temp % 2 == 0:
print("HL")
else:
print("T") | 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | a = int(input())
b = []
c = []
for i in range(a):
b.append(int(input()))
c.append(list(map(int, input().split())))
for i in range(a):
if b[i] == 1:
print("T")
elif b[i] == 2:
if c[i][0] == c[i][1]:
print("HL")
else:
print("T")
elif max(c[i]) > sum(c[i]) / 2:
print("T")
elif sum(c[i]) % 2 == 0:
print("HL")
else:
print("T") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
sumi = sum(a[: n - 1])
s = a[-1]
if s > sumi:
print("T")
continue
sumi += s
if sumi % 2:
print("T")
continue
print("HL") | 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 FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | import sys
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
if 2 * max(a) > sum(a) or sum(a) % 2 == 1:
print("T")
else:
print("HL") | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL 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 IF BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
most = max(a)
s = sum(a)
if most > s - most:
print("T")
elif most == s - most:
print("HL")
elif s % 2 == 0:
print("HL")
else:
print("T") | 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 FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
if n == 1 and s > 0 or sum(arr) < 2 * max(arr):
print("T")
elif s % 2 == 0:
print("HL")
else:
print("T") | 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 VAR NUMBER FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | import sys
input = sys.stdin.buffer.readline
def solve():
n = int(input())
alst = list(map(int, input().split()))
if n == 1:
print("T")
return
total = sum(alst)
max_a = max(alst)
if max_a * 2 > total:
print("T")
elif total % 2 == 0:
print("HL")
else:
print("T")
t = int(input())
for _ in range(t):
solve() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input().split()[0])
for case in range(t):
n = int(input().split()[0])
a = list(map(int, input().split()))
if n == 1:
print("T")
else:
a.sort()
if sum(a) - a[n - 1] < a[n - 1]:
print("T")
elif sum(a) % 2 == 0:
print("HL")
else:
print("T") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | for ad in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l.sort()
l.reverse()
if n == 1:
print("T")
continue
elif n == 2:
if l[0] > l[1]:
print("T")
else:
print("HL")
continue
t = 0
i = 0
j = 0
while True:
l.sort(reverse=True)
if t == 0:
if l[0] > 0:
l[0] -= 1
else:
i = 1
break
if l[1] > 0:
l[1] -= 1
else:
j = 1
break
if i == 1:
print("HL")
else:
print("T") | 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 EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
if max(a) > sum(a) / 2:
print("T")
elif sum(a) % 2 == 1:
print("T")
else:
print("HL") | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for _ in range(t):
n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
print("T")
continue
elif n == 2:
if a[0] == a[1]:
print("HL")
else:
print("T")
continue
total = sum(a)
if total % 2 or max(a) * 2 > total:
print("T")
else:
print("HL") | 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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | cases = int(input())
for t in range(cases):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
if a[0] == 0:
print("HL")
else:
print("T")
else:
a = sorted(a)
if a[-1] > sum(a[:-1]):
print("T")
else:
s = 0
for i in range(n):
s += a[i] - 1
if s % 2 == 0:
if n % 2 == 0:
print("HL")
else:
print("T")
elif n % 2 == 0:
print("T")
else:
print("HL") | 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 IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
s = sum(a)
flag = False
for x in a:
if x > s // 2:
flag = True
break
if flag:
print("T")
continue
print("HL" if s % 2 == 0 else "T") | 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
s = sum(a)
if a[n - 1] * 2 > s or s % 2 == 1:
print("T")
elif s % 2 == 0:
print("HL") | 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 FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for _ in range(t):
p = int(input())
arr = list(map(int, input().split()))
if len(arr) == 1:
print("T")
else:
last = 999
ind = 997
c = 0
while ind != 998:
ind = 998
best = 0
for i in range(len(arr)):
if arr[i] > best and i != last:
ind = i
best = arr[i]
if ind < 900:
arr[ind] -= 1
c += 1
last = ind
if c % 2 == 0:
print("HL")
else:
print("T") | 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 IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
while t:
t -= 1
n = int(input())
l = list(map(int, input().split()))
m = max(l)
s = sum(l)
if s % 2 or 2 * m > s:
print("T")
else:
print("HL") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | import sys
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n == 1:
print("T")
else:
s = sum(a) - a[-1]
if a[-1] > s:
print("T")
else:
s += a[-1]
if s % 2 == 0:
print("HL")
else:
print("T") | 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 EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def gift():
for _ in range(t):
n = int(input())
arry = list(map(int, input().split()))
if n == 1:
yield "T"
elif n == 2:
if arry[0] != arry[1]:
yield "T"
else:
yield "HL"
else:
sumN = sum(arry)
maxNum = max(arry)
if maxNum > sumN - maxNum:
yield "T"
elif sumN % 2:
yield "T"
else:
yield "HL"
t = int(input())
ans = gift()
print(*ans, sep="\n") | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF 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 IF VAR NUMBER EXPR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR STRING EXPR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR STRING IF BIN_OP VAR NUMBER EXPR STRING EXPR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
while t > 0:
n = int(input())
l = list(map(int, input().split()))
ls = [0] * n
tu = 0
p = 0
while True:
m = 0
ind = -1
for i in range(n):
if l[i] > m and ls[i] == 0:
m = l[i]
ind = i
if ind == -1:
break
else:
tu += 1
l[ind] -= 1
ls[p] = 0
p = ind
ls[p] = 1
if tu % 2 == 0:
print("HL")
else:
print("T")
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | for w in range(eval(input())):
n = eval(input())
l = [int(i) for i in input().split()]
s = sum(l)
if max(l) * 2 > s or s % 2 == 1:
print("T")
else:
print("HL") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | for s in [*open(0)][2::2]:
s = sum((a := [*map(int, s.split())]))
print("HTL"[s < 2 * max(map(int, a)) or s % 2 :: 2]) | FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | def check_done(a):
count = 0
for i in a:
if i != 0:
count += 1
if count == 2:
return False
return True
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
turn = "T"
T_pick = -1
H_pick = -1
while True:
if n == 1:
print("T")
break
max_num = max(a)
idx_max = a.index(max_num)
max_two = -1
max_two_idx = -1
for i in range(n):
if i != idx_max:
if a[i] > max_two:
max_two = a[i]
max_two_idx = i
if turn == "T":
turn = "HL"
if H_pick != idx_max:
T_pick = idx_max
a[idx_max] -= 1
else:
T_pick = max_two_idx
a[max_two_idx] -= 1
else:
turn = "T"
if T_pick != idx_max:
H_pick = idx_max
a[idx_max] -= 1
else:
H_pick = max_two_idx
a[max_two_idx] -= 1
if check_done(a):
print(turn)
break | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR STRING ASSIGN VAR STRING IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
n = int(input())
A = list(map(int, input().split()))
if n == 1:
print("T")
elif n == 2:
if A[0] == A[1]:
print("HL")
else:
print("T")
else:
SUM = sum(A)
MAX = max(A)
if MAX > SUM - MAX:
print("T")
elif SUM % 2 != 0:
print("T")
else:
print("HL") | 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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | import sys
input = sys.stdin.readline
def solve(n, a):
if n == 1:
print("T")
return
s = sum(a)
if max(a) > s - max(a):
print("T")
return
s -= n
if s % 2 == 0:
cur = "T"
else:
cur = "HL"
if n % 2 == 0:
print("T" if cur == "HL" else "HL")
else:
print(cur)
for nt in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
solve(n, a) | IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING STRING STRING EXPR FUNC_CALL 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 EXPR FUNC_CALL VAR VAR VAR |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for you in range(t):
n = int(input())
l = input().split()
li = [int(i) for i in l]
z = sum(li)
if z % 2:
print("T")
continue
poss = 0
for i in li:
if 2 * i > z:
poss = 1
break
if poss:
print("T")
else:
print("HL") | 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 FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | test = int(input())
for t in range(0, test):
n = int(input())
a = [int(i) for i in input().split(" ")]
m1 = max(a)
c = 0
a.remove(m1)
while sum(a):
m2 = max(a)
a.append(m1 - 1)
a.remove(m2)
m1 = m2
c += 1
if c % 2:
print("HL")
else:
print("T") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
while t:
t -= 1
n = int(input())
lst = list(map(int, input().split()))
max_ele = max(lst)
sum1 = sum(lst)
diff = sum1 - max_ele
if max_ele > sum1:
print("T")
elif diff >= max_ele and diff % 2 == max_ele % 2:
print("HL")
else:
print("T") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | def checkWin(a, summ):
if summ % 2 == 1:
return "T"
for i in range(n):
if a[i] > summ - a[i]:
return "T"
return "HL"
def simulate(a):
popped = True
turn = 0
while True:
a.sort()
if len(a) == 0 or len(a) == 1 and not popped:
if turn == 0:
return "HL"
else:
return "T"
a[0] -= 1
if a[0] == 0:
a.pop(0)
popped = True
else:
popped = False
turn = (turn + 1) % 2
T = int(input())
for t in range(T):
n = int(input())
a = []
s = input().split()
summ = 0
for i in range(n):
a.append(int(s[i]))
summ += a[i]
print(checkWin(a, summ)) | FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER RETURN STRING RETURN STRING VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP 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 LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for q in range(t):
n = int(input())
A = [int(i) for i in input().split()]
vis = -1
last = 1
t = True
while t:
m = 0
mi = -1
sm = 0
smi = -1
for i in range(n):
if A[i] > m:
sm = m
smi = mi
m = A[i]
mi = i
elif A[i] > sm:
sm = A[i]
smi = i
if m == 0 and sm == 0:
break
if vis != mi:
A[mi] -= 1
vis = mi
last = (last + 1) % 2
elif sm == 0:
break
else:
A[smi] -= 1
vis = smi
last = (last + 1) % 2
if last == 1:
print("HL")
else:
print("T") | 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | T = int(input())
for _ in range(T):
n, ar = int(input()), list(map(int, input().split()))
ar.sort()
sm, psm, last = sum(ar), sum(ar) - ar[-1], ar[-1]
if last > psm or sm % 2:
print("T")
else:
print("HL") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | from sys import stdin
input = stdin.readline
def put():
return map(int, input().split())
def fail():
print(-1)
exit()
t = int(input())
for _ in range(t):
n = int(input())
if n == 1:
_ = input()
print("T")
else:
l = list(put())
x = 0
m = max(l)
for i in l:
x += i
if m > x - m or x % 2 == 1:
print("T")
else:
print("HL") | ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | def main():
t = int(input())
for i in range(t):
n = int(input())
a = tuple(map(int, input().split()))
winner = who_wins(("T", "HL"), a)
print(winner)
def who_wins(players, field):
players = tuple(players)
field = sorted(field)
max_value = field.pop()
other_values_sum = sum(field)
delta = max_value - other_values_sum
if delta > 0:
winner_index = 0
elif delta == 0:
winner_index = 1
else:
assert delta < 0
winner_index = 1 if delta % 2 == 0 else 0
return players[winner_index]
main() | 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER RETURN VAR VAR EXPR FUNC_CALL VAR |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
nokori_a = sum(a) - max_a
if nokori_a < max_a:
print("T")
continue
if sum(a) % 2 == 0:
print("HL")
else:
print("T") | 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | def solve():
n = int(input())
a = list(map(int, input().split()))
mx = max(a)
s = sum(a)
if s - mx < mx or s & 1:
print("T")
else:
print("HL")
for _ in range(int(input())):
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 VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | t = int(input())
for juego in range(t):
n = int(input())
a = [int(x) for x in input().split()]
maxx = 0
summ = 0
for i in range(n):
if a[i] > maxx:
maxx = a[i]
summ += a[i]
if maxx > summ - maxx:
print("T")
elif summ % 2:
print("T")
else:
print("HL") | 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
flag = True
if n == 1:
print("T")
elif arr[0] > sum(arr[1:]):
print("T")
elif (sum(arr[1:]) - arr[0]) % 2 == 1:
print("T")
else:
print("HL") | 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 NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
arr = [int(el) for el in input().split()]
if n == 1:
print("T")
elif max(arr) > sum(arr) - max(arr):
print("T")
elif sum(arr) % 2 == 0:
print("HL")
else:
print("T") | 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 VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of $t$ games, determine the winner of each game.
-----Input-----
The first line of the input contains a single integer $t$ $(1 \le t \le 100)$ β the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer $n$ $(1 \le n \le 100)$ β the number of piles.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 100)$.
-----Output-----
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
-----Example-----
Input
2
1
2
2
1 1
Output
T
HL
-----Note-----
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $1$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | def rainy(S, L):
if sum(L) < 2 * max(L) or sum(L) % 2:
return "T"
return "HL"
C = int(input())
for i in range(C):
S = int(input())
L = list(map(int, input().split()))
print(rainy(S, L)) | FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN STRING 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 FUNC_CALL VAR VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.