message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 42 109k | cluster float64 5 5 | __index_level_0__ int64 84 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60 | instruction | 0 | 79,031 | 5 | 158,062 |
"Correct Solution:
```
#!/usr/bin/python3
import re
class Num:
def __init__(this, x):
this.x = x
def __str__(this):
return str(this.x)
def __add__(this, that):
return Num(this.x + that.x)
def __sub__(this, that):
return Num(this.x - that.x)
def __truediv__(this, that):
return Num(int(this.x / that.x))
def __mul__(this, that):
return Num(this.x * that.x)
def __neg__(this):
return Num(-this.x)
n = int(input())
for _ in range(n):
expr = input()[0:-1]
expr = re.sub(r'(\d+)', r'Num(\1)', expr)
print(eval(expr))
``` | output | 1 | 79,031 | 5 | 158,063 |
Provide a correct Python 3 solution for this coding contest problem.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60 | instruction | 0 | 79,032 | 5 | 158,064 |
"Correct Solution:
```
def digit():
global S
global cur
if S[cur].isdigit():
n = int(S[cur])
cur += 1
return n
def number():
global S
L = len(S)
global cur
n = digit()
while (cur < L and S[cur].isdigit()):
n = n*10 + digit()
return n
def expression():
global S
global cur
L = len(S)
a = term()
while (cur < L and (S[cur] == '+' or S[cur] == '-')):
op = S[cur]
cur += 1
b = term()
if op == '+':
a += b
else:
a -= b
return a
import math
def term():
global S
global cur
L = len(S)
a = factor()
while (cur < L and (S[cur] == '*' or S[cur] == '/')):
op = S[cur]
cur += 1
b = factor()
if op == '*':
a *= b
else:
a = math.trunc(a/b)
return a
def factor():
global S
global cur
if (S[cur] != '('):
return number()
else:
cur += 1
n = expression()
if S[cur] == ')':
cur += 1
return n
N = int(input().strip())
for _ in range(N):
S = str(input().strip())
S = S[:-1]
cur = 0
ans = expression()
print(ans)
``` | output | 1 | 79,032 | 5 | 158,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60
Submitted Solution:
```
import re
class Num:
def __str__(self):
return str(self.x)
def __init__(self, value):
self.x = value
def __add__(self, value):
return Num(self.x + value.x)
def __sub__(self, value):
return Num(self.x - value.x)
def __mul__(self, value):
return Num(self.x * value.x)
def __truediv__(self, value):
return Num(int(self.x / value.x))
N = int(input())
for i in range(N):
s = input()[:-1]
s = re.sub(r'(\d+)',r'Num(\1)',s)
print(eval(s))
``` | instruction | 0 | 79,033 | 5 | 158,066 |
Yes | output | 1 | 79,033 | 5 | 158,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60
Submitted Solution:
```
# AOJ 0109 Smart Calculator
# Python3 2018.6.18 bal4u
INF = 1000000010
LEFT = INF+1
RIGHT = INF+2
PLUS = INF+3
MINUS = INF+4
MUL = INF+5
DIV = INF+6
token = { '+':PLUS, '-':MINUS, '*':MUL, '/':DIV }
rank = { PLUS:2, MINUS:2, MUL:3, DIV:3, LEFT:1, RIGHT:1 }
S, top = [0]*200, 0
Q, end = [0]*200, 0
def getInt():
global id
global buf
k = ''
while buf[id] >= '0' and buf[id] <= '9':
k += buf[id]
id += 1
return int(k)
n = int(input())
for i in range(n):
buf = list(input())
id, f, top, end = 0, True, 0, 0
while True:
if buf[id] == '=':
while top > 0:
top -= 1
Q[end] = S[top]
end += 1
break;
if buf[id] == '-' and f and buf[id+1] >= '0' and buf[id+1] <= '9':
id += 1
Q[end] = -getInt()
end += 1
f = False
continue
f = False
if buf[id] >= '0' and buf[id] <= '9':
Q[end] = getInt()
end += 1
elif buf[id] == ')':
while S[top - 1] != LEFT:
top -= 1
Q[end] = S[top]
end += 1
top -= 1
id += 1
elif buf[id] == '(':
S[top] = LEFT
top += 1
id += 1
f = True
else:
k = token[buf[id]]
id += 1
while top > 0:
if rank[k] <= rank[S[top-1]]:
top -= 1
Q[end] = S[top];
end += 1
else: break
S[top] = k;
top += 1
top = 0
for i in range(end):
k = Q[i]
if k > INF:
d1, d2 = S[top-1], S[top-2]
top -= 2
if k == PLUS: d2 += d1
elif k == MINUS: d2 -= d1
elif k == MUL: d2 *= d1
else:
if (d2 > 0 and d1 < 0) or (d2 < 0 and d1 > 0):
d2 //= -d1
d2 = -d2
else: d2 //= d1
S[top] = d2
else: S[top] = k
top += 1
print(S[top-1])
``` | instruction | 0 | 79,034 | 5 | 158,068 |
Yes | output | 1 | 79,034 | 5 | 158,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60
Submitted Solution:
```
import re
class c:
def __str__(self):
return str(self.x)
def __init__(self,value):
self.x=value
def __add__(self,value):
return c(self.x+value.x)
def __sub__(self,value):
return c(self.x-value.x)
def __mul__(self,value):
return c(self.x*value.x)
def __truediv__(self,value):
return c(int(self.x/value.x))
n=int(input())
for i in range(n):
s=input()[:-1]
s=re.sub(r'(\d+)',r'c(\1)',s)
print(eval(s))
``` | instruction | 0 | 79,035 | 5 | 158,070 |
Yes | output | 1 | 79,035 | 5 | 158,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60
Submitted Solution:
```
def get_input():
while True:
try:
yield ''.join(input())
except EOFError:
break
# Convert String to List
def String2List(s):
L = []; tmp = ""
for i in s:
if i.isdigit():
tmp += i
else:
if tmp != "":
L.append(tmp)
tmp = ""
L.append(i)
if tmp != "":
L.append(tmp)
return L
# generate Reverse Polish Notation
def Generate_RPN(L):
S, L2 = [], []
table = {"*": 1, "/": 1, "+": 0, "-": 0, "(": -1, ")": -1}
for i in L:
if i.isdigit():
L2.append(i)
elif i == "(":
S.append(i)
elif i == ")":
while S[-1] != "(":
L2.append(S.pop())
S.pop()
else:
while len(S) != 0 and (table[S[-1]] >= table[i]):
L2.append(S.pop())
S.append(i)
while len(S) != 0:
L2.append(S.pop())
return L2
Nline = int(input())
for ll in range(Nline):
S = input()
p = Generate_RPN(String2List(S[0:-1]))
N = len(p)
s = []
for i in range(len(p)):
if p[i] == "+":
a = int(s.pop())
b = int(s.pop())
s.append(str(b+a))
elif p[i] == "-":
a = int(s.pop())
b = int(s.pop())
s.append(str(b-a))
elif p[i] == "*":
a = int(s.pop())
b = int(s.pop())
s.append(str(b*a))
elif p[i] == "/":
a = int(s.pop())
b = int(s.pop())
s.append(str(int(b/a)))
else:
s.append(p[i])
print(s[0])
``` | instruction | 0 | 79,036 | 5 | 158,072 |
Yes | output | 1 | 79,036 | 5 | 158,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60
Submitted Solution:
```
import re
n = int(input())
for i in range(n):
eq = input()
meq = re.sub(r'([\d*]+)/(\d+)',r'(\1//\2)', eq)
print(eval(meq.replace("=","")))
``` | instruction | 0 | 79,037 | 5 | 158,074 |
No | output | 1 | 79,037 | 5 | 158,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60
Submitted Solution:
```
n = int(input())
for i in range(n):
s = input()
print(eval(s[:-1:]))
``` | instruction | 0 | 79,038 | 5 | 158,076 |
No | output | 1 | 79,038 | 5 | 158,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
n = int(input())
for i in range(n):
command = input().strip()
command = command.replace('=', '')
print(eval(command))
``` | instruction | 0 | 79,039 | 5 | 158,078 |
No | output | 1 | 79,039 | 5 | 158,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.
* Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.
* You may assume that there is no division by zero.
* All calculation is performed as integers, and after the decimal point should be truncated
* Length of the expression will not exceed 100.
* -1 × 109 ≤ intermediate results of computation ≤ 109
Input
The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.
Output
For each datasets, prints the result of calculation.
Example
Input
2
4-2*3=
4*(8+4+3)=
Output
-2
60
Submitted Solution:
```
n=int(input())
for i in range(n):print(eval(input()[:-1].replace('/','//')))
``` | instruction | 0 | 79,040 | 5 | 158,080 |
No | output | 1 | 79,040 | 5 | 158,081 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5 | instruction | 0 | 79,094 | 5 | 158,188 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
class LazyPropSegmentTree:
def __init__(self, lst, op, apply, comp, e, identity):
self.n = len(lst)
self.depth = (self.n - 1).bit_length()
self.N = 1 << self.depth
self.op = op # binary operation of elements
self.apply = apply # function to apply to an element
self.comp = comp # composition of functions
self.e = e # identity element w.r.t. op
self.identity = identity # identity element w.r.t. comp
self.v = self._build(lst) # self.v is set to be 1-indexed for simplicity
self.lazy = [self.identity] * (2 * self.N)
def __getitem__(self, i):
return self.fold(i, i+1)
def _build(self, lst):
# construction of a tree
# total 2 * self.N elements (tree[0] is not used)
tree = [self.e] * (self.N) + lst + [self.e] * (self.N - self.n)
for i in range(self.N - 1, 0, -1): tree[i] = self.op(tree[i << 1], tree[(i << 1)|1])
return tree
def _indices(self, l, r):
left = l + self.N; right = r + self.N
left //= (left & (-left)); right //= (right & (-right))
left >>= 1; right >>= 1
while left != right:
if left > right: yield left; left >>= 1
else: yield right; right >>= 1
while left > 0: yield left; left >>= 1
# propagate self.lazy and self.v in a top-down manner
def _propagate_topdown(self, *indices):
identity, v, lazy, apply, comp = self.identity, self.v, self.lazy, self.apply, self.comp
for k in reversed(indices):
x = lazy[k]
if x == identity: continue
lazy[k << 1] = comp(lazy[k << 1], x)
lazy[(k << 1)|1] = comp(lazy[(k << 1)|1], x)
v[k << 1] = apply(v[k << 1], x)
v[(k << 1)|1] = apply(v[(k << 1)|1], x)
lazy[k] = identity # propagated
# propagate self.v in a bottom-up manner
def _propagate_bottomup(self, indices):
v, op = self.v, self.op
for k in indices: v[k] = op(v[k << 1], v[(k << 1)|1])
# update for the query interval [l, r) with function x
def update(self, l, r, x):
*indices, = self._indices(l, r)
self._propagate_topdown(*indices)
N, v, lazy, apply, comp = self.N, self.v, self.lazy, self.apply, self.comp
# update self.v and self.lazy for the query interval [l, r)
left = l + N; right = r + N
if left & 1: v[left] = apply(v[left], x); left += 1
if right & 1: right -= 1; v[right] = apply(v[right], x)
left >>= 1; right >>= 1
while left < right:
if left & 1:
lazy[left] = comp(lazy[left], x)
v[left] = apply(v[left], x)
left += 1
if right & 1:
right -= 1
lazy[right] = comp(lazy[right], x)
v[right] = apply(v[right], x)
left >>= 1; right >>= 1
self._propagate_bottomup(indices)
# returns answer for the query interval [l, r)
def fold(self, l, r):
self._propagate_topdown(*self._indices(l, r))
e, N, v, op = self.e, self.N, self.v, self.op
# calculate the answer for the query interval [l, r)
left = l + N; right = r + N
L = R = e
while left < right:
if left & 1: # self.v[left] is the right child
L = op(L, v[left])
left += 1
if right & 1: # self.v[right-1] is the left child
right -= 1
R = op(v[right], R)
left >>= 1; right >>= 1
return op(L, R)
N, Q = map(int, input().split())
op = min
apply = lambda x, f: f
comp = lambda f, g: g
e = 2**31 - 1
identity = None
A = [e] * N
lpsg = LazyPropSegmentTree(A, op, apply, comp, e, identity)
ans = []
for _ in range(Q):
t, *arg, = map(int, input().split())
if t == 0:
s, t, x = arg
lpsg.update(s, t+1, x)
else:
ans.append(lpsg[arg[0]])
print('\n'.join(map(str, ans)))
``` | output | 1 | 79,094 | 5 | 158,189 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5 | instruction | 0 | 79,095 | 5 | 158,190 |
"Correct Solution:
```
class SegmentTreeDual():
def __init__(self,arr,op=lambda x,y:y if y != -1 else x,ie=-1):
self.h = (len(arr)-1).bit_length()
self.n = 2**self.h
self.ie = ie
self.op = op
self.val = [ie for _ in range(len(arr))]
self.laz = [ie for _ in range(2*self.n)]
for i in range(len(arr)):
self.val[i] = arr[i]
def propagate(self,k):
if self.laz[k] == self.ie:
return
if self.n <= k:
self.val[k-self.n] = self.op(self.val[k-self.n],self.laz[k])
self.laz[k] = self.ie
else:
self.laz[(k<<1)] = self.op(self.laz[(k<<1)],self.laz[k])
self.laz[(k<<1)+1] = self.op(self.laz[(k<<1)+1],self.laz[k])
self.laz[k] = self.ie
def update(self,left,right,f):
left += self.n
right += self.n
for i in reversed(range(self.h+1)):
self.propagate(left>>i)
for i in reversed(range(self.h+1)):
self.propagate((right-1)>>i)
while right - left > 0:
if right & 1:
right -= 1
self.laz[right] = self.op(self.laz[right],f)
if left & 1:
self.laz[left] = self.op(self.laz[left],f)
left += 1
left >>= 1
right >>= 1
def get(self,index):
res = self.val[index]
index += self.n
while index:
res = self.op(res,self.laz[index])
index //= 2
return res
INF = 2**31-1
N,Q = map(int,input().split())
A = [INF for _ in range(N)]
sg = SegmentTreeDual(A)
ans = []
for _ in range(Q):
q = list(map(int,input().split()))
if q[0] == 0:
s,t,x = q[1:]
sg.update(s,t+1,x)
else:
i = q[1]
ans.append(sg.get(i))
print('\n'.join(map(str,ans)))
``` | output | 1 | 79,095 | 5 | 158,191 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5 | instruction | 0 | 79,096 | 5 | 158,192 |
"Correct Solution:
```
class TemplateTree:
def __init__(self, iterable):
self.iter_size = self.get_size(iterable)
self.size = self.iter_size * 2 - 1
self.value = [None] * self.size
for i, v in enumerate(iterable):
self.value[self.iter_size + i - 1] = (-1, v)
self.set_value(0)
self.range = [None] * self.size
self.set_range(0, 0, self.iter_size - 1)
def get_size(self, iterable):
ret = 1
x = len(iterable)
while ret < x:
ret *= 2
return ret
def set_range(self, x, left, right):
self.range[x] = (left, right)
if left != right:
self.set_range(x * 2 + 1, left, (right + left) // 2)
self.set_range(x * 2 + 2, (right + left) // 2 + 1, right)
def set_value(self, x):
if x >= self.iter_size - 1:return self.value[x]
a = self.set_value(x * 2 + 1)
b = self.set_value(x * 2 + 2)
if a == None and b == None:
self.value[x] = None
elif a == None:
self.value[x] = b
elif b == None:
self.value[x] = a
else:
self.value[x] = a
return self.value[x]
def update(self, x, val, order, left, right):
#print(x)
x_left, x_right = self.range[x]
if left <= x_left and x_right <= right:
self.value[x] = (order, val)
elif right < x_left or x_right < left:
pass
else:
self.update(x * 2 + 1, val, order, left, right)
self.update(x * 2 + 2, val, order, left, right)
def query(self, x, order, value):
if x < 0:
return value
x_order, x_val = self.value[x]
if order < x_order:
return self.query((x - 1) // 2, x_order, x_val)
else:
return self.query((x - 1) // 2, order, value)
def print_tree(self):
print(self.value)
print(self.range)
n, q = map(int, input().split())
INF = 2 ** 31 - 1
tree = TemplateTree([INF] * n)
for j in range(q):
lst = list(map(int, input().split()))
if lst[0] == 0:
s, t, x = lst[1:]
tree.update(0, x, j, s, t)
else:
i = lst[1]
print(tree.query(tree.iter_size - 1 + i, -2, 0))
``` | output | 1 | 79,096 | 5 | 158,193 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5 | instruction | 0 | 79,097 | 5 | 158,194 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
n, q = map(int, readline().split())
N0 = 2**(n-1).bit_length()
data = [None]*(2*N0)
INF = (-1, 2**31-1)
def update(l, r, v):
L = l + N0; R = r + N0
while L < R:
if R & 1:
R -= 1
data[R-1] = v
if L & 1:
data[L-1] = v
L += 1
L >>= 1; R >>= 1
def _query(k):
k += N0-1
s = INF
while k >= 0:
if data[k]:
s = max(s, data[k])
k = (k - 1) // 2
return s
def query(k):
return _query(k)[1]
ans = []
for i in range(q):
t, *cmd = map(int, readline().split())
if t:
ans.append(str(query(cmd[0])))
else:
s, t, x = cmd
update(s, t+1, (i, x))
write("\n".join(ans))
write("\n")
``` | output | 1 | 79,097 | 5 | 158,195 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5 | instruction | 0 | 79,098 | 5 | 158,196 |
"Correct Solution:
```
"""
Segment-Tree
maxval:入力されるデータ以上の値
offset:根と枝の数(n=1のときは根1つ葉2つの木)
init_array(array):配列で初期化
update(k,x):k番目をxに変更
sum_query(p,q):[p,q)の範囲の合計
"""
class SegmentTree():
maxval=(1<<31)-1
def __init__(self,n):
self.offset=self.setOffset(n)
self.segTree=[(0,self.maxval) for i in range(2*self.offset+1)]
self.time=0
def setOffset(self,n):
if n==1:
return 1
else:
return 2**(n-1).bit_length()-1
def find(self,k):
k+=self.offset
data=self.segTree[k]
while k:
k=(k-1)//2
data=max(data,self.segTree[k])
return data
def update_query(self,p,q,x):
if p>=q:
return
self.time+=1
p+=self.offset
q+=self.offset-1
v=(self.time,x)
while q-p>1:
#p%2==0
if not p&1:
self.segTree[p]=v
#q%2==1
if q&1:
self.segTree[q]=v
q-=1
p=p//2
q=(q-1)//2
if p==q:
self.segTree[p]=v
else:
self.segTree[p]=v
self.segTree[q]=v
def show(self):
print(self.segTree)
n,q=map(int,input().split())
ST=SegmentTree(n)
for i in range(q):
qry=list(map(int,input().split()))
if qry[0]==0:
ST.update_query(qry[1],qry[2]+1,qry[3])
else:
print(ST.find(qry[1])[1])
``` | output | 1 | 79,098 | 5 | 158,197 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5 | instruction | 0 | 79,099 | 5 | 158,198 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
#INF = 2**31 -1
#n, q = list(map(int, input().split()))
#
#lis = [INF for i in range(n)]
#
#for i in range(q):
# data = list(map(int, input().split()))
# if len(data) == 4:
# a, s, t, x = data
# for j in range(s, t+1):
# lis[j] = x
# else:
# b, k = data
# print(lis[k])
INF = 2**31 - 1
n, q = list(map(int, input().split()))
lazy = [None for i in range(4*n)]
for i in range(n):
lazy[i] = INF
def updata(a, b, x, k, l, r):
m = (l+r)//2
if a >= r or b <= l:
return 0
elif a <= l and b >= r:
lazy[k] = x
else:
if lazy[k] != None:
lazy[k*2+1] = lazy[k]
lazy[k*2+2] = lazy[k]
lazy[k] = None
updata(a, b, x, k*2+1, l, m)
updata(a, b, x, k*2+2, m, r)
def find(x, k, l, r):
m = (l+r)//2
if lazy[k] != None:
print(lazy[k])
else:
if x < (l+r)//2:
find(x, k*2+1, l, m)
else:
find(x, k*2+2, m, r)
for i in range(q):
data = list(map(int, input().split()))
if len(data) == 4:
f, a, b, x = data
updata(a, b+1, x, 0, 0, n)
else:
f, i = data
find(i, 0, 0, n)
``` | output | 1 | 79,099 | 5 | 158,199 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5 | instruction | 0 | 79,100 | 5 | 158,200 |
"Correct Solution:
```
n,q=map(int,input().split())
Q=[list(map(int,input().split())) for i in range(q)]
for i in range(30):#要素数以上の2のベキを見つける
if n<=1<<i:
seg_el=1<<i#Segment treeの台の要素数
break
SEG=[None for i in range(2*seg_el-1)]#Segment tree(遅延伝搬を用いるが、一本のセグ木でOK)
def lazy_update(k,x):#一つ下の子へ伝搬
if 0<=k<seg_el-1:
lazy_item,SEG[k]=SEG[k],None
SEG[k*2+1]=SEG[k*2+2]=lazy_item
def update(a,b,x,k,l,r):
if SEG[k]!=None:#アクセスした箇所にデータが入っていたときは,評価を伝搬させる
lazy_update(k,x)
if r<=a or b<=l:#区間[a,b)が対象区間の外にあれば終了
return
if a<=l and r<=b:#区間[a,b)が対象区間の中にあればSEG[k]を更新.後にアクセスされたときに遅延評価する.
SEG[k]=x#
return
update(a,b,x,k*2+1,l,(l+r)//2)#それ以外のときは,SEG[k*2+1]とSEG[k*2+2]で場合分け
update(a,b,x,k*2+2,(l+r)//2,r)
def getvalue(n):#値を得る
i=n+seg_el-1
ANS=SEG[i]
i=(i-1)//2
while i>=0:
if SEG[i]!=None:
ANS=SEG[i]#できるだけ親に近いノードから値を得るようにする.(そこが最後に更新されたものなので)
i=(i-1)//2
return ANS
for i in range(n):
SEG[i+seg_el-1]=(1<<31)-1
for query in Q:
if query[0]==0:
update(query[1],query[2]+1,query[3],0,0,seg_el)
else:
print(getvalue(query[1]))
``` | output | 1 | 79,100 | 5 | 158,201 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5 | instruction | 0 | 79,101 | 5 | 158,202 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
n, q = map(int, input().split())
size = 2**((n-1).bit_length())
tree = [None]*(size*2)
INF = (-1, 2**31-1)
def _find(i):
ind = size+i
s = INF
while ind:
if tree[ind]:
s = max(s, tree[ind])
ind = ind//2
return s
def find(i):
return _find(i)[1]
def update(s, t, v):
L = s+size;R = t+size
while L<R:
if R&1:
R-=1
tree[R]=v
if L&1:
tree[L]=v
L+=1
L>>=1;R>>=1
ans = []
for i in range(q):
a, *b = map(int, input().split())
if a:ans.append(find(b[0]))
else:update(b[0],b[1]+1,(i,b[2]))
print('\n'.join(map(str,ans)))
``` | output | 1 | 79,101 | 5 | 158,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5
Submitted Solution:
```
import sys
input = sys.stdin.readline
n, q = map(int, input().split())
size = 2**((n-1).bit_length())
tree = [None]*(size*2)
INF = (-1, 2**31-1)
def _find(i):
ind = size+i
s = INF
while ind:
if tree[ind]:
s = max(s, tree[ind])
ind = ind//2
return s
def find(i):
return _find(i)[1]
def update(s, t, v):
L = s+size;R = t+size
while L<R:
if L&1:
tree[L]=v
L+=1
if R&1:
R-=1
tree[R]=v
L>>=1;R>>=1
res = []
for i in range(q):
a, *b = map(int, input().split())
if a:res.append(find(b[0]))
else:update(b[0],b[1]+1,(i,b[2]))
print('\n'.join(map(str,res)))
``` | instruction | 0 | 79,102 | 5 | 158,204 |
Yes | output | 1 | 79,102 | 5 | 158,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5
Submitted Solution:
```
#3158554 By JAKENU0X5E 参照
n,q = map(int,input().split( ))
s = 1
while s < n:
s*=2
A = [(-1,2**31-1)]*(2*s-1)
#print(A)
def update(l,r,i,v):#A[l,r)および対応する親ノードをiターン目にvに書き換える
while l<r:
if r&1:
r -= 1###-1
A[r-1] = (i,v)###-1
if l&1:
A[l-1]=(i,v)###-1
l+=1###+1
l//=2
r//=2
for i in range(q):
c = list(map(int, input().split( )))
if not c[0]:
x = c[1]
y = c[2]
u = c[3]
x += s ###
y += s
#x -=1###
update(x,y+1,i,u)
#print(A)
else:
res = (-1,0)
x = c[1] + s-1
while x>=0:
#print(res,A[x])
if A[x] > res:
res = A[x]
x -=1
x//=2
print(res[1])
``` | instruction | 0 | 79,103 | 5 | 158,206 |
Yes | output | 1 | 79,103 | 5 | 158,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5
Submitted Solution:
```
from math import log2, ceil
class SegmentTree:
def __init__(self, n):
tn = 2 ** ceil(log2(n))
self.a = [2 ** 31 - 1] * (tn * 2)
def find(self, c, l, r, i):
if self.a[c] != -1:
return self.a[c]
mid = (l + r) // 2
if i <= mid:
return self.find(c * 2, l, mid, i)
else:
return self.find(c * 2 + 1, mid + 1, r, i)
def update(self, c, l, r, s, t, x):
if l == s and r == t:
self.a[c] = x
return
cv = self.a[c]
if cv != -1:
self.a[c * 2] = self.a[c * 2 + 1] = cv
self.a[c] = -1
mid = (l + r) // 2
if t <= mid:
self.update(c * 2, l, mid, s, t, x)
elif s > mid:
self.update(c * 2 + 1, mid + 1, r, s, t, x)
else:
self.update(c * 2, l, mid, s, mid, x)
self.update(c * 2 + 1, mid + 1, r, mid + 1, t, x)
n, q = map(int, input().split())
st = SegmentTree(n)
for _ in range(q):
query = input().split()
if query[0] == '0':
s, t, x = map(int, query[1:])
st.update(1, 0, n - 1, s, t, x)
else:
print(st.find(1, 0, n - 1, int(query[1])))
``` | instruction | 0 | 79,104 | 5 | 158,208 |
Yes | output | 1 | 79,104 | 5 | 158,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5
Submitted Solution:
```
import sys
INF = 2**31 - 1
class RUQ:
def __init__(self, n):
tmp = 1
while tmp < n:
tmp *= 2
self.n = tmp * 2
self.A = [INF] * (2 * self.n - 1)
def update(self, a, b, x=-1, k=0, l=0, r=0):
if r <= a or b <= l:
return
if a <= l and r <= b:
if x >= 0:
self.A[k] = x
return
if self.A[k] != INF:
self.A[k*2+1] = self.A[k*2+2] = self.A[k]
self.A[k] = INF
self.update(a, b, x, k*2+1, l, (l+r)/2)
self.update(a, b, x, k*2+2, (l+r)/2, r)
line = sys.stdin.readline()
n, q = map(int, line.split())
ruq = RUQ(n)
for i in range(q):
line = sys.stdin.readline()
if line[0] == "0":
com, s, t, x = map(int, line.split())
ruq.update(s, t+1, x, 0, 0, ruq.n)
else:
com, i = map(int, line.split())
ruq.update(i, i+1, -1, 0, 0, ruq.n)
print(ruq.A[i+ruq.n-1])
``` | instruction | 0 | 79,105 | 5 | 158,210 |
Yes | output | 1 | 79,105 | 5 | 158,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5
Submitted Solution:
```
#! -*- coding:utf-8 -*-
n,q = map(int,input().split())
query = [0] * q
for i in range(q):
query[i] = input()
arr = [2**31 - 1] * n
for i in range(q):
if len(query[i]) == 7:
tmp = list(query[i].split())
s = int(tmp[1])
t = int(tmp[2])
for i in range(s,t+1):
arr[i] = tmp[3]
else:
tmp = list(query[i].split())
print(arr[int(tmp[1])])
``` | instruction | 0 | 79,106 | 5 | 158,212 |
No | output | 1 | 79,106 | 5 | 158,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5
Submitted Solution:
```
import math
INT_MAX = 2147483647
n,q=(int(x) for x in input().split())
b= int(math.sqrt(n))
def update(x_f):
x = int(x_f)
for i in range(int(x*b),min(n-1,int((x+1)*b-1))+1):a[i]=l[x]
l[x]=-1
return
if __name__=='__main__':
a = [INT_MAX for i in range(n)]
l = [-1 for i in range(n)]
for j in range(q):
t, *com = (int(x) for x in input().split())
if t :
x = com[0]
if l[int(x/b)] != -1:update(x/b)
print(a[x])
else:
x,y,z = com
if l[int(x/b)] != -1:update(x/b)
for i in range(x,min(y,int((x/b+1)*b-1))+1):a[i]=z
for i in range(int(x/b+1),int(y/b)):l[i]=z
if l[int(y/b)] != -1:update(y/b)
for i in range(max(x,int(y/b**2)),y+1):a[i]=z
``` | instruction | 0 | 79,107 | 5 | 158,214 |
No | output | 1 | 79,107 | 5 | 158,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5
Submitted Solution:
```
import math
INT_MAX = 2147483647
MAX = 100003
n,q=(int(x) for x in input().split())
b= math.sqrt(n)
def update(x):
for i in range(int(x*b),(min(n-1,(x+1)*b)):a[i]=l[x]
l[x]=-1;
return;
if __name__=='__main__':
a = [INT_MAX for i in range(n)]
l = [-1 for i in range(n)]
for i in range(q):
t, *com = (int(x) for x in input().split())
if t :
x = com[0]
if l[int(x/b)] != -1:update(x/b)
print(a[x])
else:
x,y,z = com
if l[int(x/b)] != -1:update(x/b)
for i in range(x,int(min(y,(x/b+1)*b))):a[i]=z
for i in range(int(x/b)+1,int(y/b)):l[i]=z
if l[int(y/b)] != -1:update(y/b)
for i in range(int(max(x,y/b**2)),y+1):a[i]=z
``` | instruction | 0 | 79,108 | 5 | 158,216 |
No | output | 1 | 79,108 | 5 | 158,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* 0 ≤ s ≤ t < n
* 0 ≤ i < n
* 0 ≤ x < 231−1
Input
n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x
or
1 i
The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Examples
Input
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Output
1
3
Input
1 3
1 0
0 0 0 5
1 0
Output
2147483647
5
Submitted Solution:
```
import sys
import math
import time
sys.setrecursionlimit(20000)
INT_MAX = 2**31 - 1
def update(tree,x,y,z,N):
left = x + N #- 1
right = y + N #- 1
while True:
if(left > right):
break
if(right > 0):
tree[right - 1] = z
if(left > 0):
tree[left - 1] = z
left = math.floor((left + 1)/2)
right = math.floor((right - 1)/2)
def find(tree,x,N):
x += N - 1
s = (INT_MAX, -1)
while True:
if(x <= 0):
break
if(tree[x][1] > s[1]):
s = tree[x]
x = math.floor((x - 1)/2)
return s[0]
if __name__ == '__main__':
_N,query_num = map(int, input().split())
N = 1
while True:
if(N >= _N):
break
N <<= 1
if not (N == 1):
A = [(INT_MAX,-1)]*(2*N - 1)
else:
A = [(INT_MAX,-1)]*(2*N)
#start = time.time()
for i in range(query_num):
query = list(map(int,input().split()))
# update
if(query[0]==0):
update(A,query[1],query[2],(query[3],i),N)
#print(A)
# find
if(query[0]==1):
#z = find(A,lazy_A,query[1],query[1]+1,0,0,N,N)
z = find(A,query[1],N)
print(z)
#elapsed_time = time.time() - start
#print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
``` | instruction | 0 | 79,109 | 5 | 158,218 |
No | output | 1 | 79,109 | 5 | 158,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows:
* F_0 = 0, F_1 = 1.
* For each i ≥ 2: F_i = F_{i - 1} + F_{i - 2}.
Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2⋅ d,…, a + (n - 1)⋅ d).
You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2⋅ e,…, b + (n - 1)⋅ e) such that:
* 0 < b, e < 2^{64},
* for all 0≤ i < n, the decimal representation of a + i ⋅ d appears as substring in the last 18 digits of the decimal representation of F_{b + i ⋅ e} (if this number has less than 18 digits, then we consider all its digits).
Input
The first line contains three positive integers n, a, d (1 ≤ n, a, d, a + (n - 1) ⋅ d < 10^6).
Output
If no such arithmetic sequence exists, print -1.
Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}).
If there are many answers, you can output any of them.
Examples
Input
3 1 1
Output
2 1
Input
5 1 2
Output
19 5
Note
In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3.
In the second test case, we can choose (b, e) = (19, 5) because:
* F_{19} = 4181 contains 1;
* F_{24} = 46368 contains 3;
* F_{29} = 514229 contains 5;
* F_{34} = 5702887 contains 7;
* F_{39} = 63245986 contains 9.
Submitted Solution:
```
a,t,h=map(int,input().split())
print(368131125*t%10**9*12*10**9+1,368131125*h%10**9*12*10**9)
``` | instruction | 0 | 79,275 | 5 | 158,550 |
Yes | output | 1 | 79,275 | 5 | 158,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows:
* F_0 = 0, F_1 = 1.
* For each i ≥ 2: F_i = F_{i - 1} + F_{i - 2}.
Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2⋅ d,…, a + (n - 1)⋅ d).
You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2⋅ e,…, b + (n - 1)⋅ e) such that:
* 0 < b, e < 2^{64},
* for all 0≤ i < n, the decimal representation of a + i ⋅ d appears as substring in the last 18 digits of the decimal representation of F_{b + i ⋅ e} (if this number has less than 18 digits, then we consider all its digits).
Input
The first line contains three positive integers n, a, d (1 ≤ n, a, d, a + (n - 1) ⋅ d < 10^6).
Output
If no such arithmetic sequence exists, print -1.
Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}).
If there are many answers, you can output any of them.
Examples
Input
3 1 1
Output
2 1
Input
5 1 2
Output
19 5
Note
In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3.
In the second test case, we can choose (b, e) = (19, 5) because:
* F_{19} = 4181 contains 1;
* F_{24} = 46368 contains 3;
* F_{29} = 514229 contains 5;
* F_{34} = 5702887 contains 7;
* F_{39} = 63245986 contains 9.
Submitted Solution:
```
value = 3337867500
n, a, d = map(int, input().split())
print(value * n, value * d)
``` | instruction | 0 | 79,279 | 5 | 158,558 |
No | output | 1 | 79,279 | 5 | 158,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The well-known Fibonacci sequence F_0, F_1, F_2,… is defined as follows:
* F_0 = 0, F_1 = 1.
* For each i ≥ 2: F_i = F_{i - 1} + F_{i - 2}.
Given an increasing arithmetic sequence of positive integers with n elements: (a, a + d, a + 2⋅ d,…, a + (n - 1)⋅ d).
You need to find another increasing arithmetic sequence of positive integers with n elements (b, b + e, b + 2⋅ e,…, b + (n - 1)⋅ e) such that:
* 0 < b, e < 2^{64},
* for all 0≤ i < n, the decimal representation of a + i ⋅ d appears as substring in the last 18 digits of the decimal representation of F_{b + i ⋅ e} (if this number has less than 18 digits, then we consider all its digits).
Input
The first line contains three positive integers n, a, d (1 ≤ n, a, d, a + (n - 1) ⋅ d < 10^6).
Output
If no such arithmetic sequence exists, print -1.
Otherwise, print two integers b and e, separated by space in a single line (0 < b, e < 2^{64}).
If there are many answers, you can output any of them.
Examples
Input
3 1 1
Output
2 1
Input
5 1 2
Output
19 5
Note
In the first test case, we can choose (b, e) = (2, 1), because F_2 = 1, F_3 = 2, F_4 = 3.
In the second test case, we can choose (b, e) = (19, 5) because:
* F_{19} = 4181 contains 1;
* F_{24} = 46368 contains 3;
* F_{29} = 514229 contains 5;
* F_{34} = 5702887 contains 7;
* F_{39} = 63245986 contains 9.
Submitted Solution:
```
n,a,d=map(int,input().split())
print(368131125 * a % 10**9 * 12 * 10**9 + 1, 368131125 * a % 10**9 * 12 * 10**9)
``` | instruction | 0 | 79,281 | 5 | 158,562 |
No | output | 1 | 79,281 | 5 | 158,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only differences between easy and hard versions are the constraints on n and the time limit. You can make hacks only if all versions are solved.
Slime is interested in sequences. He defined good positive integer sequences p of length n as follows:
* For each k>1 that presents in p, there should be at least one pair of indices i,j, such that 1 ≤ i < j ≤ n, p_i = k - 1 and p_j = k.
For the given integer n, the set of all good sequences of length n is s_n. For the fixed integer k and the sequence p, let f_p(k) be the number of times that k appears in p. For each k from 1 to n, Slime wants to know the following value:
$$$\left(∑_{p∈ s_n} f_p(k)\right)\ mod\ 998 244 353$$$
Input
The first line contains one integer n\ (1≤ n≤ 5000).
Output
Print n integers, the i-th of them should be equal to \left(∑_{p∈ s_n} f_p(i)\right)\ mod\ 998 244 353.
Examples
Input
2
Output
3 1
Input
3
Output
10 7 1
Input
1
Output
1
Note
In the first example, s=\{[1,1],[1,2]\}.
In the second example, s=\{[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,2],[1,2,3]\}.
In the third example, s=\{[1]\}.
Submitted Solution:
```
t=input()
if t=='2':
print('3 1')
if t=='3':
print('10 7 1')
if t=='1':
print('1')
``` | instruction | 0 | 79,309 | 5 | 158,618 |
No | output | 1 | 79,309 | 5 | 158,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once, Leha found in the left pocket an array consisting of n integers, and in the right pocket q queries of the form l r k. If there are queries, then they must be answered. Answer for the query is minimal x such that x occurs in the interval l r strictly more than <image> times or - 1 if there is no such number. Help Leha with such a difficult task.
Input
First line of input data contains two integers n and q (1 ≤ n, q ≤ 3·105) — number of elements in the array and number of queries respectively.
Next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — Leha's array.
Each of next q lines contains three integers l, r and k (1 ≤ l ≤ r ≤ n, 2 ≤ k ≤ 5) — description of the queries.
Output
Output answer for each query in new line.
Examples
Input
4 2
1 1 2 2
1 3 2
1 4 2
Output
1
-1
Input
5 3
1 2 1 3 2
2 5 3
1 2 3
5 5 2
Output
2
1
2
Submitted Solution:
```
from collections import Counter
a,b=map(int,input("").split(" "))
l=list(map(int,input("").split(" ")))
l=sorted(l)
c=Counter(l)
for i in range(b):
q,w,e=map(int,input("").split(" "))
p=(w-q+1)/e
s=[]
z=pow(10,5)
for j in l:
if j>=q and j<=w:
s.append(j)
for d in s:
if c[d]>p and z>d:
z=d
if z==pow(10,5):
print(-1)
else:
print(z)
``` | instruction | 0 | 79,638 | 5 | 159,276 |
No | output | 1 | 79,638 | 5 | 159,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once, Leha found in the left pocket an array consisting of n integers, and in the right pocket q queries of the form l r k. If there are queries, then they must be answered. Answer for the query is minimal x such that x occurs in the interval l r strictly more than <image> times or - 1 if there is no such number. Help Leha with such a difficult task.
Input
First line of input data contains two integers n and q (1 ≤ n, q ≤ 3·105) — number of elements in the array and number of queries respectively.
Next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — Leha's array.
Each of next q lines contains three integers l, r and k (1 ≤ l ≤ r ≤ n, 2 ≤ k ≤ 5) — description of the queries.
Output
Output answer for each query in new line.
Examples
Input
4 2
1 1 2 2
1 3 2
1 4 2
Output
1
-1
Input
5 3
1 2 1 3 2
2 5 3
1 2 3
5 5 2
Output
2
1
2
Submitted Solution:
```
import re
_,n=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(n):
l,r,k=map(int,input().split())
k=(l-r+1)/k
b = a[l - 1:r]
b.sort()
t=0
k1=0
m=b[0]
for i in b:
if i==m:
k1+=1
else:
if k1>k:
t=1
print(m)
break
else:
k=1
m=i
if t==0:
print(-1)
#print(' '.join([str(i) for i in s]))
``` | instruction | 0 | 79,640 | 5 | 159,280 |
No | output | 1 | 79,640 | 5 | 159,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once, Leha found in the left pocket an array consisting of n integers, and in the right pocket q queries of the form l r k. If there are queries, then they must be answered. Answer for the query is minimal x such that x occurs in the interval l r strictly more than <image> times or - 1 if there is no such number. Help Leha with such a difficult task.
Input
First line of input data contains two integers n and q (1 ≤ n, q ≤ 3·105) — number of elements in the array and number of queries respectively.
Next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — Leha's array.
Each of next q lines contains three integers l, r and k (1 ≤ l ≤ r ≤ n, 2 ≤ k ≤ 5) — description of the queries.
Output
Output answer for each query in new line.
Examples
Input
4 2
1 1 2 2
1 3 2
1 4 2
Output
1
-1
Input
5 3
1 2 1 3 2
2 5 3
1 2 3
5 5 2
Output
2
1
2
Submitted Solution:
```
from collections import Counter
a,b=map(int,input("").split(" "))
l=list(map(int,input("").split(" ")))
l=sorted(l)
c=Counter(l)
for i in range(b):
q,w,e=map(int,input("").split(" "))
p=(w-q+1)/e
s=[]
z=pow(10,5)
if p.is_integer():
for j in l:
if j>=q and j<=w:
s.append(j)
for d in s:
if c[d]>p and z>d:
z=d
if z==pow(10,5):
print(-1)
else:
print(z)
``` | instruction | 0 | 79,641 | 5 | 159,282 |
No | output | 1 | 79,641 | 5 | 159,283 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes | instruction | 0 | 79,701 | 5 | 159,402 |
"Correct Solution:
```
N = (input())
print('Yes')if '7' in N else print('No')
``` | output | 1 | 79,701 | 5 | 159,403 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes | instruction | 0 | 79,702 | 5 | 159,404 |
"Correct Solution:
```
print('Yes') if '7' in input() else print('No')
``` | output | 1 | 79,702 | 5 | 159,405 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes | instruction | 0 | 79,703 | 5 | 159,406 |
"Correct Solution:
```
a = input()
print('Yes' if "7" in a else "No")
``` | output | 1 | 79,703 | 5 | 159,407 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes | instruction | 0 | 79,704 | 5 | 159,408 |
"Correct Solution:
```
n = input()
print("Yes" if n.count("7") >= 1 else "No")
``` | output | 1 | 79,704 | 5 | 159,409 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes | instruction | 0 | 79,705 | 5 | 159,410 |
"Correct Solution:
```
print('Yes' if "7" in input() else 'No')
``` | output | 1 | 79,705 | 5 | 159,411 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes | instruction | 0 | 79,706 | 5 | 159,412 |
"Correct Solution:
```
N = input()
print('Yes' if N.find('7') != -1 else 'No')
``` | output | 1 | 79,706 | 5 | 159,413 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes | instruction | 0 | 79,707 | 5 | 159,414 |
"Correct Solution:
```
print("Yes" if input().find("7") >= 0 else "No")
``` | output | 1 | 79,707 | 5 | 159,415 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes | instruction | 0 | 79,708 | 5 | 159,416 |
"Correct Solution:
```
print("Yes" if input().count('7') else "No")
``` | output | 1 | 79,708 | 5 | 159,417 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes
Submitted Solution:
```
import sys
n = input()
print('Yes' if '7' in n else 'No')
``` | instruction | 0 | 79,709 | 5 | 159,418 |
Yes | output | 1 | 79,709 | 5 | 159,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes
Submitted Solution:
```
print(["No","Yes"][int("7" in input())])
``` | instruction | 0 | 79,710 | 5 | 159,420 |
Yes | output | 1 | 79,710 | 5 | 159,421 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes
Submitted Solution:
```
A = input()
if "7" in A:
print("Yes")
else:
print("No")
``` | instruction | 0 | 79,711 | 5 | 159,422 |
Yes | output | 1 | 79,711 | 5 | 159,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes
Submitted Solution:
```
n=str(input())
print("YNeos"[not "7" in n::2])
``` | instruction | 0 | 79,712 | 5 | 159,424 |
Yes | output | 1 | 79,712 | 5 | 159,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes
Submitted Solution:
```
n=int(input())
s=list(input())
rn=s.count('R')
gn=s.count('G')
bn=n-rn-gn
ans=0
if n>2:
for x in range(len(s)-2):
if s[x]=='R':
rn-=1
ans+=gn*bn
elif s[x]=='G':
gn-=1
ans+=rn*bn
else:
bn-=1
ans+=gn*rn
y=(n-1-x)//2
for i in range(1,y+1):
if (not s[x]==s[x+i]) & (not s[x]==s[x+i+i]) & (not s[x+i]==s[x+i+i]):
ans-=1
print(ans)
else:
print(0)
``` | instruction | 0 | 79,713 | 5 | 159,426 |
No | output | 1 | 79,713 | 5 | 159,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes
Submitted Solution:
```
A = input()
for a in range(3):
if A[a] == '7':
print(yes)
break
if a == 2:
print('No')
``` | instruction | 0 | 79,714 | 5 | 159,428 |
No | output | 1 | 79,714 | 5 | 159,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes
Submitted Solution:
```
N = input()
if '7' in N:
print("Yes")
elif '7' not in N:
print:("No")
``` | instruction | 0 | 79,715 | 5 | 159,430 |
No | output | 1 | 79,715 | 5 | 159,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a three-digit integer N. Does N contain the digit 7?
If so, print `Yes`; otherwise, print `No`.
Constraints
* 100 \leq N \leq 999
Input
Input is given from Standard Input in the following format:
N
Output
If N contains the digit 7, print `Yes`; otherwise, print `No`.
Examples
Input
117
Output
Yes
Input
123
Output
No
Input
777
Output
Yes
Submitted Solution:
```
l = input()
print("Yes" if l[-1]=='7' else "No")
``` | instruction | 0 | 79,716 | 5 | 159,432 |
No | output | 1 | 79,716 | 5 | 159,433 |
Provide a correct Python 3 solution for this coding contest problem.
We have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \leq i < N ) holds.
Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.
Let S and T be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible values of S - T are there?
Constraints
* -10^8 \leq X, D \leq 10^8
* 1 \leq N \leq 2 \times 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X D
Output
Print the number of possible values of S - T.
Examples
Input
3 4 2
Output
8
Input
2 3 -3
Output
2
Input
100 14 20
Output
49805 | instruction | 0 | 79,717 | 5 | 159,434 |
"Correct Solution:
```
from collections import defaultdict
n, x, d = map(int, input().split())
if d == 0:
if x == 0:
print(1)
else:
print(n+1)
exit()
L = []
C = defaultdict(int)
D = defaultdict(int)
for i in range(n+1):
q, r = divmod(x*i, d)
a = i*(i-1)//2
b = i*(2*n-i-1)//2
a += q
b += q
L.append((a, r, 1))
L.append((b+1, r, -1))
L.sort()
ans = 0
for p, idx, b in L:
if C[idx] > 0:
ans += p - D[idx]
C[idx] += b
D[idx] = p
print(ans)
``` | output | 1 | 79,717 | 5 | 159,435 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.