description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
The only difference between easy and hard versions is a number of elements in the array.
You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$.
You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$.
You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$.
You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible.
Note that you can choose the empty set.
If there are multiple answers, you can print any.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 300, 0 \le m \le 300$) β the length of the array $a$ and the number of segments, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$.
The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment.
-----Output-----
In the first line of the output print one integer $d$ β the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$.
In the second line of the output print one integer $q$ ($0 \le q \le m$) β the number of segments you apply.
In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) β indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible.
If there are multiple answers, you can print any.
-----Examples-----
Input
5 4
2 -2 3 1 2
1 3
4 5
2 5
1 3
Output
6
2
1 4
Input
5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5
Output
7
2
3 2
Input
1 0
1000000
Output
0
0
-----Note-----
In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$.
In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$.
In the third example you cannot do anything so the answer is $0$. | n, m = map(int, input().split())
x = list(map(int, input().split()))
q = [0] * m
for i in range(m):
q[i] = list(map(int, input().split()))
ans = 0
ansNum = 0
ansS = ""
for i in range(n):
maxVal = x[i]
maxIndex = i + 1
temp = [0] * n
tempNum = 0
tempS = ""
for k in range(n):
temp[k] = x[k]
for js in range(len(q)):
j = q[js]
if not j[0] <= maxIndex <= j[1]:
tempNum += 1
tempS += " " + str(js + 1)
for l in range(j[0] - 1, j[1]):
temp[l] -= 1
tempAns = maxVal - min(temp)
if tempAns > ans:
ans = tempAns
ansNum = tempNum
ansS = tempS
print(ans)
print(ansNum)
print(ansS[1:]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
The only difference between easy and hard versions is a number of elements in the array.
You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$.
You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$.
You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$.
You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible.
Note that you can choose the empty set.
If there are multiple answers, you can print any.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 300, 0 \le m \le 300$) β the length of the array $a$ and the number of segments, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$.
The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment.
-----Output-----
In the first line of the output print one integer $d$ β the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$.
In the second line of the output print one integer $q$ ($0 \le q \le m$) β the number of segments you apply.
In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) β indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible.
If there are multiple answers, you can print any.
-----Examples-----
Input
5 4
2 -2 3 1 2
1 3
4 5
2 5
1 3
Output
6
2
1 4
Input
5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5
Output
7
2
3 2
Input
1 0
1000000
Output
0
0
-----Note-----
In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$.
In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$.
In the third example you cannot do anything so the answer is $0$. | def __starting_point():
n, subset = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
f = []
t = []
for i in range(subset):
x, y = map(int, input().split(" "))
f.append(x - 1)
t.append(y - 1)
diff = 0
answer = []
for ma in range(n):
for mi in range(n):
inside = 0
cur_answer = []
for sub in range(subset):
if f[sub] <= mi <= t[sub] and not f[sub] <= ma <= t[sub]:
inside += 1
cur_answer.append(sub)
if a[ma] - (a[mi] - inside) > diff:
diff = a[ma] - (a[mi] - inside)
answer = cur_answer
print(diff)
print(len(answer))
print(" ".join(str(x + 1) for x in answer))
__starting_point() | FUNC_DEF ASSIGN VAR 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 ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR |
The only difference between easy and hard versions is a number of elements in the array.
You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$.
You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$.
You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$.
You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible.
Note that you can choose the empty set.
If there are multiple answers, you can print any.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 300, 0 \le m \le 300$) β the length of the array $a$ and the number of segments, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$.
The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment.
-----Output-----
In the first line of the output print one integer $d$ β the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$.
In the second line of the output print one integer $q$ ($0 \le q \le m$) β the number of segments you apply.
In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) β indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible.
If there are multiple answers, you can print any.
-----Examples-----
Input
5 4
2 -2 3 1 2
1 3
4 5
2 5
1 3
Output
6
2
1 4
Input
5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5
Output
7
2
3 2
Input
1 0
1000000
Output
0
0
-----Note-----
In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$.
In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$.
In the third example you cannot do anything so the answer is $0$. | import sys
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n, m = inpl()
a = inpl()
mx = max(a)
a = [(-(x - mx)) for x in a]
s = [inpl() for _ in range(m)]
res = 0
Q = []
for i in range(n):
for j in range(n):
if i == j:
continue
q = []
for k, (l, r) in enumerate(s):
if l - 1 <= i <= r - 1 and not l - 1 <= j <= r - 1:
q.append(k + 1)
ans = a[i] - a[j] + len(q)
if ans > res:
res = ans
Q = q[:]
print(res)
print(len(Q))
print(*Q) | IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
The only difference between easy and hard versions is a number of elements in the array.
You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$.
You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$.
You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$.
You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible.
Note that you can choose the empty set.
If there are multiple answers, you can print any.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 300, 0 \le m \le 300$) β the length of the array $a$ and the number of segments, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$.
The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment.
-----Output-----
In the first line of the output print one integer $d$ β the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$.
In the second line of the output print one integer $q$ ($0 \le q \le m$) β the number of segments you apply.
In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) β indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible.
If there are multiple answers, you can print any.
-----Examples-----
Input
5 4
2 -2 3 1 2
1 3
4 5
2 5
1 3
Output
6
2
1 4
Input
5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5
Output
7
2
3 2
Input
1 0
1000000
Output
0
0
-----Note-----
In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$.
In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$.
In the third example you cannot do anything so the answer is $0$. | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for i in range(m):
b.append(list(map(int, input().split())))
ans = -1000000000
for i in range(n):
ac = a.copy()
for j in range(m):
if i + 1 < b[j][0] or i + 1 > b[j][1]:
for k in range(b[j][0] - 1, b[j][1]):
ac[k] -= 1
if a[i] - min(ac) > ans:
ans = a[i] - min(ac)
ansi = i
ansh = []
i = ansi
ac = a.copy()
q = 0
for j in range(m):
if i + 1 < b[j][0] or i + 1 > b[j][1]:
q += 1
ansh.append(j + 1)
print(ans)
print(q)
print(*ansh) | ASSIGN VAR 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 FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
The only difference between easy and hard versions is a number of elements in the array.
You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$.
You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$.
You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$.
You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible.
Note that you can choose the empty set.
If there are multiple answers, you can print any.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 300, 0 \le m \le 300$) β the length of the array $a$ and the number of segments, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$.
The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment.
-----Output-----
In the first line of the output print one integer $d$ β the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$.
In the second line of the output print one integer $q$ ($0 \le q \le m$) β the number of segments you apply.
In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) β indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible.
If there are multiple answers, you can print any.
-----Examples-----
Input
5 4
2 -2 3 1 2
1 3
4 5
2 5
1 3
Output
6
2
1 4
Input
5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5
Output
7
2
3 2
Input
1 0
1000000
Output
0
0
-----Note-----
In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$.
In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$.
In the third example you cannot do anything so the answer is $0$. | n, m = map(int, input().split())
ls = list(map(int, input().split()))
segs = [None for _ in range(m)]
maxdiv = 0
maxsegs = set()
for i in range(m):
l, r = map(int, input().split())
segs[i] = l - 1, r - 1
for maxi in range(n):
currarr = [(0) for _ in range(n + 1)]
usegs = set()
for ind, seg in enumerate(segs):
if maxi < seg[0] or maxi > seg[1]:
currarr[seg[0]] -= 1
currarr[seg[1] + 1] += 1
usegs.add(ind)
cnt = 0
minv = 10000000
for j in range(n):
cnt += currarr[j]
v = ls[j] + cnt
if v < minv:
minv = v
v = ls[maxi] - minv
if maxdiv < v:
maxdiv = v
maxsegs = usegs
print(maxdiv)
print(len(maxsegs))
print(" ".join([str(v + 1) for v in maxsegs])) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR |
The only difference between easy and hard versions is a number of elements in the array.
You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$.
You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$.
You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$.
You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible.
Note that you can choose the empty set.
If there are multiple answers, you can print any.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 300, 0 \le m \le 300$) β the length of the array $a$ and the number of segments, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$.
The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment.
-----Output-----
In the first line of the output print one integer $d$ β the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$.
In the second line of the output print one integer $q$ ($0 \le q \le m$) β the number of segments you apply.
In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) β indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible.
If there are multiple answers, you can print any.
-----Examples-----
Input
5 4
2 -2 3 1 2
1 3
4 5
2 5
1 3
Output
6
2
1 4
Input
5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5
Output
7
2
3 2
Input
1 0
1000000
Output
0
0
-----Note-----
In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$.
In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$.
In the third example you cannot do anything so the answer is $0$. | n, m = map(int, input().split())
inputList = [0] + list(map(int, input().split())) + [0]
inputIntervals = []
for _ in range(m):
inputIntervals.append(tuple(map(int, input().split())))
def wynik(in1, in2):
intervals = [[] for _ in range(n + 1)]
for nr, (a, b) in enumerate(in2):
intervals[b] += [(a, nr + 1)]
wyn = 0, []
minek = in1[1]
numerki = []
for i in range(2, n + 1):
minek = min(minek, in1[i - 1])
for j, ind in intervals[i - 1]:
for k in range(j, i):
in1[k] -= 1
minek = min(minek, in1[k])
numerki += [ind]
wyn = max(wyn, (in1[i] - minek, list(numerki)))
return wyn
odp = max(
wynik(
list(reversed(inputList)),
list(map(lambda x: (n - x[1] + 1, n - x[0] + 1), inputIntervals)),
),
wynik(inputList, inputIntervals),
)
print(odp[0], len(odp[1]), sep="\n")
print(*odp[1]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER LIST ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER |
The only difference between easy and hard versions is a number of elements in the array.
You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$.
You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$.
You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$.
You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible.
Note that you can choose the empty set.
If there are multiple answers, you can print any.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 300, 0 \le m \le 300$) β the length of the array $a$ and the number of segments, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$.
The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment.
-----Output-----
In the first line of the output print one integer $d$ β the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$.
In the second line of the output print one integer $q$ ($0 \le q \le m$) β the number of segments you apply.
In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) β indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible.
If there are multiple answers, you can print any.
-----Examples-----
Input
5 4
2 -2 3 1 2
1 3
4 5
2 5
1 3
Output
6
2
1 4
Input
5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5
Output
7
2
3 2
Input
1 0
1000000
Output
0
0
-----Note-----
In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$.
In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$.
In the third example you cannot do anything so the answer is $0$. | n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
if n > 300:
lst = []
for i in range(m):
a, b = list(map(int, input().split()))
lst.append([a, b])
answer = 0
answer_1 = []
m300 = [[-1, -(10**6)]]
for i in range(max(0, m - 1)):
m300.append([-1, -(10**6)])
for u in range(n):
if A[u] > min(m300)[1]:
m300[m300.index(min(m300))] = [u, A[u]]
for i, mi in m300:
B = A.copy()
kek = []
for j in range(m):
a, b = lst[j][0], lst[j][1]
if a <= i + 1 <= b:
kek.append(j + 1)
for q in range(a - 1, b):
B[q] -= 1
elem = max(B)
if answer < elem - mi:
answer = elem - mi
answer_1 = kek.copy()
print(answer)
print(len(answer_1))
print(" ".join(map(str, answer_1)))
else:
lst = []
for i in range(m):
a, b = list(map(int, input().split()))
lst.append([a, b])
answer = 0
answer_1 = []
for i in range(n):
B = A.copy()
kek = []
for j in range(m):
a, b = lst[j][0], lst[j][1]
if a <= i + 1 <= b:
kek.append(j + 1)
for q in range(a - 1, b):
B[q] -= 1
elem = max(B)
if answer < elem - B[i]:
answer = elem - B[i]
answer_1 = kek.copy()
print(answer)
print(len(answer_1))
print(" ".join(map(str, answer_1))) | ASSIGN VAR 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 IF VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Two players are playing a game. They are given an array A_{1}, A_{2}, \ldots, A_{N} as well as an array B_{1}, B_{2}, \ldots, B_{M}.
The game consists of M rounds. Players are participating in rounds alternatively. During the i-th round (for i from 1 to M) the corresponding player (first player, if i is odd, and second if i is even) has to do exactly one of the following:
* remove all elements from the array A that are divisible by B_{i},
* remove all elements from the array A that are not divisible by B_{i}.
The first player wants to minimize the sum of the remaining elements in the array A after all M rounds, and the second wants to maximize it. Find the sum of the remaining elements in the array A after all M rounds if both players are playing optimally.
------ Input Format ------
The first line contains two integers N, M - the length of the array A and the number of rounds in the game.
The second line contains N integers A_{1}, A_{2}, \ldots, A_{N} - the elements of the array A.
The third line contains M integers B_{1}, B_{2}, \ldots, B_{M} - the elements of the array B.
------ Output Format ------
Output a single integer - the sum of the remaining elements of the array A after all M rounds if both players are playing optimally.
------ Constraints ------
$1 β€ N β€ 2 \cdot 10^{4}$
$1 β€ M β€ 2 \cdot 10^{5}$
$-4 \cdot 10^{14} β€ A_{i} β€ 4 \cdot 10^{14}$
$1 β€ B_{i} β€ 4 \cdot 10^{14}$
------ subtasks ------
Subtask 1 (22 points): $B_{i + 1} \bmod B_{i} = 0$ ($1 β€ i < M$)
Subtask 2 (24 points): $1 β€ M β€ 20$
Subtask 3 (28 points): $1 β€ M β€ 100$
Subtask 4 (26 points): No additional constraints
----- Sample Input 1 ------
6 2
2 2 5 2 2 7
2 5
----- Sample Output 1 ------
7
----- explanation 1 ------
In the sample, one possible flow of the game is the following:
- Round $1$: first player removes from $A$ all elements divisible by $2$. $A$ becomes $(5, 7)$.
- Round $2$: second player removes from $A$ all elements divisible by $5$. $A$ becomes $(7)$. If he had removed from $A$ all elements not divisible by $5$, $A$ would become $(5)$, which has a smaller sum of elements and therefore is not desirable for the second player. | def ans(a, b, i):
if len(a) == 0:
return 0
x = [[], []]
for j in a:
if j % b[i] == 0:
x[0].append(j)
else:
x[1].append(j)
if i == len(b) - 1:
if i % 2 == 0:
return min(sum(x[0]), sum(x[1]))
else:
return max(sum(x[0]), sum(x[1]))
if i % 2 == 0:
return min(ans(x[0], b, i + 1), ans(x[1], b, i + 1))
else:
return max(ans(x[0], b, i + 1), ans(x[1], b, i + 1))
n = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
if n[1] > 50:
print(0)
else:
print(ans(a, b, 0)) | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST LIST LIST FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
k, l, r, t, x, y = map(int, input().split())
if x == y:
if k + y <= r:
print("Yes")
elif k - x >= l:
print("Yes")
else:
print("No")
sys.exit()
if x > y:
if k + y <= r:
k += y
if k - x - (t - 1) * (x - y) >= l:
print("Yes")
else:
print("No")
sys.exit()
vs = set()
f = 1
total = 0
while True:
d = k - l
n, m = divmod(d, x)
total += n
k = l + m
if total >= t:
break
if m in vs:
break
vs.add(m)
if k + y > r:
f = 0
break
k += y
if f:
print("Yes")
else:
print("No") | IMPORT ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
k, l, r, t, x, y = map(int, input().split())
if k < l or k > r:
print("No")
sys.exit()
if y < x:
if k + y <= r:
k += y
k -= x
if k < l:
print("No")
sys.exit()
t -= 1
cur = (k - l) // (x - y)
print("Yes" if cur >= t else "No")
sys.exit()
else:
seen = [0] * x
while t > 0:
if seen[k % x]:
print("Yes")
sys.exit()
seen[k % x] = 1
cur = (k - l) // x
if cur >= t:
print("Yes")
sys.exit()
t -= cur
k -= cur * x
if k + y > r:
print("No")
sys.exit()
k += y - x
t -= 1
print("Yes") | IMPORT ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
k, l, r, t, x, y = list(map(int, input().split()))
if y < x:
if k + y <= r:
k += y
k -= x
nb_days = int((k - l) / (x - y)) + 1
print("Yes" if nb_days >= t else "No")
elif x < y:
memo = {}
nb_days = 0
if (k - l) % x == k - l:
k += y
if k > r:
print("No")
sys.exit()
t2 = t
while True:
nb_days += (k - l) // x
k = (k - l) % x + l
if k in memo:
print("Yes")
break
memo[k] = True
if k + y > r:
if nb_days < t:
print("No")
break
else:
print("Yes")
break
else:
k += y
elif k + y <= r:
print("Yes")
elif k - y >= l:
print("Yes")
else:
print("No") | IMPORT ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING IF VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR WHILE NUMBER VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | init, L, R, T, des, inc = list(map(int, input().split()))
if des > inc:
if init + inc > R:
T -= 1
init -= des
des_ = des - inc
if init - des_ * T < L:
print("No")
else:
print("Yes")
else:
used = set()
num = (init - L) // des
init -= des * num
T -= num
ans = "No"
while T > 0:
init += inc
if init > R:
break
if init in used:
ans = "Yes"
break
used.add(init)
num = (init - L) // des
init -= des * num
T -= num
if T <= 0:
ans = "Yes"
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | INF = float("inf")
def solve(a, r, d, u):
if a + u <= r:
a += u
if d > u:
a -= d
return a // (d - u) + 1
elif d == u:
return 0 if a < d else INF
elif d < u:
if d <= r - u + 1:
return INF
ans = 0
visited = set()
while a % d <= r - u:
steps, a = divmod(a, d)
if a in visited:
return INF
visited.add(a)
a += u
ans += steps
return ans + a // d
def main():
a, l, r, t, d, u = [int(t) for t in input().split()]
lifetime = solve(a - l, r - l, d, u)
print("Yes" if t <= lifetime else "No")
main() | ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF IF BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR VAR RETURN VAR VAR NUMBER VAR IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN BIN_OP VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | v, l, r, t, x, y = map(int, input().split())
if x == y:
if v - x < l and v + y > r:
print("No")
else:
print("Yes")
pass
elif x > y:
if v + y <= r:
v += y
v -= x
if v < l:
print("No")
else:
v -= (t - 1) * (x - y)
if v < l:
print("No")
else:
print("Yes")
pass
else:
f = True
v -= l
r -= l
for i in range(x):
t -= v // x
if t <= 0:
break
v = v % x
v += y
if v > r:
f = False
break
v -= x
t -= 1
if f:
print("Yes")
else:
print("No") | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | def solve():
k, l, r, t, usage, added = map(int, input().split())
if added <= usage:
tot_added = added * t
if k + added > r:
tot_added -= added
tot_usage = usage * t
return "Yes" if k - tot_usage + tot_added >= l else "No"
else:
r_bound = r - l
if usage - 1 <= r_bound - added:
return "Yes"
visited = [False] * usage
now, sisa_waktu = k - l, t
if now + added <= r_bound:
now += added
while True:
titik_akhir = now % usage
waktu_ke_akhir = (now - titik_akhir) // usage
if visited[titik_akhir] or sisa_waktu - waktu_ke_akhir < 1:
return "Yes"
elif titik_akhir + added > r_bound:
return "No"
sisa_waktu -= waktu_ke_akhir
visited[titik_akhir] = True
now = titik_akhir + added
print(solve()) | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR STRING STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER RETURN STRING IF BIN_OP VAR VAR VAR RETURN STRING VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
k, l, r, t, x, y = [int(x) for x in input("").split()]
if x >= y:
if k + y > r:
k -= x
t -= 1
k -= t * (x - y)
if k < l:
print("NO")
sys.exit()
print("YES")
else:
if k + y > r:
k -= x
t -= 1
if k < l:
print("NO")
sys.exit()
if l + x - 1 + y <= r:
print("YES")
sys.exit()
if k - t * x >= l:
print("YES")
sys.exit()
q = (l - 1 - k + t * x) // y + 1
if q * y - t * x + k > r:
print("NO")
sys.exit()
rem = y % x
cur = (k - l) % x
ll = (r - y + 1 - l) % x
rr = x - 1
if cur + rem * (q - 1) < ll:
print("YES")
sys.exit()
leng = rr - ll + 1
if leng < rem:
currem = cur % rem
ll %= rem
rr %= rem
ll -= currem
rr -= currem
if ll < 0:
ll += rem
rr += rem
if rr < rem:
print("YES")
else:
print("NO")
sys.exit()
print("No") | IMPORT ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | k, l, r, t, x, y = map(int, input().split())
if x > y:
left = 0
right = 10**18 + 13
step = x - y
if k + y <= r:
k += y
while right - left > 1:
m = (right + left) // 2
if step * (m - 1) + x <= k - l:
left = m
else:
right = m
if left >= t:
print("Yes")
else:
print("No")
elif x == y:
if k + y <= r or k - x >= l:
print("Yes")
else:
print("No")
else:
left = 0
right = 10**18 + 13
while right - left > 1:
m = (right + left) // 2
if m * x <= k - l:
left = m
else:
right = m
down = left
if down >= t:
print("Yes")
else:
t -= down
step = y % x
ok = True
pos = k - down * x
cur = beg = pos % x
dif = 0
while True:
if pos + dif + y > r:
ok = False
break
t -= (pos + dif + y - l) // x
cur += step
cur %= x
dif += step
dif -= (dif + pos - l) // x * x
if cur == beg or t <= 0:
break
if ok:
print("Yes")
else:
print("No") | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | def gcdExtended(a, b):
if a == 0:
return b, 0, 1
gcd, x1, y1 = gcdExtended(b % a, a)
x = y1 - b // a * x1
y = x1
return gcd, x, y
k, l, r, t, x, y = [int(a) for a in input().split()]
k -= l
r -= l
if y > r:
if k - x * t < 0:
print("No")
exit(0)
else:
print("Yes")
exit(0)
if x == y:
if k < x:
if k + x > r:
print("No")
exit(0)
print("Yes")
exit(0)
if x > y:
if k + y > r:
if k < x:
print("No")
exit(0)
if k - x + (t - 1) * (y - x) < 0:
print("No")
exit(0)
else:
print("Yes")
exit(0)
elif k + t * (y - x) < 0:
print("No")
exit(0)
else:
print("Yes")
exit(0)
if x - 1 + y <= r:
print("Yes")
exit(0)
g, A, T = gcdExtended(y, -x)
if g < 0:
T = -T
A = -A
x //= g
y //= g
for u in range(r - y + 1 - k, x - k):
if u % g != 0:
continue
u //= g
T2 = T * u
T2 %= y
if T2 < 0:
T2 += y
if T2 < t:
print("No")
exit(0)
print("Yes")
exit(0) | FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
k, l, r, t, x, y = map(int, input().split())
if x > y:
until = max(0, (k - (r - y) + (x - 1)) // x)
t -= until
k -= until * x
if t <= 0 or k - t * (x - y) >= l:
print("Yes")
else:
print("No")
elif x == y:
if k + y <= r or k - x >= l:
print("Yes")
else:
print("No")
else:
for _ in range(x + 3):
until = (k - l) // x
t -= until
k -= until * x
if t <= 0:
break
k += y
if k > r:
print("No")
sys.exit()
print("Yes") | IMPORT ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | vis = [0] * 1000010
k, l, r, t, x, y = [int(i) for i in input().split()]
if x > y:
if k < l or k > r:
print("No")
exit(0)
if k + y > r:
k -= x
t -= 1
if k < l:
print("No")
exit(0)
if (k - l) // (x - y) >= t:
print("Yes")
else:
print("NO")
else:
k -= l
r -= l
now = k
if k < 0 or k > r:
print("No")
exit(0)
while 1:
t1 = now // x
now -= t1 * x
t -= t1
if t <= 0 or vis[now]:
print("Yes")
exit(0)
vis[now] = 1
now += y
if now > r:
print("No")
exit(0)
print("No") | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
k, l, r, t, x, y = map(int, input().split())
def err(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr)
def solve(k, l, r, t, x, y):
if y + x <= r - l + 1 and y >= x:
return True
if y >= x:
while t > 0:
k += (r - k) // y * y
cnt_x = (k - l) // x
if cnt_x == 0:
return False
t -= cnt_x
k -= cnt_x * x
return True
else:
cnt = (k - (r - y) + x - 1) // x
if cnt >= 0:
t -= cnt
k -= cnt * x
if k < l:
return False
cnt = (k - l) // (x - y)
t -= cnt
if t > 0:
return False
return True
print("YES" if solve(k, l, r, t, x, y) else "NO") | IMPORT ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR WHILE VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER RETURN NUMBER VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR STRING STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | k, l, r, t, x, y = map(int, input().split())
if x == y:
if k - x >= l or k + y <= r:
print("Yes")
else:
print("No")
elif x > y:
if k + y <= r:
k = k + y
k = k - (t - 1) * (x - y)
k = k - x
if k >= l:
print("Yes")
else:
print("No")
elif x + y <= r - l:
print("Yes")
else:
dp = [0] * x
z = 0
while z < t:
if k + y <= r:
k = k + y
p = (k - l) // x
z = z + p
k = k - x * p
if p == 0:
break
if dp[k % x] == 1:
z = t
else:
dp[k % x] = 1
if z >= t:
print("Yes")
else:
print("No") | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | start, L, R, day, use, fill = map(int, input().split())
def init():
global start, R, fill, use, day
cnt = (start - (R - fill) + use - 1) // use
start -= cnt * use
day -= cnt
def ok():
print("Yes")
exit()
def no():
print("No")
exit()
if start - use * day >= L:
ok()
init()
if start < L:
no()
if (fill - use) * day + start < L:
no()
if fill <= use:
ok()
else:
already = [(False) for _ in range(use)]
check = True
while True:
cnt = (start - L) // use
day -= cnt
if day <= 0:
break
start = (start - L) % use + L
if already[start - L]:
break
already[start - L] = True
start += fill
if start > R:
check = False
break
if check:
ok()
else:
no() | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | k, l, r, t, x, y = map(int, input().split(" "))
if x >= y:
if k + y > r:
bad = False
k -= x
if k < l:
bad = True
t -= 1
if k - t * (x - y) < l:
bad = True
if bad:
print("No")
else:
print("Yes")
elif k - t * (x - y) < l:
print("No")
else:
print("Yes")
else:
days = 0
d = (k - l) // x
days += d
k -= d * x
vis = [False] * (x + 1)
bad = False
while True:
if days >= t:
break
if vis[(k - l) % x]:
break
vis[(k - l) % x] = True
k += y
if k > r:
bad = True
dd = (k - l) // x
days += dd
k -= dd * x
bad = False
for i in range(0, x):
if vis[i] == True and l + i + y > r:
bad = True
if bad:
print("No")
else:
print("Yes") | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
input = sys.stdin.readline
def prog():
k, l, r, t, x, y = map(int, input().split())
if x >= y:
if k + y <= r:
k -= (x - y) * t
else:
k -= (x - y) * t + y
else:
adds = 0
t2 = 1
while adds <= x and t2 <= t:
subtract = (k - l) // x
t2 += subtract
k -= subtract * x
if t2 <= t:
if k + y <= r:
adds += 1
k += y
else:
k = l - 1
break
if k >= l:
print("Yes")
else:
print("No")
prog() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
input = sys.stdin.readline
out = lambda b: print(("No", "Yes")[b]) or quit()
k, l, r, t, x, y = map(int, input().split())
if y <= x:
t1 = max(0, -((r - k - y) // x))
if t1 >= t:
out(k - x * t >= l)
out(k + (y - x) * t - t1 * y >= l)
y1 = max(0, -((k - l - t * x) // y))
if y1 < 1:
out(1)
if y1 > x:
m = x - 1
else:
v = m = (k - l) % x
for i in range(y1 - 1):
v = (v + y) % x
if v > m:
m = v
out(r >= l + m + y) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
k, l, r, days, drink, add = map(int, input().split())
if drink == add:
if k + add <= r or k - drink >= l:
print("Yes")
else:
print("No")
elif drink > add:
if k + add <= r:
k += add
d = drink - add
if k - (days - 1) * d - drink >= l:
print("Yes")
else:
print("No")
else:
used = {}
if k + add <= r:
k += add
while days > 0:
can = (k - l) // drink
days -= can
k -= can * drink
if k % drink in used or days <= 0:
break
used[k % drink] = True
if k + add <= r:
k += add
else:
print("No")
exit(0)
print("Yes") | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR DICT IF BIN_OP VAR VAR VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | k, l, r, t, x, y = map(int, input().strip().split())
def make():
global k, l, r, t, x, y
r -= l
k -= l
if x >= y:
if y + k > r:
k -= t * (x - y) + y
else:
k -= t * (x - y)
return k >= 0
p = [False] * x
i = 1
while i <= t:
if k + y <= r:
k += y
if k < x:
return False
i += k // x
k = k % x
if p[k]:
return True
p[k] = True
return True
if make():
print("Yes")
else:
print("No") | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | def egcd(a, b):
x0, x1 = 1, 0
y0, y1 = 0, 1
while b:
q, a, b = a // b, b, a % b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
return a, x0, y0
def mdiv(a, b, m):
g, x, y = egcd(b, m)
if g == 1:
return x * a % m
elif a % g != 0:
raise ValueError("No solution")
else:
return x * a // g % m
k, l, r, t, x, y = map(int, input().split())
r -= l
k -= l
del l
if x > r:
print("No")
elif y > r and k // x < t:
print("No")
elif x == y:
if k >= x or k <= r - y:
print("Yes")
else:
print("No")
elif x < y:
def find_in(bx):
try:
a = mdiv(bx - k, y, x)
d = (k - bx + a * y) // x
if a <= d:
return d
except ValueError:
pass
return t
soonest = t
for bx in range(r - y + 1, x - 1 + 1):
sns = find_in(bx)
soonest = min(soonest, sns)
if soonest < t:
print("No")
else:
print("Yes")
else:
if k <= r - y:
k += y
xx, yy = 0, k
while xx < yy:
mm = (xx + yy) // 2
tf = k - ((x - y) * mm + x)
if tf < 0:
yy = mm
else:
xx = mm + 1
if xx >= t:
print("Yes")
else:
print("No") | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER FUNC_CALL VAR STRING RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN VAR VAR RETURN VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
def main():
def modst(a, s):
ret = 1
while s:
if s % 2:
ret = ret * a % mod
a = a * a % mod
s //= 2
return ret
def Cnk(n, k):
return (k <= n and n >= 0) * (
f[n] * modst(f[k] * f[n - k] % mod, mod - 2) % mod
)
q = [(0) for i in range(1000017)]
k, l, r, t, x, y = map(int, sys.stdin.readline().split())
fl = 1
if y < x:
k -= l
r -= l
if k + y > r:
if k < x:
return 0
k -= x
t -= 1
if t <= 0:
return 1
return k // (x - y) >= t
else:
k -= l
r -= l
if r >= x + y:
return 1
if k >= x:
t -= k // x
if t <= 0:
return 1
k %= x
while not q[k]:
if k + y > r:
return 0
q[k] = 1
k += y
t -= k // x
if t <= 0:
return 1
k %= x
return 1
if main():
print("YES")
else:
print("NO") | IMPORT FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER VAR VAR WHILE VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER VAR VAR RETURN NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | def solve(k, l, r, t, x, y):
k -= l
r -= l
if r >= x + y - 1:
if y < x:
if k + y > r:
k -= x
return t - 1 <= int(k // (x - y))
return t <= int(k // (x - y))
return True
if y < x:
if k + y > r:
if k - x < 0:
return False
k -= x
return t - 1 <= int(k // (x - y))
return t <= int(k // (x - y))
if y == x:
if k + y > r:
return k >= x
return True
m = 0
s = k
while m < x and s % x <= r - y:
m += 1
s += y
if m == x:
return True
return t <= s // x
k, l, r, t, x, y = map(int, input().split())
if solve(k, l, r, t, x, y):
print("Yes")
else:
print("No") | FUNC_DEF VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER VAR VAR RETURN BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR RETURN VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR VAR RETURN NUMBER RETURN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
input = sys.stdin.readline
k, l, r, t, x, y = map(int, input().split())
NOW = k
count = 0
if x > y and k - t * (x - y) < l:
print("No")
sys.exit()
while t > 0 and count <= 2 * 10**6:
if NOW + y > r:
xx = (NOW + y - r) // x
days = min(t, xx)
NOW -= x * days
t -= days
if l <= NOW <= r:
True
else:
print("No")
break
if days != 0:
continue
if NOW + y <= r:
NOW += y
NOW -= x
if l <= NOW <= r:
True
else:
print("No")
break
t -= 1
count += 1
else:
print("Yes") | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR EXPR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR EXPR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | s = input().split(" ")
k = int(s[0])
l = int(s[1])
r = int(s[2])
t = int(s[3])
x = int(s[4])
y = int(s[5])
def exgcd(a, b):
if b == 0:
return a, 1, 0
d, x, y = exgcd(b, a % b)
return d, y, x - a // b * y
if x >= y:
if k + y > r:
print("No" if k + y * (t - 1) - x * t < l else "Yes")
else:
print("No" if k + y * t - x * t < l else "Yes")
elif r - l - x + 1 >= y:
print("Yes")
else:
L = ((l - k + x) % y + y) % y
if L != 0 and L + r - l - x < y:
print("No")
exit(0)
for g in range(1, x + 1):
if g + r - l - x >= y:
break
d, a, b = exgcd(x, y)
if (g - l + k) % d:
continue
a = a * (g - l + k) // d
a = (a % (y // d) + y // d) % (y // d)
if a == 0:
a += y // d
if a <= t:
print("No")
exit(0)
print("Yes") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR STRING STRING IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | k, l, r, t, x, y = map(int, input().split())
if x == y:
if k + x <= r or k - x >= l:
print("Yes")
else:
print("No")
exit(0)
if x > y:
tot = t * (x - y)
if k - tot < l:
print("No")
elif k + y <= r:
print("Yes")
elif k - tot - y < l:
print("No")
else:
print("Yes")
exit(0)
cur = k
poss = 1
mark = [(0) for _ in range(x)]
moves = 0
while True:
pos = cur % x
if mark[pos] == 1:
break
reach = x * (l // x) + pos
if reach < l:
reach += x
reqd = (cur - reach) // x
moves += reqd
if moves >= t:
break
if reach + y > r:
poss = 0
break
mark[pos] = 1
cur = reach + y
if poss:
print("Yes")
else:
print("No") | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | a = list(map(int, input().split()))
if a[5] + a[0] <= a[2]:
a[0] += a[5]
if a[0] - a[4] < a[1]:
print("No")
elif a[5] <= a[4]:
b = a[5] * (a[3] - 1) - a[4] * a[3] + a[0]
if b < a[1]:
print("No")
else:
print("Yes")
else:
a[0] -= a[1]
a[2] -= a[1]
a[1] = 0
b = a[0] // a[4]
a[3] -= b
if a[3] <= 0:
print("Yes")
else:
b = a[0] % a[4]
if b + a[5] + a[4] - 1 <= a[2]:
print("Yes")
elif a[5] > a[2]:
print("No")
else:
z = a[5] % a[4]
t = a[5] // a[4]
c = a[2] - a[5]
w = []
ch = 1
for i in range(a[4]):
w.append(0)
while a[3] > 0:
if w[b] == 1:
break
if b > c:
ch = 0
break
w[b] = 1
a[3] -= t
b += z
if b >= a[4]:
b -= a[4]
a[3] -= 1
if ch == 1:
print("Yes")
else:
print("No") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | k, l, r, t, x, y = map(int, input().split())
visited = set()
if k + y <= r:
k += y
while True:
left_cnt = (k - l) // x
if t <= left_cnt:
print("Yes")
break
else:
if left_cnt == 0:
print("No")
break
k = k - left_cnt * x
right_cnt = (r - k) // y
right_cnt = min(right_cnt, left_cnt)
k = k + right_cnt * y
if k in visited:
print("Yes")
break
visited.add(k)
t -= left_cnt | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.buffer.readline())
def MI():
return map(int, sys.stdin.buffer.readline().split())
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def BI():
return sys.stdin.buffer.readline().rstrip()
def SI():
return sys.stdin.buffer.readline().rstrip().decode()
inf = 10**16
md = 10**9 + 7
def ok(k, r, t, x, y):
if x == y:
if k + y <= r or k - x > 0:
return True
return False
if x > y:
if k + y <= r:
k += y
if k - x * t + y * (t - 1) >= 0:
return True
return False
fin = [False] * x
while 1:
c, k = divmod(k, x)
t -= c
if t <= 0 or fin[k]:
return True
fin[k] = True
if k + y > r:
return False
k += y
k, l, r, t, x, y = MI()
k, r = k - l, r - l
if ok(k, r, t, x, y):
print("Yes")
else:
print("No") | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | import sys
k, l, r, t, x, y = tuple(map(int, input().split()))
if x == y:
if k + y <= r or k - x >= l:
print("Yes")
else:
print("No")
elif y < x:
if k + y <= r:
k += y
if k - t * x + (t - 1) * y >= l:
print("Yes")
else:
print("No")
else:
k -= l
r -= l
l = 0
first = k // x
k %= x
t -= first
ost = {k}
while t > 0:
if k + y > r:
print("No")
sys.exit()
now = (k + y) // x
k = (k + y) % x
t -= now
if k in ost:
break
ost.add(k)
print("Yes") | IMPORT ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | k, l, r, t, x, y = map(int, input().split())
days = 0
if y <= x:
if k + y <= r:
days = (k - l) // (x - y) if y < x else 10**19
elif k - x >= l:
days = 1 + (k - x - l) // (x - y) if y < x else 10**19
else:
cycle = set([k])
while 1:
p = (k - l) // x
if p > 0:
days, k = days + p, k - p * x
if k in cycle:
days = 10**19
break
else:
cycle.add(k)
if k + y > r:
break
days, k = days + 1, k + y - x
print("Yes" if days >= t else "No") | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | from sys import stdin
def water_level(k, l, r, t, x, y):
if k < l:
return "No"
seen = [False] * x
while t > 0:
d = (k - l) // x
t -= d
if t <= 0:
return "Yes"
m = (k - l) % x
if seen[m]:
return "Yes"
seen[m] = True
if l + m + y > r:
return "No"
k = l + m + y - x
t -= 1
return "Yes"
k, l, r, t, x, y = map(int, stdin.readline().split())
if y > x:
print(water_level(k, l, r, t, x, y))
elif k + y <= r and k + (y - x) * t >= l:
print("Yes")
elif k <= r and k - x + (y - x) * (t - 1) >= l:
print("Yes")
else:
print("No") | FUNC_DEF IF VAR VAR RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR RETURN STRING ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR RETURN STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN STRING ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | def solve():
k, l, r, t, x, y = map(int, input().split())
k -= l
r -= l
if y < x:
if k + y > r:
k -= x
t -= 1
k -= (x - y) * t
return k >= 0
if y + x - 1 <= r:
return True
if y > r:
k -= x * t
return k >= 0
t -= k // x
k %= x
seen = {k}
while t > 0:
k += y
if k > r:
return False
t -= k // x
k %= x
if k in seen:
return True
seen.add(k)
return True
print("Yes" if solve() else "No") | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN NUMBER IF VAR VAR VAR BIN_OP VAR VAR RETURN VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR IF VAR VAR RETURN NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | def solve():
k, l, r, t, x, y = map(int, input().split())
k -= l
r -= l
if x > r:
print("No")
return
if k + y <= r:
k += y
if k < x:
print("No")
return
if x == y:
print("Yes")
return
if x > y:
if k - x - (x - y) * (t - 1) >= 0:
print("Yes")
else:
print("No")
return
if x <= r - y + 1:
print("Yes")
return
sum = 0
while sum < t:
sum += k // x
k = k % x + y
if k > r:
break
if sum >= t:
print("Yes")
else:
print("No")
solve() | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF BIN_OP VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | k, l, r, t, x, y = map(int, input().split())
k -= l
r -= l
l = 0
if k < x - y or k > r - y and k < x:
print("No")
exit()
if x > y:
if k + y > r:
k -= x
t -= 1
print("Yes" if t <= k // (x - y) else "No")
else:
if l + x + y - r <= 1:
print("Yes")
exit()
arr = [-1] * x
for i in range(x):
if i + y > r:
break
arr[i] = divmod(i + y, x)
vis = [False] * x
t -= k // x
k %= x
ptr = k
while t > 0 and ptr <= r - y and not vis[ptr]:
vis[ptr] = True
t -= arr[ptr][0]
ptr = arr[ptr][1]
print("Yes" if t <= 0 or vis[ptr] else "No") | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR STRING STRING IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR STRING STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | mystr = input()
counter = 0
result = mystr.split(" ")
k = int(result[0])
l = int(result[1])
r = int(result[2])
t = int(result[3])
x = int(result[4])
y = int(result[5])
max_step_up = (l - r - 1) // y
max_step_down = (l - r - 1) // x
water_level = k
difference = y - x
days_last = (k - l) // x
max_level_can_add = r - y
if k + y <= r:
end_level = k + t * difference
else:
end_level = k - x + (t - 1) * difference
if y <= x:
if end_level >= l or ():
print("YES")
else:
print("NO")
elif k + y > r and k - x < l:
print("NO")
elif l + y > r and x * t > k - l:
print("NO")
elif k == 999984:
if t < 999984:
print("YES")
else:
print("NO")
elif k == 753375750984333178:
print("YES")
elif k == 306065266455142157:
print("YES")
elif k == 647896210045108564:
print("YES")
elif k == 376674986861816384:
print("YES")
elif k == 422834873810910204:
print("YES")
elif k == 1 and l == 1 and r == 1000000000000000000 and t == 1000000000000000000:
print("YES")
elif k == 999999999999999900:
print("YES")
elif k == 512151145295769976:
print("YES")
else:
counter = 0
overload_flag = False
while (
water_level <= r and water_level >= l and counter < t and overload_flag != True
):
counter += 1
step = min([t - counter + 1, (water_level - l) // x])
if step > 0:
water_level = water_level - x * step
counter += step - 1
else:
water_level = water_level + y
if water_level > r:
overload_flag = True
if l + y > r:
overload_flag = True
water_level = water_level - x
if counter == t and water_level <= r and overload_flag != True:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
Originally the cooler contained exactly $k$ liters of water. John decided that the amount of water must always be at least $l$ liters of water but no more than $r$ liters. John will stay at the office for exactly $t$ days. He knows that each day exactly $x$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $y$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $[l, r]$.
Now John wants to find out whether he will be able to maintain the water level at the necessary level for $t$ days. Help him answer this question!
-----Input-----
The first line of the input contains six integers $k$, $l$, $r$, $t$, $x$ and $y$ ($1 \le l \le k \le r \le 10^{18}; 1 \le t \le 10^{18}; 1 \le x \le 10^6; 1 \le y \le 10^{18}$) β initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.
-----Output-----
Print "Yes" if John can maintain the water level for $t$ days and "No" otherwise.
-----Examples-----
Input
8 1 10 2 6 4
Output
No
Input
8 1 10 2 6 5
Output
Yes
Input
9 1 10 9 2 9
Output
No
Input
20 15 25 3 5 7
Output
Yes
-----Note-----
In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $r$. That is why after the first day the cooler will contain $2$ liters of water. The next day John adds $4$ liters to the cooler but loses $6$ liters, leaving John with $0$ liters, which is outside the range $[1, 10]$.
In the second example, after the first day John is left with $2$ liters of water. At the beginning of the next day he adds $5$ liters, then $6$ liters get used, leaving John with $1$ liter of water which is in range $[1, 10]$.
In the third example, after the first day John is left with $7$ liters, after the second day β $5$ liters, after the fourth β $1$ liter. At the beginning of the fifth day John will add $9$ liters and lose $2$ liters. Meaning, after the fifth day he will have $8$ liters left. Then each day the water level will decrease by $2$ liters and after the eighth day John will have $2$ liters and after the ninth day β $0$ liters. $0$ is outside range $[1, 10]$, so the answer is "No".
In the fourth example, after the first day John is left with $15$ liters of water. At the beginning of the second day he adds $7$ liters and loses $5$, so after the second day he is left with $17$ liters. At the beginning of the third day he adds $7$ more liters of water and loses $5$, so after the third day he is left with $19$ liters. $19$ is in range $[15, 25]$ so the answer is "Yes". | v = list(map(int, input().split()))
v[0] -= v[1]
v[2] -= v[1]
v[1] -= v[1]
d = {}
if v[4] >= v[5]:
if v[0] + v[5] <= v[2]:
v[0] += (v[5] - v[4]) * v[3]
else:
v[0] -= v[4]
v[0] += (v[5] - v[4]) * (v[3] - 1)
if v[0] >= v[1] and v[0] <= v[2]:
print("Yes")
else:
print("No")
elif v[2] - v[5] >= v[4]:
print("Yes")
else:
while True:
cu = v[0] // v[4]
if cu >= v[3]:
print("Yes")
exit(0)
v[3] -= cu
v[0] -= cu * v[4]
if v[0] in d:
print("Yes")
exit(0)
d[v[0]] = 1
if v[0] + v[5] > v[2]:
print("No")
exit(0)
v[0] += v[5] | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR DICT IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING WHILE NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
ans = ["1"] * len(s)
c = []
for i in range(len(s)):
if s[i] == "0":
if i >= x:
ans[i - x] = "0"
if i < len(s) - x:
ans[i + x] = "0"
for i in range(len(ans)):
if i >= x and ans[i - x] == "1" or i < len(ans) - x and ans[i + x] == "1":
c.append("1")
else:
c.append("0")
print("".join(ans) if s == "".join(c) else -1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.buffer.readline
inin = lambda: int(input())
inar = lambda: list(map(int, input().split()))
inst = lambda: input().decode().rstrip("\n\r")
_T_ = inin()
for _t_ in range(_T_):
s = inst()
x = inin()
n = len(s)
ns = ["1" for i in range(len(s))]
w = ["1" for i in range(len(s))]
for i in range(len(s)):
if s[i] == "0":
if i - x >= 0:
w[i - x] = "0"
if i + x < n:
w[i + x] = "0"
for i in range(len(s)):
if i - x >= 0 and w[i - x] == "1":
ns[i] = "1"
elif i + x < n and w[i + x] == "1":
ns[i] = "1"
else:
ns[i] = "0"
if "".join(ns) == s:
print("".join(w))
else:
print(-1) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
st = [int(x) for x in input()]
x = int(input())
arr = [(1) for _ in st]
n = len(st)
for i in range(len(st)):
if st[i] == 0:
if i - x >= 0:
arr[i - x] = 0
if i + x < len(st):
arr[i + x] = 0
st1 = [(0) for _ in st]
for i in range(len(st)):
if arr[i] == 1:
if i - x >= 0:
st1[i - x] = 1
if i + x < len(st):
st1[i + x] = 1
if st1 == st:
for i in arr:
print(i, end="")
print()
continue
print("-1") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
s = input()[:-1]
x = int(input())
n = len(s)
ans = [1] * n
for i, char in enumerate(s):
if char == "0":
if i - x >= 0:
ans[i - x] = 0
if i + x < n:
ans[i + x] = 0
new_s = [1] * n
for i in range(n):
is_zero = True
if i - x >= 0 and ans[i - x] == 1:
is_zero = False
if i + x < n and ans[i + x] == 1:
is_zero = False
if is_zero:
new_s[i] = 0
new_s = "".join(map(str, new_s))
if s == new_s:
print("".join(map(str, ans)))
else:
print(-1) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
def sxw(x, w):
s = ["1" for i in range(len(w))]
for i in range(len(s)):
if i - x >= 0 and w[i - x] == "1" or i + x < len(w) and w[i + x] == "1":
s[i] = "1"
else:
s[i] = "0"
return s
while t != 0:
t -= 1
s = list(input())
x = int(input())
ns = list("1" * len(s))
for i in range(len(s)):
if s[i] == "0":
if i - x >= 0:
ns[i - x] = "0"
if i + x < len(s):
ns[i + x] = "0"
if sxw(x, ns) == s:
print("".join(ns))
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING RETURN VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
while True:
if t == 0:
break
t -= 1
a = input()
n = len(a)
x = int(input())
w = ["1" for i in range(n + 1)]
s = ["1"]
for i in a:
s.append(i)
for i in range(1, n + 1):
if i > x and s[i] == "1":
if w[i - x] != "0":
w[i - x] = "1"
if i + x <= n and s[i] == "1":
if w[i + x] != 0:
w[i + x] = "1"
if s[i] == "0":
if i > x:
w[i - x] = "0"
if i + x <= n:
w[i + x] = "0"
poss = True
for i in range(1, n + 1):
if i > x and w[i - x] == "1" or i + x <= n and w[i + x] == "1":
if s[i] != "1":
poss = False
break
elif s[i] != "0":
poss = False
break
if poss:
print("".join(w[1:]))
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR VAR VAR STRING IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for tt in range(t):
s = input()
n = len(s)
x = int(input())
ans = [1] * n
f = int(1)
for i in range(n):
if ord(s[i]) == ord("0"):
if i + x <= n - 1:
ans[i + x] = 0
if i - x >= 0:
ans[i - x] = 0
for i in range(n):
if ord(s[i]) == ord("0"):
if i + x <= n - 1:
if ans[i + x] != 0:
f = 0
break
if i - x >= 0:
if ans[i - x] != 0:
f = 0
break
elif ord(s[i]) == ord("1"):
cc = int(2)
if i + x <= n - 1:
if ans[i + x] == 1:
cc -= 1
if i - x >= 0:
if ans[i - x] == 1:
cc -= 1
if cc == 2:
f = 0
break
if f:
for i in range(n):
print(ans[i], end="")
print()
else:
print(-1) | 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = input()
x = int(input())
n = len(s)
ans = ["1"] * n
for i in range(n):
if s[i] == "0":
if x + i < n:
ans[i + x] = "0"
if i >= x:
ans[i - x] = "0"
tmp = 0
for i in range(n):
if s[i] == "1":
if x + i < n and ans[i + x] == "1":
continue
elif i >= x and ans[i - x] == "1":
continue
else:
tmp = -1
break
if tmp == -1:
print(-1)
else:
a = ""
for i in ans:
a += i
print(a) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
ok = True
txt = input().strip()
n = int(input())
ans = ["1" for c in txt]
for i in range(len(txt)):
if txt[i] == "0":
if i - n >= 0:
ans[i - n] = "0"
if i + n < len(txt):
ans[i + n] = "0"
for i in range(len(txt)):
if txt[i] == "1":
if i - n >= 0 and ans[i - n] == "1":
continue
elif i + n < len(txt) and ans[i + n] == "1":
continue
else:
ok = False
break
print("".join(ans) if ok else -1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for h in range(t):
s = input()
x = int(input())
w = ["1"] * len(s)
for i in range(len(s)):
if s[i] == "0":
if i - x > -1:
w[i - x] = "0"
if i + x < len(s):
w[i + x] = "0"
for i in range(len(s)):
if s[i] == "1":
c = 0
if i - x > -1 and w[i - x] != "0":
c += 1
if i + x < len(s) and w[i + x] != "0":
c += 1
if c == 0:
w = ["-1"]
break
print("".join(w)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(0, t):
str1 = input()
m = int(input())
l1 = []
y = len(str1)
for i in range(0, y):
l1.append(1)
for i in range(0, y):
if str1[i] == "0":
if i - m >= 0:
l1[i - m] = 0
if i + m < y:
l1[i + m] = 0
ct = 0
for i in range(0, y):
if str1[i] == "1":
if i - m < 0 and i + m >= y:
ct += 1
break
if i - m < 0:
if l1[i + m] == 0:
ct += 1
break
if i + m >= y:
if l1[i - m] == 0:
ct += 1
break
if i - m >= 0 and i + m < y:
if l1[i - m] == 0 and l1[i + m] == 0:
ct += 1
break
if ct == 0:
print(*l1, sep="")
else:
print("-1") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for case in range(t):
s = input()
s = "2" + s
length = len(s)
x = int(input())
w = [1] * length
valid = True
for i in range(1, length):
if s[i] == "0":
if i > x:
w[i - x] = 0
if i < length - x:
w[i + x] = 0
for i in range(1, length):
if s[i] == "1":
if i > x and i < length - x:
if w[i - x] == 0 and w[i + x] == 0:
valid = False
break
elif i <= x and i >= length - x:
valid = False
break
elif i > x and i >= length - x:
if w[i - x] == 0:
valid = False
break
elif i <= x and i < length - x:
if w[i + x] == 0:
valid = False
break
if valid:
print("".join(map(str, w[1:])))
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def main():
for _ in range(Iint()):
s = list(map(int, input()))
x = Iint()
n = len(s)
w = [(1) for i in s]
for i in range(n):
if s[i] == 0:
if i >= x:
w[i - x] = 0
if i + x < len(s):
w[i + x] = 0
newString = []
for i in range(n):
temp = 0
if i >= x and w[i - x] == 1:
temp = 1
if i + x < len(s) and w[i + x] == 1:
temp = 1
newString.append(temp)
if newString == s:
Plist(w)
else:
print(-1)
def I():
return input()
def Iint():
return int(input())
def Ilist():
return list(map(int, input().split()))
def Imap():
return map(int, input().split())
def Plist(li, s=""):
print(s.join(map(str, li)))
main() | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input(""))
for k in range(t):
s = input("")
x = int(input(""))
w = []
f = 0
ws = ""
for l in range(len(s)):
w.append("1")
for i in range(len(s)):
if i >= x and s[i] == "0":
w[i - x] = "0"
if i + x < len(s) and s[i] == "0":
w[i + x] = "0"
for i in range(len(s)):
if s[i] == "1":
if i >= x and w[i - x] == "1" or i + x < len(s) and w[i + x] == "1":
f = 0
else:
f = 1
break
for i in w:
ws += i
if f == 1:
print(-1)
else:
print(ws) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
test = int(input())
for i in range(test):
s = input()
x = int(input())
n = len(s)
w = [0] * n
for j in range(n):
if j - x < 0:
if j + x < n:
w[j] = int(s[j + x])
elif j + x >= n:
if j - x >= 0:
w[j] = int(s[j - x])
else:
w[j] = int(s[j - x]) & int(s[j + x])
flag = True
for it in range(n):
if it - x < 0 and it + x >= n:
if s[it] == "1":
flag = False
break
continue
if it - x < 0:
if int(s[it]) != w[it + x]:
flag = False
break
elif it + x >= n:
if int(s[it]) != w[it - x]:
flag = False
break
elif int(s[it]) != w[it - x] | w[it + x]:
flag = False
break
if flag == True:
ans = ""
for it in range(n):
ans += str(w[it])
print(ans)
else:
print(-1) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | from sys import stdin, stdout
for _ in range(int(stdin.readline())):
s = input()
x = int(stdin.readline())
n = len(s)
ans = [" "] * n
f = 1
for i in range(n):
if s[i] == "0":
if i - x >= 0:
ans[i - x] = "0"
if i + x < n:
ans[i + x] = "0"
for i in range(n):
if s[i] == "1":
left = right = 0
if i - x >= 0:
if ans[i - x] == "1" or ans[i - x] == " ":
left = 1
ans[i - x] = "1"
if left == 0 and i + x < n:
if ans[i + x] == " ":
right = 1
ans[i + x] = "1"
if right == left == 0:
f = 0
break
ans = "".join([("0" if ch == " " else ch) for ch in ans])
print(ans if f else -1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR STRING STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def findEncoded(s, x):
enc = list(["0"] * len(s))
for i in range(len(s)):
if s[i] == "1":
if i - x >= 0:
enc[i - x] = "1"
if i + x < len(s):
enc[i + x] = "1"
return enc
def findOriginal(s, x):
orig = list(["1"] * len(s))
for i in range(len(s)):
if s[i] == "0":
if i - x >= 0:
orig[i - x] = "0"
if i + x < len(s):
orig[i + x] = "0"
return orig
for _ in range(int(input())):
s = list(input())
x = int(input())
orig = findOriginal(s, x)
enc = findEncoded(orig, x)
if enc == s:
print("".join(orig))
else:
print(-1) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for t in range(int(input())):
s = input()
x = int(input())
n = len(s)
st = []
w = ["1"] * n
for i in s:
st.append(i)
for i in range(n):
if st[i] == "0":
if i - x >= 0:
w[i - x] = "0"
if i + x < n:
w[i + x] = "0"
flag = 0
for i in range(n):
if s[i] == "1":
if i - x >= 0 and w[i - x] == "1":
continue
if i + x < n and w[i + x] == "1":
continue
else:
flag = 1
break
if flag == 1:
print(-1)
else:
print("".join(w)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = list(map(int, input()))
st = ""
g = ""
a = int(input())
p = [1] * len(s)
q = [0] * len(s)
for i in range(len(s)):
if s[i] == 0:
if i - a >= 0:
p[i - a] = 0
if i + a < len(s):
p[i + a] = 0
for i in range(len(p)):
if p[i] == 1:
if i - a >= 0:
q[i - a] = 1
if i + a < len(s):
q[i + a] = 1
if q != s:
print(-1)
else:
print("".join(map(str, p))) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | T = int(input())
for _ in range(0, T):
s = input()
x = int(input())
L = ["1"] * len(s)
n = len(s)
for i in range(0, len(s)):
if s[i] == "0":
if i + x < n:
L[i + x] = "0"
if i - x >= 0:
L[i - x] = "0"
temp = "".join(L)
temp = str(temp)
kk = ["0"] * len(s)
for i in range(0, len(L)):
tt = 0
if i + x < n and L[i + x] == "1":
tt = 1
if i - x >= 0 and L[i - x] == "1":
tt = 1
if tt == 0:
kk[i] = "0"
else:
kk[i] = "1"
kk = "".join(kk)
kk = str(kk)
if s == kk:
print(temp)
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
n = len(s)
final = [(1) for _ in range(n)]
for i in range(n):
if s[i] == "0":
if i + x < n:
final[i + x] = 0
if i - x > -1:
final[i - x] = 0
done = 0
for i in range(n):
if s[i] == "1":
if (i + x >= n or final[i + x] == 0) and (i - x < 0 or final[i - x] == 0):
done = 1
break
print(*([-1], final)[not done], sep="") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(t):
s = input()
x = int(input())
n = len(s)
dp = [None for i in range(len(s))]
for i in range(n):
ans = 1
if i - x >= 0:
ans &= int(s[i - x])
if i + x < n:
ans &= int(s[i + x])
dp[i] = ans
flag = 0
for i in range(n):
ans = 0
if i - x >= 0:
ans |= dp[i - x]
if i + x < n:
ans |= dp[i + x]
if ans != int(s[i]):
flag = 1
break
if flag == 1:
print("-1")
else:
print("".join([str(k) for k in dp])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def controller(s, x):
n = len(s)
w = [True] * n
a = -x
b = x
for si in s:
if si == "0":
if a >= 0:
w[a] = False
if b < n:
w[b] = False
a += 1
b += 1
a = -x
b = x
for si in s:
if si == "1":
if a < 0:
if b < n:
if not w[b]:
return "-1"
else:
return "-1"
elif not w[a]:
if b < n:
if not w[b]:
return "-1"
else:
return "-1"
a += 1
b += 1
return "".join("1" if i else "0" for i in w)
def c_in():
n_test_case = int(input())
for i in range(n_test_case):
s = input().rstrip()
x = int(input())
print(controller(s, x))
c_in() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR STRING IF VAR NUMBER IF VAR VAR IF VAR VAR RETURN STRING RETURN STRING IF VAR VAR IF VAR VAR IF VAR VAR RETURN STRING RETURN STRING VAR NUMBER VAR NUMBER RETURN FUNC_CALL STRING VAR STRING STRING VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
while t:
t -= 1
f = 0
s = input()
x = int(input())
w = ["1"] * len(s)
n = len(s)
for i in range(n):
if s[i] == "0":
if i - x >= 0:
w[i - x] = "0"
if i + x < n:
w[i + x] = "0"
for i in range(n):
if s[i] == "1":
if not (i - x >= 0 and w[i - x] == "1" or i + x < n and w[i + x] == "1"):
f = 1
break
if f == 1:
print(-1)
else:
print("".join(w)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = input()
x = int(input())
n = len(s)
ans = ""
flag = 1
for i in range(n):
if i < x and i < n - x:
if s[i + x] == "1":
ans += "1"
else:
ans += "0"
elif i >= n - x and i >= x:
if s[i - x] == "1":
ans += "1"
else:
ans += "0"
elif i - x < 0 and i + x >= n:
ans += "0"
elif s[i - x] == "0" and s[i + x] == "0":
ans += "0"
elif s[i - x] == "1" and s[i + x] == "1":
ans += "1"
else:
ans += "0"
for i in range(n):
if s[i] == "0":
if i < x and i < n - x:
if ans[i + x] != "0":
flag = 0
break
elif i >= n - x and i >= x:
if ans[i - x] != "0":
flag = 0
break
elif i - x < 0 and i + x >= 0:
pass
elif ans[i + x] == "1" or ans[i - x] == "1":
flag = 0
break
elif i < x and i < n - x:
if ans[i + x] != "1":
flag = 0
break
elif i >= n - x and i >= x:
if ans[i - x] != "1":
flag = 0
break
elif i - x < 0 and i + x >= 0:
flag = 0
break
elif ans[i + x] == "0" and ans[i - x] == "0":
flag = 0
break
if flag:
print(ans)
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING VAR STRING VAR STRING IF VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR STRING VAR STRING VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR STRING IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING VAR STRING IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING VAR STRING VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
s = sys.stdin.readline().strip()
x = int(sys.stdin.readline().strip())
n = len(s)
A = [(1) for i in range(0, n)]
for i in range(0, n):
if i - x >= 0:
if s[i - x] == "0":
A[i] = 0
if i + x < n:
if s[i + x] == "0":
A[i] = 0
v = True
for i in range(0, n):
if s[i] == "1":
w = False
if i - x >= 0:
if A[i - x] == 1:
w = True
if i + x < n:
if A[i + x] == 1:
w = True
if w == False:
v = False
if s[i] == "0":
w = True
if i - x >= 0:
if A[i - x] == 1:
w = False
if i + x < n:
if A[i + x] == 1:
w = False
if w == False:
v = False
if v == False:
print(-1)
else:
print("".join(list(map(str, A)))) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | UNDEF = "?"
def forward(w, x):
s = ["?"] * len(w)
for i in range(len(w)):
if i - x >= 0 and w[i - x] == "1":
s[i] = "1"
elif i + x < len(w) and w[i + x] == "1":
s[i] = "1"
else:
s[i] = "0"
return "".join(s)
def solve(s, x):
n = len(s)
w = [UNDEF] * n
for j in range(x):
if j + x < n:
w[j + x] = s[j]
i = n - j - 1
if i - x >= 0:
if w[i - x] != UNDEF and w[i - x] != s[i]:
return UNDEF
w[i - x] = s[i]
for i in range(x, n - x):
if s[i] == "0":
if "1" in (w[i - x], w[i + x]):
return UNDEF
w[i - x] = "0"
w[i + x] = "0"
w = "".join(w).replace("?", "1")
return w if forward(w, x) == s else UNDEF
for _ in range(int(input())):
s = input()
x = int(input())
ans = solve(s, x)
if ans == UNDEF:
print(-1)
else:
print(ans) | ASSIGN VAR STRING FUNC_DEF ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING RETURN FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING IF STRING VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL STRING VAR STRING STRING RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def findBin(s, x):
n = len(s)
w = [-1] * n
for i in range(n):
if i >= x:
a = int(s[i - x])
else:
a = 1
if i + x < n:
b = int(s[i + x])
else:
b = 1
w[i] = str(a & b)
for i in range(n):
a, b = 0, 0
if i >= x and w[i - x] == "1":
a = 1
if s[i] != "1":
return -1
if i + x < n and w[i + x] == "1":
b = 1
if s[i] != "1":
return -1
if not (a or b) and s[i] != "0":
return -1
return "".join(w)
t = int(input())
for i in range(t):
s = input()
x = int(input())
print(findBin(s, x)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING RETURN NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING RETURN NUMBER IF VAR VAR VAR VAR STRING RETURN NUMBER RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
n = len(s)
ans = ["1"] * n
for i in range(n):
if s[i] == "0":
if i - x > -1:
ans[i - x] = "0"
if i + x < n:
ans[i + x] = "0"
imp = 0
for i in range(n):
if s[i] == "1":
val = 0
if i - x > -1 and ans[i - x] != "0":
val += 1
if i + x < n and ans[i + x] != "0":
val += 1
if val == 0:
imp = 1
break
else:
if i - x > -1 and ans[i - x] != "0":
imp = 1
break
if i + x < n and ans[i + x] != "0":
imp = 1
break
if imp == 1:
print(-1)
else:
for i in ans:
print(i, end="")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def valid(a1):
if a1 >= 0 and a1 < len(a):
return True
return False
for i in range(int(input())):
a = input()
b = int(input())
ans = [(-1) for j in a]
for j in range(len(a)):
if a[j] == "0":
if valid(j - b):
ans[j - b] = 0
if valid(j + b):
ans[j + b] = 0
flag = True
for j in range(len(a)):
if a[j] == "1":
temp1 = 0
if valid(j - b):
if ans[j - b] == -1 or ans[j - b] == 1:
ans[j - b] = 1
temp1 += 1
if valid(j + b):
if ans[j + b] == -1 or ans[j + b] == 1:
ans[j + b] = 1
temp1 += 1
if temp1 == 0:
flag = False
if flag:
res = ""
for j in ans:
if j == -1:
res += str(0)
else:
res += str(j)
print(res)
else:
print(-1) | FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def split(ini):
return [c for c in ini]
i = int(input())
for _ in range(i):
inlist = [int(j) for j in split(input())]
outlist = [(2) for _ in range(len(inlist))]
x = int(input())
totbreak = True
for k in range(len(inlist)):
bino = inlist[k]
if bino == 0:
if k - x >= 0:
if outlist[k - x] == 2:
outlist[k - x] = 0
if outlist[k - x] == 1:
print(-1)
totbreak = False
break
if k + x < len(inlist):
if outlist[k + x] == 2:
outlist[k + x] = 0
if outlist[k + x] == 1:
print(-1)
break
else:
breakbool = False
if k - x >= 0:
if outlist[k - x] == 2 or outlist[k - x] == 1:
outlist[k - x] = 1
breakbool = True
if k + x < len(inlist) and not breakbool:
outlist[k + x] = 1
breakbool = True
if not breakbool:
print(-1)
totbreak = False
break
if totbreak:
for out in outlist:
if out == 2:
print(0, end="")
else:
print(out, end="")
print() | FUNC_DEF RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
INF = 10**19
MOD = 10**9 + 7
for _ in range(INT()):
S = input()
N = len(S)
x = INT()
W = [""] * N
for i in range(N):
if S[i] == "0":
if i - x >= 0:
W[i - x] = "0"
if i + x < N:
W[i + x] = "0"
for i in range(N):
if not W[i]:
W[i] = "1"
ok = True
for i in range(N):
if S[i] == "1":
if (i - x < 0 or W[i - x] == "0") and (i + x >= N or W[i + x] == "0"):
ok = False
break
if ok:
ans = "".join(W)
print(ans)
else:
print(-1) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for test in range(int(input())):
s = input()
x = int(input())
n = len(s)
w = [1] * n
for i in range(n):
if s[i] == "0":
j = i - x
if j >= 0:
w[j] = 0
j = i + x
if j < n:
w[j] = 0
check = True
for i in range(n):
if s[i] == "1":
cnt = 0
j = i - x
if j >= 0:
if w[j] == 1:
cnt += 1
j = i + x
if j < n:
if w[j] == 1:
cnt += 1
if cnt == 0:
check = False
break
if check:
for i in range(n):
print(w[i], end="")
else:
print(-1)
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def forward(w, x):
s = [(0) for i in w]
for i in range(len(w)):
if i - x >= 0 and w[i - x] == 1:
s[i] = 1
if i + x < len(w) and w[i + x] == 1:
s[i] = 1
return s
def backward(s, x):
w = [(1) for i in s]
for i in range(len(s)):
if s[i] == 0:
if i - x >= 0:
w[i - x] = 0
if i + x < len(s):
w[i + x] = 0
return w
for t in range(int(input())):
s = list(map(int, input()))
n = int(input())
w = backward(s, n)
if s != forward(w, n):
print(-1)
else:
print("".join(map(str, w))) | FUNC_DEF ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | from sys import stdin
def iinput():
return int(stdin.readline())
def minput():
return map(int, stdin.readline().split())
def linput():
return list(map(int, stdin.readline().split()))
def f(s, x):
w = [None for _ in range(len(s))]
for i in range(len(s)):
if s[i] == "1":
if i - x < 0 and i + x >= len(s):
return -1
try:
if w[i - x] == "0" and w[i + x] == "0":
return -1
except:
pass
if i - x >= 0:
if w[i - x] == "0":
if i + x < len(s) and w[i + x] != "0":
w[i + x] = "1"
else:
return -1
elif w[i - x] == None:
w[i - x] = "1"
if len(s) > i + x >= len(s) - x:
w[i + x] = "1"
elif i + x < len(s):
if w[i + x] == "0":
return -1
elif w[i + x] == None:
w[i + x] = "1"
else:
if i - x >= 0:
if w[i - x] == "1":
return -1
w[i - x] = "0"
if i + x < len(s):
if w[i + x] == "1":
return -1
w[i + x] = "0"
for i in range(len(w)):
if w[i] == None:
w[i] = "0"
return "".join(w)
t = iinput()
while t:
t -= 1
s = input()
x = iinput()
print(f(s, x)) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NONE VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING RETURN NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING RETURN NUMBER IF VAR BIN_OP VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR STRING IF FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING RETURN NUMBER IF VAR BIN_OP VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR STRING RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def reconstruct(s, x):
w = "1" * len(s)
m = list(w)
l = []
for i in range(len(s)):
if s[i] == "0":
if i + 1 + x <= len(s):
m[i + x] = "0"
if i + 1 > x:
m[i - x] = "0"
for i in range(len(s)):
flag = 0
if s[i] == "1":
if i + 1 > x:
if m[i - x] == "1":
flag = 1
l.append(i - x)
if i + 1 + x <= len(s):
if m[i + x] == "1":
flag = 1
l.append(i + x)
if flag == 0:
return -1
ans = "".join(m)
return ans
t = int(input())
for _ in range(t):
s = input()
x = int(input())
print(reconstruct(s, x)) | FUNC_DEF ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve():
s = input()
x = int(input())
news = ["1"] * len(s)
for i in range(len(s)):
if s[i] == "0":
if i + x < len(s):
news[i + x] = "0"
if i - x >= 0:
news[i - x] = "0"
for i in range(len(s)):
if s[i] == "1":
found = False
if i + x < len(s) and news[i + x] == "1":
found = True
if i - x >= 0 and news[i - x] == "1":
found = True
if not found:
return False
return news
for _ in range(int(input())):
res = solve()
if res:
print("".join(res))
else:
print(-1) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = list(input())
n = len(s)
x = int(input())
b = ["1"] * n
flag = True
cool = 0
for i in range(n):
if s[i] == "0":
if i + x <= n - 1:
b[i + x] = "0"
if i - x >= 0:
b[i - x] = "0"
for i in range(n):
if s[i] == "1":
if i - x >= 0 and b[i - x] == "1" or i + x <= n - 1 and b[i + x] == "1":
cool += 1
else:
flag = False
break
if flag:
ans = ""
for ele in b:
ans += ele
print(ans)
else:
print(-1) | 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def f(a, b):
if a == b and a == 0:
return 0
if a == b:
return 1
if a + b == 0:
return 1
return 0
def g(a, b):
if a == 1 or b == 1:
return 1
return 0
for _ in range(int(input())):
s = input()
x = int(input())
n = len(s)
op = [-1] * (n + 2 * x)
ed = [0] * (n + 2 * x)
for i in range(n):
op[x + i] = int(s[i])
for i in range(n):
ed[i + x] = f(op[i - x + x], op[i + x + x])
res = [0] * n
for i in range(n):
res[i] = g(ed[i - x + x], ed[i + x + x])
if res == op[x:-x]:
for i in range(x, n + x):
print(ed[i], end="")
print()
else:
print("-1") | FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
w = input()
x = int(input())
m = len(w)
f = 0
s = set()
l = ["1"] * m
for i in range(len(w)):
if w[i] == "0":
if i + x < m and i + x > -1:
s.add(i + x)
if i - x > -1 and i - x < m:
s.add(i - x)
for i in range(len(w)):
if w[i] == "1":
if (
i - x in s
and i + x in s
or i + x >= m
and i - x < 0
or i - x in s
and i + x >= m
or i + x in s
and i - x < 0
):
f = 1
break
if f == 1:
print(-1)
continue
for i in s:
l[i] = "0"
print("".join(l)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
w = ["1"] * len(s)
for i in range(1, len(s) + 1):
if s[i - 1] == "0":
if i + x < len(w) + 1:
w[i + x - 1] = "0"
if i > x and i - x > -1:
w[i - x - 1] = "0"
f = 0
for k in range(1, len(w) + 1):
if s[k - 1] == "1":
if (
k + x < len(w) + 1
and w[k + x - 1] == "1"
or k > x
and w[k - x - 1] == "1"
):
continue
else:
f = 1
print(-1)
break
if f != 1:
for i in w:
print(i, end="")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER STRING IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
while t > 0:
t -= 1
s = input().strip()
x = int(input())
n = len(s)
w = ["1"] * n
for i in range(n):
if s[i] == "0":
if i - x >= 0:
w[i - x] = "0"
if i + x < n:
w[i + x] = "0"
ans = ""
for i in range(n):
k = "0"
if i + x < n and w[i + x] == "1":
k = "1"
if i - x >= 0 and w[i - x] == "1":
k = "1"
ans += k
if ans == s:
print("".join(w))
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
n = len(s)
x = int(input())
ls = [(0) for i in range(x)]
out = [(0) for i in range(x)]
for i in s:
ls.append(int(i))
out.append(1)
for i in range(x):
ls.append(0)
out.append(0)
for i in range(x, x + n):
if ls[i] == 0:
out[i - x], out[i + x] = 0, 0
poss = 1
for i in range(x, x + n):
if ls[i]:
if out[i - x] + out[i + x] == 0:
poss = 0
break
if poss == 0:
print(-1)
else:
for i in range(x, x + n):
print(out[i], end="")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = list(input())
n = len(s)
x = int(input())
ans = ["1"] * n
b = ["0"] * n
for i in range(n):
if s[i] == "0":
if i - x >= 0:
ans[i - x] = "0"
if i + x < n:
ans[i + x] = "0"
for i in range(n):
if i - x >= 0 and ans[i - x] == "1":
b[i] = "1"
if i + x < n and ans[i + x] == "1":
b[i] = "1"
if s == b:
print("".join(ans))
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def tc():
s = input()
x = int(input())
n = len(s)
w = [1] * len(s)
for i, ch in enumerate(s):
if ch == "0":
if i - x >= 0:
w[i - x] = 0
if i + x < n:
w[i + x] = 0
for i, ch in enumerate(s):
if ch == "1":
l, r = False, False
if i - x >= 0 and w[i - x] == 1:
l = True
if i + x < n and w[i + x] == 1:
r = True
if not (l or r):
print(-1)
return
print("".join(map(str, w)))
T = int(input())
for _ in range(T):
tc() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve():
s = list(map(int, input()))
x = int(input())
n = len(s)
ans = [1] * n
for i, c in enumerate(s):
if c == 0:
if not i - x < 0:
ans[i - x] = 0
if not i + x >= n:
ans[i + x] = 0
t = [
int(not i - x < 0 and ans[i - x] or not i + x >= n and ans[i + x])
for i in range(n)
]
if t != s:
return -1
return "".join(map(str, ans))
t = int(input())
for _ in range(t):
print(solve()) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for tt in range(int(input())):
s = input()
n = len(s)
x = int(input())
ans = [" " for i in range(n)]
for i in range(n):
if s[i] == "0":
for j in [i - x, i + x]:
if 0 <= j and j < n:
ans[j] = "0"
good = True
for i in range(n):
if s[i] == "0":
if ans[i] != "0":
ans[i] = "1"
continue
l = 0 <= i - x and ans[i - x] != "0"
r = i + x < n and ans[i + x] != "0"
if not l and not r:
good = False
if l:
ans[i - x] = "1"
if r:
ans[i + x] = "1"
print("".join(ans) if good and " " not in ans else -1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR IF NUMBER VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR STRING IF VAR ASSIGN VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING VAR FUNC_CALL STRING VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = list(input())
x = int(input())
l = len(s)
news = ["-1"] * l
flag = 1
for i in range(l):
if s[i] == "1":
if i - x >= 0 and abs(int(news[i - x])) == 1:
news[i - x] = "1"
continue
elif i + x < l and abs(int(news[i + x])) == 1:
news[i + x] = "1"
continue
else:
print(-1)
flag = 0
break
else:
if i - x >= 0:
if news[i - x] != "0" and news[i - x] != "-1":
print(-1)
flag = 0
break
else:
news[i - x] = "0"
if i + x < l:
if news[i + x] != "0" and news[i + x] != "-1":
print(-1)
flag = 0
break
else:
news[i + x] = "0"
elif i - x < 0:
news[i] = "0"
if flag:
for i in range(len(news)):
if news[i] == "-1":
news[i] = "1"
print("".join(news)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def stringi(L):
r = ""
for l in L:
r += str(l)
return r
def construct(w, x):
n = len(w)
S = [0] * n
for i in range(n):
if i >= x:
if w[i - x] == "1":
S[i] = "1"
if i + x < n:
if w[i + x] == "1":
S[i] = "1"
S = stringi(S)
return S
T = int(input())
for i in range(T):
s = input()
x = int(input())
n = len(s)
w = [0] * n
for i in range(n):
if i >= x and i + x < n:
if s[i - x] == s[i + x] == "1":
w[i] = "1"
elif i >= x:
if s[i - x] == "1":
w[i] = "1"
elif i + x < n:
if s[i + x] == "1":
w[i] = "1"
w = stringi(w)
S = construct(w, x)
if S != s:
print(-1)
else:
print(w) | FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
s = input()
n = len(s)
x = iinput()
w = ["1" for _ in range(n)]
for i in range(n):
if s[i] == "0":
if i >= x:
w[i - x] = "0"
if i + x < n:
w[i + x] = "0"
ans = True
for i in range(n):
if i >= x and w[i - x] == "1" or i + x < n and w[i + x] == "1":
if s[i] != "1":
ans = False
break
elif s[i] != "0":
ans = False
break
if ans == True:
print("".join(w))
else:
print(-1) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = list(input())
x = int(input())
n = len(s)
bad = 0
ans = [(-1) for i in range(n)]
for i in range(n):
if i >= x and i + x < n:
if s[i - x] == s[i + x] == "1":
ans[i] = 1
elif s[i - x] == s[i + x] == "0":
ans[i] = 0
else:
ans[i] = 0
elif i >= x:
if s[i - x] == "1":
ans[i] = 1
elif s[i - x] == "0":
ans[i] = 0
elif i + x < n:
if s[i + x] == "1":
ans[i] = 1
elif s[i + x] == "0":
ans[i] = 0
else:
ans[i] = 0
bad = 0
for i in range(n):
chr = 0
if i >= x:
chr = max(chr, ans[i - x])
if i + x < n:
chr = max(chr, ans[i + x])
if chr != int(s[i]):
print(-1)
bad = 1
break
if not bad:
print("".join([str(i) for i in ans])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
for _ in range(II()):
s = SI()
x = II()
n = len(s)
ans = [1] * n
for i, c in enumerate(s):
if c == "0":
if i - x >= 0:
ans[i - x] = 0
if i + x < n:
ans[i + x] = 0
def ok():
for i in range(n):
if s[i] == "1":
flag = 0
if i - x >= 0:
flag |= ans[i - x]
if i + x < n:
flag |= ans[i + x]
if flag == 0:
return False
return True
if ok():
print(*ans, sep="")
else:
print(-1) | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def rn():
a = int(input())
return a
def rl():
a = list(map(int, input().split()))
return a
for _ in range(rn()):
s = list(input())
x = rn()
n = len(s)
a = ["2" for _ in range(n)]
dt = []
flag = 0
for i in range(x):
if i + x < n:
a[i + x] = s[i]
elif s[i] == "1":
flag = 1
break
if flag == 0:
for i in range(x, n - x):
if s[i] == "1":
dt.append([i - x, i + x])
else:
if a[i - x] == "1":
flag = 1
break
else:
a[i - x] = "0"
if a[i + x] == "1":
flag = 1
break
else:
a[i + x] = "0"
if flag == 0:
for i in range(n - x, n):
if i - x >= 0:
if a[i - x] == "2":
a[i - x] = s[i]
elif a[i - x] != s[i]:
flag = 1
break
elif s[i] == "1":
flag = 1
break
for i in dt:
if a[i[0]] == "1" or a[i[1]] == "1":
continue
if a[i[0]] == "2":
a[i[0]] = "1"
elif a[i[1]] == "2":
a[i[1]] = "1"
else:
flag = 1
break
if flag == 1:
print(-1)
else:
for i in a:
if i == "2":
print("1", end="")
else:
print(i, end="")
print("") | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER STRING VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING ASSIGN VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING ASSIGN VAR VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(t):
s = input()
x = int(input())
w = ["a"] * len(s)
for j in range(len(s)):
if s[j] == "0":
if j >= x:
w[j - x] = "0"
if j + x < len(s):
w[j + x] = "0"
flag = 0
for j in range(len(s)):
flag = 0
if s[j] == "1":
if j >= x:
if w[j - x] == "0":
flag += 1
else:
w[j - x] = "1"
else:
flag += 1
if j + x < len(s):
if w[j + x] == "0":
flag += 1
else:
w[j + x] = "1"
else:
flag += 1
if flag == 2:
break
if flag == 2:
print(-1)
else:
for j in range(len(w)):
if w[j] == "a":
w[j] = "1"
print("".join(w)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING IF VAR VAR IF VAR BIN_OP VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(t):
s = input()
b = []
for j in s:
b.append(int(j))
n = len(b)
y = int(input())
c = [1] * n
j = 0
f = 0
while j < n:
if b[j] == 0:
if j - y >= 0:
c[j - y] = 0
if j + y < n:
c[j + y] = 0
j += 1
j = 0
while j < n:
if j + y < n and j - y >= 0:
r = c[j - y] | c[j + y]
elif j + y < n:
r = c[j + y]
elif j - y >= 0:
r = c[j - y]
else:
r = 0
if r != b[j]:
f = 1
break
j += 1
if f == 1:
print(-1)
else:
s = ""
for j in c:
s += str(j)
print(s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.