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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Submitted Solution:
```
def count(n):
P = 60
m = [ 0, 0, 1, 1, 0, 1,-1, 1, 0, 0,
-1, 1, 0, 1,-1,-1, 0, 1, 0, 1,
0,-1,-1, 1, 0, 0,-1, 0, 0, 1,
1, 1, 0,-1,-1,-1, 0, 1,-1,-1,
0, 1, 1, 1, 0, 0,-1, 1, 0, 0,
0,-1, 0, 1, 0,-1, 0,-1,-1, 1 ]
c = 1
x = 3
for i in range(2, P):
if m[i]:
if x == 2:
if x**i > n:
x = 1
else:
x = int(pow(n, 1/i))
if (x + 1)**i == n:
x += 1
c += (x-1) * m[i]
return c
q = int(input())
for _ in range(q):
l, r = map(int, input().split())
ans = count(r) - count(l-1)
print(ans)
``` | instruction | 0 | 94,124 | 5 | 188,248 |
No | output | 1 | 94,124 | 5 | 188,249 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Submitted Solution:
```
q=int(input())
def root(x,n):
l=0
r=x
while(r-l>1):
mid=(r+l)//2
if(mid**n>x):
r=mid
else:
l=mid
return l
def calc(x):
if(x==0):
return 1
dp=[0]*70
sm=0
for i in range(62):
j=63-i
#dp[j]=root(x,j)
dp[j]=int(x**(1/j))
for m in range(2,1000):
if(j*m>63):
break
dp[j]-=dp[j*m]
sm+=dp[j]
return sm
for i in range(q):
l,r=map(int,input().split())
print(calc(r)-calc(l-1))
``` | instruction | 0 | 94,125 | 5 | 188,250 |
No | output | 1 | 94,125 | 5 | 188,251 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445 | instruction | 0 | 94,131 | 5 | 188,262 |
"Correct Solution:
```
n=int(input())
ans=10**n - 2*9**n + 8**n
print(ans%(10**9 + 7))
``` | output | 1 | 94,131 | 5 | 188,263 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445 | instruction | 0 | 94,132 | 5 | 188,264 |
"Correct Solution:
```
n=int(input())
m=((10**n)-(2*(9**n))+(8**n))%1000000007
print(m)
``` | output | 1 | 94,132 | 5 | 188,265 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445 | instruction | 0 | 94,133 | 5 | 188,266 |
"Correct Solution:
```
N=int(input())
ans=(10**N-9**N-9**N+8**N)%(10**9+7)
print(ans)
``` | output | 1 | 94,133 | 5 | 188,267 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445 | instruction | 0 | 94,134 | 5 | 188,268 |
"Correct Solution:
```
n=int(input())
print((10**n+8**n-2*9**n)%(10**9+7))
``` | output | 1 | 94,134 | 5 | 188,269 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445 | instruction | 0 | 94,135 | 5 | 188,270 |
"Correct Solution:
```
n=int(input())
a=10**n+8**n-2*(9**n)
print(a%(10**9+7))
``` | output | 1 | 94,135 | 5 | 188,271 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445 | instruction | 0 | 94,136 | 5 | 188,272 |
"Correct Solution:
```
n=int(input())
x=10**n
y=9**n
z=8**n
print((x-y*2+z)%(10**9+7))
``` | output | 1 | 94,136 | 5 | 188,273 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445 | instruction | 0 | 94,137 | 5 | 188,274 |
"Correct Solution:
```
N=int(input())
x=(10**N-2*(9**N)+8**N)%(10**9+7)
print(x)
``` | output | 1 | 94,137 | 5 | 188,275 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445 | instruction | 0 | 94,138 | 5 | 188,276 |
"Correct Solution:
```
n=int(input())
print((10**n-(2*9**n-8**n))%(10**9+7))
``` | output | 1 | 94,138 | 5 | 188,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n=int(input())
mod=10**9+7
print((10**n-(2*9**n)+8**n)%mod)
``` | instruction | 0 | 94,139 | 5 | 188,278 |
Yes | output | 1 | 94,139 | 5 | 188,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
MOD=10**9+7
n=int(input())
ans= 10**n - 9**n - 9**n + 8**n
print(ans%MOD)
``` | instruction | 0 | 94,140 | 5 | 188,280 |
Yes | output | 1 | 94,140 | 5 | 188,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
N=int(input())
print((10**N-8**N-(2*(9**N-8**N)))%(10**9+7))
``` | instruction | 0 | 94,141 | 5 | 188,282 |
Yes | output | 1 | 94,141 | 5 | 188,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n=int(input())
a=10**n-2*(9**n)+8**n
print(a%(10**9+7))
``` | instruction | 0 | 94,142 | 5 | 188,284 |
Yes | output | 1 | 94,142 | 5 | 188,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n=int(input())
print(pow(10,n,10**9+7)-2*pow(9,n,10**9+7)+pow(8,n,10**9+7))
``` | instruction | 0 | 94,143 | 5 | 188,286 |
No | output | 1 | 94,143 | 5 | 188,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n = int(input())
x = n*(n-1)*2(10**(n-2))
print(x%(10**9 + 7))
``` | instruction | 0 | 94,144 | 5 | 188,288 |
No | output | 1 | 94,144 | 5 | 188,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n = int(input())
if (n == 1)or(n==0):
print(0)
else:
if n==2:
print(2)
else:
ans = (10**(n-3))*54
print(ans)
``` | instruction | 0 | 94,145 | 5 | 188,290 |
No | output | 1 | 94,145 | 5 | 188,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n=int(input())
P=1000000007
print((pow(10,n,P)-pow(8,n,P)) % P)
``` | instruction | 0 | 94,146 | 5 | 188,292 |
No | output | 1 | 94,146 | 5 | 188,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
import numpy
n, m = map(int, input().split())
a = list(map(int, input().split()))
ahalf = [i//2 for i in a]
lcm = numpy.lcm.reduce(ahalf)
ans = 1 + (m - lcm) // (lcm * 2)
print(ans)
``` | instruction | 0 | 94,175 | 5 | 188,350 |
No | output | 1 | 94,175 | 5 | 188,351 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3 | instruction | 0 | 94,185 | 5 | 188,370 |
"Correct Solution:
```
def main():
import sys
input = sys.stdin.readline
p = int(input())
A = list(map(int, input().split()))
ans = [0] * p
for i, a in enumerate(A):
if not a:
continue
ans[-1] += 1
ij = 1
ans[0] = (ans[0] - ij)%p
for j in range(1, p):
ij = (ij * i)%p
ans[j] = (ans[j] - ij)%p
ans.reverse()
print(*ans)
if __name__ == '__main__':
main()
``` | output | 1 | 94,185 | 5 | 188,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
p = int(input())
a = [int(i) for i in input().split()]
ans = [0]*p
for i,j in enumerate(a):
if j == 0:
continue
ans[0] -= p-1
m = 1
for k in range(p):
ans[p-1-k] -= m
ans[p-1-k] %= p
m *= i
m %= p
print(*ans)
``` | instruction | 0 | 94,187 | 5 | 188,374 |
Yes | output | 1 | 94,187 | 5 | 188,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
#mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
def main():
p = int(ipt())
a = [int(i) for i in ipt().split()]
mod = p
#nCrをmodで割った余りを求める。Nに最大値を入れて使用。
N = 3000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
def cmb(n,r,mod=p):
if r<0 or r>n :
return 0
r = min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
for i in range(2,N+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod % i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
ans = [0]*p
for i in range(p):
if a[i]:
ans[0] += 1
sgn = -1
ji = 1
for j in range(p-1,-1,-1):
ans[j] += sgn*ji*cmb(p-1,j,p)
ji *= i
ji %= p
ans[j] %= p
sgn *= -1
print(" ".join(map(str,ans)))
return None
if __name__ == '__main__':
main()
``` | instruction | 0 | 94,188 | 5 | 188,376 |
Yes | output | 1 | 94,188 | 5 | 188,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
p = int(input())
aaa = list(map(int, input().split()))
coefs = [0] * p
coefs[0] = sum(aaa)
invs = [pow(x, p - 2, p) for x in range(p + 1)]
for i, a in enumerate(aaa):
if a == 0:
continue
b = 1
c = 1
for j in range(p - 1, -1, -1):
coefs[j] = (coefs[j] - b * c) % p
b = -b * i % p
c = c * j * invs[p - j] % p
print(*coefs)
``` | instruction | 0 | 94,189 | 5 | 188,378 |
Yes | output | 1 | 94,189 | 5 | 188,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
class Combination:
"""階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
def __init__(self, n, MOD):
self.fact = [1]
for i in range(1, n + 1):
self.fact.append(self.fact[-1] * i % MOD)
self.inv_fact = [0] * (n + 1)
self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
for i in reversed(range(n)):
self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
self.MOD = MOD
def inverse(self, k):
"""kの逆元を求める O(1)"""
return (self.inv_fact[k] * self.fact[k - 1]) % self.MOD
def factorial(self, k):
"""k!を求める O(1)"""
return self.fact[k]
def inverse_factorial(self, k):
"""k!の逆元を求める O(1)"""
return self.inv_fact[k]
def permutation(self, k, r):
"""kPrを求める O(1)"""
if k < r:
return 0
return (self.fact[k] * self.inv_fact[k - r]) % self.MOD
def combination(self, k, r):
"""kCrを求める O(1)"""
if k < r:
return 0
return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD
def combination2(self, k, r):
"""kCrを求める O(r)
kが大きいが、r <= nを満たしているときに使用
"""
if k < r:
return 0
res = 1
for l in range(r):
res *= (k - l)
res %= self.MOD
return (res * self.inv_fact[r]) % self.MOD
p = int(input())
a = list(map(int, input().split()))
comb = Combination(p - 1, p)
b = [0] * p
for i in range(p):
for j in range(p):
# (x - j) ^ (p - 1) の係数x^iの部分
tmp = pow(-j, (p - 1 - i), p) * comb.combination(p - 1, i)
b[i] -= a[j] * tmp
b[i] %= p
b[0] = a[0]
print(*b)
``` | instruction | 0 | 94,190 | 5 | 188,380 |
Yes | output | 1 | 94,190 | 5 | 188,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
p = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(p)]
B[0] = A[0]
for i in range(1, p):
B[p-i] = ((-1) * sum(A[1:]))%p
for j in range(p):
A[j] *= j
A[j] %= p
for i in range(p):
if i != p - 1:
print(B[i], end = ' ')
else:
print(B[i], end = '')
``` | instruction | 0 | 94,191 | 5 | 188,382 |
No | output | 1 | 94,191 | 5 | 188,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
p = int(input())
a = [int(item) for item in input().split()]
fac = [1] + [0] * (p - 1)
facinv = [1] + [0] * (p - 1)
for i in range(1, p):
fac[i] = fac[i-1] * i % p
facinv[i] = facinv[i-1] * pow(i, p-2, p) % p
# print(fac)
# print(facinv)
comb = [0] * p
for i in range(p):
comb[i] = fac[p-1] * facinv[i] * facinv[p-1-i] % p
# print(comb)
ans = [0] * p
ppowp = [[0] * (p + 1) for _ in range(p + 1)]
for i in range(p+1):
val = 1
for j in range(p+1):
ppowp[i][j] = val
val *= i
val %= p
for i, item in enumerate(a):
if item == 1:
ans[0] += 1
# Calc (i - x)**(p - 1)
for j in range(p):
# ans[j] -= pow(i, p-1-j, p) * pow(-1, j, p) * comb[j] % p
if j % 2 == 1:
ans[j] -= ppowp[i][p-1-j] * -1 * comb[j] % p
else:
ans[j] -= ppowp[i][p-1-j] * comb[j] % p
ans[j] %= p
print(" ".join([str(item) for item in ans]))
``` | instruction | 0 | 94,192 | 5 | 188,384 |
No | output | 1 | 94,192 | 5 | 188,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
#!/usr/bin/env python3
import sys
import functools
INF = float("inf")
MOD = 2 # type: int
def power(b, p):
if p == 0:
return 1
elif p == 1:
return b
elif p % 2 == 1:
return b*power(b, p-1)
else:
return power(b*b, p//2)
def solve(p: int, a: "List[int]"):
kaijo = [1]*p
kaijo_inv = [1]*p
for i in range(2, p):
kaijo[i] = (kaijo[i-1]*i) % p
kaijo_inv[i] = power(kaijo[i], p-2) % p
@functools.lru_cache(maxsize=None)
def cmb(n, r):
return (kaijo[n]*kaijo_inv[n-r]*kaijo_inv[r]) % p
b = [0]*p
for ai, av in enumerate(a):
if av == 1:
for i in range(p):
b[i] += -cmb(p-1, i) * power(-ai, p-i-1)
b[i] %= p
b[0] += 1
b[0] %= p
print(*b, sep=" ")
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
p = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(p-1-0+1)] # type: "List[int]"
solve(p, a)
if __name__ == '__main__':
main()
``` | instruction | 0 | 94,193 | 5 | 188,386 |
No | output | 1 | 94,193 | 5 | 188,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
def f_polynomal_construction(P, A):
class Combination(object):
"""参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb"""
__slots__ = ["mod", "factorial", "inverse"]
def __init__(self, max_n: int = 10**6, mod: int = 10**9 + 7):
fac, inv = [1], []
fac_append, inv_append = fac.append, inv.append
for i in range(1, max_n + 1):
fac_append(fac[-1] * i % mod)
inv_append(pow(fac[-1], mod - 2, mod))
for i in range(max_n, 0, -1):
inv_append(inv[-1] * i % mod)
self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]
def combination(self, n, r):
if n < 0 or r < 0 or n < r:
return 0
return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod
combination = Combination(P - 1, P)
comb = [combination.combination(P - 1, i) for i in range(P)]
ans = [0] * P
for j, a in enumerate(A):
if a == 0:
continue
# 1-(x-j)^{p-1} = 1 - \sum_{k=0}^{p-1} comb(p-1, p-k-1) * x^{p-k-1} * (-j)^k
# なので、定数項に1を足し、x^k の係数から各々引く
# pow(-j, k, P) としたいが、時間がかかるので tmp に掛けていくことにする
ans[0] += 1
tmp = 1
for k in range(P):
index = P - k - 1
# if k > 0:
# tmp *= (-j)
# tmp %= P
# ans[index] -= comb[index] * tmp
ans[index] -= comb[index] * pow(-j, k, P)
ans[index] %= P
return ' '.join(map(str, ans))
P = int(input())
A = [int(i) for i in input().split()]
print(f_polynomal_construction(P, A))
``` | instruction | 0 | 94,194 | 5 | 188,388 |
No | output | 1 | 94,194 | 5 | 188,389 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4 | instruction | 0 | 94,227 | 5 | 188,454 |
"Correct Solution:
```
N = int(input())
X_list = list(map(int, input().split()))
X_list_min = sorted(X_list)
for i in range(N):
if X_list_min[N//2-1] >= X_list[i]:
print(X_list_min[N//2])
else:
print(X_list_min[N//2-1])
``` | output | 1 | 94,227 | 5 | 188,455 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4 | instruction | 0 | 94,228 | 5 | 188,456 |
"Correct Solution:
```
import copy
N = int(input())
X = []
X = [int(i) for i in input().split()]
Y = copy.deepcopy(X)
Y.sort()
largeMedian = Y[int(N / 2)]
smallMedian = Y[int(N / 2)-1]
for i in range(N):
if X[i] <= smallMedian:
X[i] = largeMedian
else:
X[i] = smallMedian
for i in range(N):
print(X[i])
``` | output | 1 | 94,228 | 5 | 188,457 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4 | instruction | 0 | 94,229 | 5 | 188,458 |
"Correct Solution:
```
n = int(input())
x = list(map(int, input().split()))
use = x[::]
use.sort()
l = use[n//2-1]
r = use[n//2]
for i in x:
if i <= l:
print(r)
else:
print(l)
``` | output | 1 | 94,229 | 5 | 188,459 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4 | instruction | 0 | 94,230 | 5 | 188,460 |
"Correct Solution:
```
n=int(input())
x=list(map(int,input().split()))
xx=sorted(x)
for i in range(n):
if x[i]<=xx[n//2-1]:
print(xx[n//2])
else:
print(xx[n//2-1])
``` | output | 1 | 94,230 | 5 | 188,461 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4 | instruction | 0 | 94,231 | 5 | 188,462 |
"Correct Solution:
```
N = int(input())
X = list(map(int,input().split()))
S = X[:]
S.sort()
C1 = S[(N//2)-1]
C2 = S[N//2]
for x in X:
if x >= C2:
print(C1)
else:
print(C2)
``` | output | 1 | 94,231 | 5 | 188,463 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4 | instruction | 0 | 94,232 | 5 | 188,464 |
"Correct Solution:
```
N = int(input())
X = [int(i) for i in input().split()]
Y = sorted(X)
left = Y[N//2 -1]
right = Y[N//2 ]
for x in X:
if x<=left:
print(right)
else:print(left)
``` | output | 1 | 94,232 | 5 | 188,465 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4 | instruction | 0 | 94,233 | 5 | 188,466 |
"Correct Solution:
```
n = int(input())
cn = n//2
lis = list(map(int,input().split()))
slis = sorted(lis)
if slis[cn-1] == slis[cn]:
for i in range(len(lis)):
print(slis[cn])
else:
for item in lis:
if item >= slis[cn]:
print(slis[cn-1])
else:
print(slis[cn])
``` | output | 1 | 94,233 | 5 | 188,467 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4 | instruction | 0 | 94,234 | 5 | 188,468 |
"Correct Solution:
```
n, *lst = map(int, open(0).read().split())
a, b = sorted(lst)[n // 2 - 1:n // 2 + 1]
if a == b:
print(*[a for _ in range(n)], sep='\n')
else:
print(*[b if i <= a else a for i in lst], sep='\n')
``` | output | 1 | 94,234 | 5 | 188,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
for i in range(N):
if X[i] < Y[N//2]:
print(Y[N // 2])
else:
print(Y[(N-1) // 2])
``` | instruction | 0 | 94,235 | 5 | 188,470 |
Yes | output | 1 | 94,235 | 5 | 188,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N = int(input())
arr = list(map(int, input().split()))
arr2 = sorted(arr)
mean1 = arr2[N//2-1]
mean2 = arr2[N//2]
for a in arr:
if a <= mean1:
print(mean2)
else:
print(mean1)
``` | instruction | 0 | 94,236 | 5 | 188,472 |
Yes | output | 1 | 94,236 | 5 | 188,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N = int(input())
Xs = list(map(int, input().split()))
M1, M2 = sorted(Xs)[N // 2 - 1: N // 2 + 1]
for X in Xs:
if X < M2:
print(M2)
else:
print(M1)
``` | instruction | 0 | 94,237 | 5 | 188,474 |
Yes | output | 1 | 94,237 | 5 | 188,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
def find(A):
X=[(A[i],i) for i in range(len(A))]
X=sorted(X)
ans=[0]*len(X)
p1=(len(A)-1)//2
p2=len(A)//2
#print(p1,p2)
for i in range(len(X)):
a,b=X[i]
if i<p2:
ans[b]=X[p2][0]
else:
ans[b]=X[p1][0]
return ans
input()
A=[str(x) for x in find(list(map(int,input().strip().split(" "))))]
print("\n".join(A))
``` | instruction | 0 | 94,238 | 5 | 188,476 |
Yes | output | 1 | 94,238 | 5 | 188,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
a = int(input())
ar = list(map(int,input().split(" ")))
b = a // 2 - 1
for i in range(a):
br = ar[0:i] + ar[i+1:a]
br.sort()
print(br[b])
``` | instruction | 0 | 94,239 | 5 | 188,478 |
No | output | 1 | 94,239 | 5 | 188,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N=int(input())
inp=list(map(int, input().strip().split(' ')))
med = int(N/2)
for i in range(N):
X=[]
for j in range(N):
if i!=j:
X.append(inp[j])
Xsort = sorted(X)
print(Xsort[med-1])
``` | instruction | 0 | 94,240 | 5 | 188,480 |
No | output | 1 | 94,240 | 5 | 188,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
from numpy import median
from copy import deepcopy
n = int(input())
x = list(map(int,input().split()))
sx = x.sorted()
newl = deepcopy(sx)
del newl[0]
bigm = median(newl)
newl = deepcopy(sx)
del newl[-1]
minm = median(newl)
med = median(x)
for i in x:
if i > med:
print(minm)
else:
print(maxm)
``` | instruction | 0 | 94,241 | 5 | 188,482 |
No | output | 1 | 94,241 | 5 | 188,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N = int(input())
b = [int(i) for i in input().split()]
b.sort()
s = b[(N-1)//2]
l = b[N//2]
for i in range(N):
if i > s:
print(s)
else:
print(l)
``` | instruction | 0 | 94,242 | 5 | 188,484 |
No | output | 1 | 94,242 | 5 | 188,485 |
Provide a correct Python 3 solution for this coding contest problem.
Range Count Query
Given the sequence a_1, a_2, .., a_N.
In the query, answer the number of terms whose value is l or more and r or less.
input
N Q
a_1 a_2 ... a_N
l_1 r_1
l_2 r_2
::
l_q r_q
output
ans_1
ans_2
::
ans_q
On line i, output the answer to the i-th query, that is, the number of j such as l_i \ leq a_j \ leq r_i.
Constraint
* 1 \ leq N, Q \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9
* 1 \ leq l_i \ leq r_i \ leq 10 ^ 9
Input example
6 3
8 6 9 1 2 1
2 8
1 7
3 5
Output example
3
Four
0
Example
Input
6 3
8 6 9 1 2 1
2 8
1 7
3 5
Output
3
4
0 | instruction | 0 | 94,379 | 5 | 188,758 |
"Correct Solution:
```
def num():
return int(input())
def nums():
return list(map(int,input().split()))
"""
N = num()
A = nums()
print(A.index(min(A))+1)
"""
"""
N = num()
A = set(nums())
print(len(A))
"""
def get_near_index(sorted_l,val,last):
left = 0
right = len(sorted_l) - 1
while left <= right:
mid = (right + left) // 2
if sorted_l[mid] == val:
return mid if last else mid
elif sorted_l[mid] > val:
right = mid -1
else:
left = mid + 1
return right if last else left
N,Q = nums()
A = nums()
A.sort()
L,R = [],[]
for i in range(Q):
li,ri = nums()
L.append(li)
R.append(ri)
for l,r in zip(L,R):
l_idx = get_near_index(A,l,0)
r_idx = get_near_index(A,r,1)
print(r_idx-l_idx+1)
``` | output | 1 | 94,379 | 5 | 188,759 |
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:
* find(s, t): report the minimum element in as, as+1, . . . ,at.
* update(i, x): change ai to x.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* If comi is 0, then 0 ≤ xi < n, 0 ≤ yi < 231-1.
* If comi is 1, then 0 ≤ xi < n, 0 ≤ yi < n.
Input
n q
com0 x0 y0
com1 x1 y1
...
comq−1 xq−1 yq−1
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
Output
For each find operation, print the minimum element.
Examples
Input
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
Output
1
2
Input
1 3
1 0 0
0 0 5
1 0 0
Output
2147483647
5 | instruction | 0 | 94,380 | 5 | 188,760 |
"Correct Solution:
```
class segtree:
def __init__(self, n, operator, identity):
"""
n:データ配列のサイズ
operator:演算子(モノイド)。関数オブジェクト 最小=min, 最大=max
identity:演算子に対応する単位元
"""
nb = bin(n)[2:] #2進数に変換して先頭の0bを取り除く
bc = sum([int(digit) for digit in nb]) #bitで1が立ってる数。これが1のときはちょうど2^nb.そうじゃないときは、2^nb<n<2^(nb+1)
if bc == 1: #2^nbなら
self.num_end_leaves = 2**(len(nb)-1) #最下段の葉っぱは2^nb個
else:#そうじゃないなら2^(nb+1)確保
self.num_end_leaves = 2**(len(nb))
self.array = [identity for i in range(self.num_end_leaves * 2)] #単位元で初期化
self.identity = identity
self.operator = operator
#後で使うので単位元と演算子を持っておく
def update(self,x,val):
"""
x:代入場所
val:代入する値
"""
actual_x = x+self.num_end_leaves #1-indexの末端の葉のindexがどこから始まるか分を足す(例えばデータ配列サイズ4のとき木配列サイズは8で、後半部はindex4から始まる。
self.array[actual_x] = val #値を更新する
while actual_x > 0 :
actual_x = actual_x//2#親を見る
self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])#あたらしい子をつかって親を更新
def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
"""
q_left:クエリ区間の左
q_right:クエリ区間の右
arr_ind:木配列のインデックス。最初は親なので1
leaf_left:木配列インデックスに対して、それが表す葉がカバーする範囲の左
depth:木配列での深さ。カバー範囲の広さの計算に使用
"""
width_of_floor = self.num_end_leaves//(2**depth) #今の葉のカバー幅
leaf_right = leaf_left+width_of_floor-1 #左端とカバー幅から今の葉のカバー範囲の右を求める。
if leaf_left > q_right or leaf_right < q_left:
return self.identity #クエリ領域と葉が関係ないなら単位元を返す
elif leaf_left >= q_left and leaf_right <= q_right:
return self.array[arr_ind] #クエリ領域に葉がすっぽり入ってるなら、葉の値を返す
else: #そうじゃないならば、子を見る
val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)#子の左
val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)#子の右
return self.operator(val_l,val_r)#子をマージする演算をする。
N, Q = map(int,input().split())
s_tree = segtree(N,min,2**31-1) #10**5までの配列なので適当に単位元は10**9
arr = [2**31-1] * N
#print(arr)
for i,a in enumerate(arr):
s_tree.update(i,a)
for i in range(Q):
a, x, y = map(int,input().split())
if a == 0:
s_tree.update(x,y)
else:
print(s_tree.get(x,y))
``` | output | 1 | 94,380 | 5 | 188,761 |
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:
* find(s, t): report the minimum element in as, as+1, . . . ,at.
* update(i, x): change ai to x.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* If comi is 0, then 0 ≤ xi < n, 0 ≤ yi < 231-1.
* If comi is 1, then 0 ≤ xi < n, 0 ≤ yi < n.
Input
n q
com0 x0 y0
com1 x1 y1
...
comq−1 xq−1 yq−1
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
Output
For each find operation, print the minimum element.
Examples
Input
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
Output
1
2
Input
1 3
1 0 0
0 0 5
1 0 0
Output
2147483647
5 | instruction | 0 | 94,381 | 5 | 188,762 |
"Correct Solution:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
output:
1
2
"""
import math
import sys
INIT_MAX = pow(2, 31) - 1
class SegmentTree(object):
__slots__ = ('dat', 'tree_range')
def __init__(self, n):
"""
Init a SegmentTree with update and find for range minimum queries.
"""
self.tree_range = pow(2, math.ceil(math.log2(n)))
self.dat = [INIT_MAX] * (2 * self.tree_range - 1)
# let A[k]=a
def update(self, k, a):
k += self.tree_range - 1
self.dat[k] = a
while k > 0:
k = (k - 1) // 2
self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])
# get min(A[s] A[s+1] ... A[t])
def find(self, s, t, k=0, left=0, right=float('inf')):
if right <= s or t <= left:
return INIT_MAX
elif s <= left <= right <= t:
return self.dat[k]
else:
vl = self.find(s, t, k * 2 + 1, left, (left + right) // 2)
vr = self.find(s, t, k * 2 + 2, (left + right) // 2, right)
return min(vl, vr)
def cmd_exec(cmd_list, n_num):
case = SegmentTree(n_num)
end = pow(2, math.ceil(math.log2(n_num)))
for query in cmd_list:
cmd, ele_1, ele_2 = map(int, query)
if cmd == 0:
case.update(ele_1, ele_2)
elif cmd == 1:
assert ele_1 <= ele_2
res = case.find(s=ele_1, t=ele_2 + 1, right=end)
print(res)
return None
def solve():
_input = sys.stdin.readlines()
n_num, q_num = map(int, _input[0].split())
q_list = map(lambda x: x.split(), _input[1:])
cmd_exec(q_list, n_num)
return None
if __name__ == '__main__':
solve()
``` | output | 1 | 94,381 | 5 | 188,763 |
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:
* find(s, t): report the minimum element in as, as+1, . . . ,at.
* update(i, x): change ai to x.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* If comi is 0, then 0 ≤ xi < n, 0 ≤ yi < 231-1.
* If comi is 1, then 0 ≤ xi < n, 0 ≤ yi < n.
Input
n q
com0 x0 y0
com1 x1 y1
...
comq−1 xq−1 yq−1
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
Output
For each find operation, print the minimum element.
Examples
Input
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
Output
1
2
Input
1 3
1 0 0
0 0 5
1 0 0
Output
2147483647
5 | instruction | 0 | 94,382 | 5 | 188,764 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=2**31-1
class SegTreeMin:
"""
以下のクエリを処理する
1.update: i番目の値をxに更新する
2.get_min: 区間[l, r)の最小値を得る
"""
def __init__(self, n):
"""
:param n: 要素数
"""
self.n = n
# nより大きい2の冪数
n2 = 1
while n2 < n:
n2 <<= 1
self.n2 = n2
self.tree = [INF] * (n2 << 1)
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.n2
self.tree[i] = x
while i > 1:
self.tree[i >> 1] = x = min(x, self.tree[i ^ 1])
i >>= 1
def get_min(self, a, b):
"""
[a, b)の最小値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
return self._get_min(a, b, 1, 0, self.n2)
def _get_min(self, a, b, k, l, r):
"""
[a, b)の最小値を得る内部関数
:param k: 現在調べている区間のtree内index
:param l, r: kが表す区間の左右端index [l, r)
:return: kが表す区間と[a, b)の共通区間内での最小値。共通区間を持たない場合はINF
"""
# 範囲外ならINF
if r <= a or b <= l:
return INF
# [a,b)が完全に[l,r)を包含するならtree[k]の値を採用
if a <= l and r <= b:
return self.tree[k]
# 一部だけ範囲内なら2つに分けて再帰的に調査
m = (l + r) // 2
return min(
self._get_min(a, b, k << 1, l, m),
self._get_min(a, b, (k << 1) + 1, m, r)
)
N,Q=MAP()
st=SegTreeMin(N)
for _ in range(Q):
com,x,y=MAP()
if com==0:
st.update(x, y)
else:
print(st.get_min(x, y+1))
``` | output | 1 | 94,382 | 5 | 188,765 |
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:
* find(s, t): report the minimum element in as, as+1, . . . ,at.
* update(i, x): change ai to x.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* If comi is 0, then 0 ≤ xi < n, 0 ≤ yi < 231-1.
* If comi is 1, then 0 ≤ xi < n, 0 ≤ yi < n.
Input
n q
com0 x0 y0
com1 x1 y1
...
comq−1 xq−1 yq−1
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
Output
For each find operation, print the minimum element.
Examples
Input
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
Output
1
2
Input
1 3
1 0 0
0 0 5
1 0 0
Output
2147483647
5 | instruction | 0 | 94,383 | 5 | 188,766 |
"Correct Solution:
```
import sys;
def init(n_):
length = 1;
while(length < n_):
length*=2
element=[0]*(2*length-1)
for i in range(2*length-1):
element[i] = initial
return element,length
def update(k,a,element):
k+=n-1
element[k]=a
while(k > 0):
k = (int)((k-1)/2)
element[k] = min(element[k*2+1],element[k*2+2])
def findmin(a, b):
return findquery(a,b+1,0,0,n)
def findquery(a, b, k, l, r):
if(r <= a or b <= l):
return initial
if(a <= l and r <= b):
return element[k]
vl = findquery(a,b,k*2+1,l,(int)((l+r)/2+0.5))
vr = findquery(a,b,k*2+2,(int)((l+r)/2),r)
return min(vl,vr)
n,q = map(int, input().split());
initial = pow(2,31)-1
element,n = init(n)
for i in range(q):
query,key,value = map(int, input().split());
if(query == 0):
update(key,value,element)
else :
print(findmin(key,value))
``` | output | 1 | 94,383 | 5 | 188,767 |
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:
* find(s, t): report the minimum element in as, as+1, . . . ,at.
* update(i, x): change ai to x.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 100000
* If comi is 0, then 0 ≤ xi < n, 0 ≤ yi < 231-1.
* If comi is 1, then 0 ≤ xi < n, 0 ≤ yi < n.
Input
n q
com0 x0 y0
com1 x1 y1
...
comq−1 xq−1 yq−1
In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).
Output
For each find operation, print the minimum element.
Examples
Input
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
Output
1
2
Input
1 3
1 0 0
0 0 5
1 0 0
Output
2147483647
5 | instruction | 0 | 94,384 | 5 | 188,768 |
"Correct Solution:
```
INF = 2 ** 31 - 1
class SegmentTree:
def __init__(self, n):
self.N = 1
while self.N < n:
self.N *= 2
self.tree = [INF] * (self.N * 2 - 1)
# O(ln(n))
def update(self, i, x):
i += self.N - 1
self.tree[i] = x
while i > 0:
i = (i-1) // 2
self.tree[i] = min(self.tree[i*2+1], self.tree[i*2+2])
def find(self, a, b, k, l, r):
"""[a, b), ノードkが[l, r)を担当する"""
if r <= a or b <= l:
return INF
if a <= l and r <= b:
return self.tree[k]
else:
c1 = self.find(a, b, 2*k+1, l, (r+l)//2)
c2 = self.find(a, b, 2*k+2, (l+r)//2, r)
return min(c1, c2)
import sys
input = sys.stdin.readline
from operator import itemgetter
def main():
n, q = map(int, input().strip().split())
st = SegmentTree(n)
for _ in range(q):
com, x, y = map(int, input().strip().split())
if com:
print(st.find(x, y+1, 0, 0, st.N))
else:
st.update(x, y)
if __name__ == '__main__':
main()
``` | output | 1 | 94,384 | 5 | 188,769 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.