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.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843 | instruction | 0 | 17,541 | 5 | 35,082 |
"Correct Solution:
```
a,b=2,1
for i in[0]*int(input()):a,b=b,a+b
print(a)
``` | output | 1 | 17,541 | 5 | 35,083 |
Provide a correct Python 3 solution for this coding contest problem.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843 | instruction | 0 | 17,542 | 5 | 35,084 |
"Correct Solution:
```
N = int(input())
a, b = 1, 2
for _ in range(N):
a, b = a + b, a
print(b)
``` | output | 1 | 17,542 | 5 | 35,085 |
Provide a correct Python 3 solution for this coding contest problem.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843 | instruction | 0 | 17,543 | 5 | 35,086 |
"Correct Solution:
```
L = [2,1]
n = int(input())
for i in range(2,n+1):
L.append(L[i-1]+L[i-2])
print(L[n])
``` | output | 1 | 17,543 | 5 | 35,087 |
Provide a correct Python 3 solution for this coding contest problem.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843 | instruction | 0 | 17,544 | 5 | 35,088 |
"Correct Solution:
```
a = 2
b = 1
for i in range(int(input())):
a, b = b, a + b
print(a)
``` | output | 1 | 17,544 | 5 | 35,089 |
Provide a correct Python 3 solution for this coding contest problem.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843 | instruction | 0 | 17,545 | 5 | 35,090 |
"Correct Solution:
```
N = int(input())
x = 2
y = 1
for _ in range(N):
x, y = y, x + y
print(x)
``` | output | 1 | 17,545 | 5 | 35,091 |
Provide a correct Python 3 solution for this coding contest problem.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843 | instruction | 0 | 17,546 | 5 | 35,092 |
"Correct Solution:
```
a,b=2,1;exec('a,b=b,a+b;'*int(input()));print(a)
``` | output | 1 | 17,546 | 5 | 35,093 |
Provide a correct Python 3 solution for this coding contest problem.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843 | instruction | 0 | 17,547 | 5 | 35,094 |
"Correct Solution:
```
x=[2,1]
for _ in range(100):
x.append(x[-2]+x[-1])
print(x[int(input())])
``` | output | 1 | 17,547 | 5 | 35,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843
Submitted Solution:
```
L=[2,1]
for _ in range(int(input())-1):
L.append(L[-2]+L[-1])
print(L[-1])
``` | instruction | 0 | 17,548 | 5 | 35,096 |
Yes | output | 1 | 17,548 | 5 | 35,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843
Submitted Solution:
```
n=int(input())
l=[2,1]
for i in range(n-1):
l[i%2]=l[0]+l[1]
print(l[n%2])
``` | instruction | 0 | 17,549 | 5 | 35,098 |
Yes | output | 1 | 17,549 | 5 | 35,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843
Submitted Solution:
```
n=int(input())
L=[2,1]
for i in range(n-1):
L.append(L[i]+L[i+1])
print(L[-1])
``` | instruction | 0 | 17,550 | 5 | 35,100 |
Yes | output | 1 | 17,550 | 5 | 35,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843
Submitted Solution:
```
a, b = 2,1
n = int(input())
for i in range(n-1):
a, b = b, a+b
print(b)
``` | instruction | 0 | 17,551 | 5 | 35,102 |
Yes | output | 1 | 17,551 | 5 | 35,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843
Submitted Solution:
```
# -*- coding:utf-8 -*-
def solve():
N = int(input())
L0 = 2
L1 = 1
i = 2
while True:
ans = L0 + L1
if i == N:
break
L0 = L1
L1 = ans
print(ans)
if __name__ == "__main__":
solve()
``` | instruction | 0 | 17,552 | 5 | 35,104 |
No | output | 1 | 17,552 | 5 | 35,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843
Submitted Solution:
```
import sympy
print([sympy.lucas(i) for i in range(1, int(input())+1)][-1])
``` | instruction | 0 | 17,553 | 5 | 35,106 |
No | output | 1 | 17,553 | 5 | 35,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843
Submitted Solution:
```
num = list(range(86))
num[0] = 2
num[1] = 1
for i in range(2,86):
num[i] = num[i-2] + num[i-1]
print(num[int(input())])
``` | instruction | 0 | 17,554 | 5 | 35,108 |
No | output | 1 | 17,554 | 5 | 35,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the N-th Lucas number.
Examples
Input
5
Output
11
Input
86
Output
939587134549734843
Submitted Solution:
```
def lucas(n):
if n == 0:
return 2
elif n == 1:
return 1
else:
a = lucas(n-1)
b = lucas(n-2)
c = a+b
return(c)
``` | instruction | 0 | 17,555 | 5 | 35,110 |
No | output | 1 | 17,555 | 5 | 35,111 |
Provide a correct Python 3 solution for this coding contest problem.
Min Element
Given the sequence a_1, a_2, .., a_N.
Find the minimum number in this sequence.
If the minimum value is in more than one place, answer the one with the lowest number.
input
N
a_1 a_2 ... a_N
output
Output the smallest i such that a_i is the minimum value in the sequence.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9
Input example
6
8 6 9 1 2 1
Output example
Four
Example
Input
6
8 6 9 1 2 1
Output
4 | instruction | 0 | 17,655 | 5 | 35,310 |
"Correct Solution:
```
N = int(input())
a = list(map(int,input().split()))
num = min(a)
for i in range(N):
if a[i] == num:
print(i+1)
exit()
``` | output | 1 | 17,655 | 5 | 35,311 |
Provide a correct Python 3 solution for this coding contest problem.
Min Element
Given the sequence a_1, a_2, .., a_N.
Find the minimum number in this sequence.
If the minimum value is in more than one place, answer the one with the lowest number.
input
N
a_1 a_2 ... a_N
output
Output the smallest i such that a_i is the minimum value in the sequence.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9
Input example
6
8 6 9 1 2 1
Output example
Four
Example
Input
6
8 6 9 1 2 1
Output
4 | instruction | 0 | 17,656 | 5 | 35,312 |
"Correct Solution:
```
N = int(input())
a = list(map(int, input().split()))
mina = min(a)
ans = a.index(mina)
print(ans + 1)
``` | output | 1 | 17,656 | 5 | 35,313 |
Provide a correct Python 3 solution for this coding contest problem.
Min Element
Given the sequence a_1, a_2, .., a_N.
Find the minimum number in this sequence.
If the minimum value is in more than one place, answer the one with the lowest number.
input
N
a_1 a_2 ... a_N
output
Output the smallest i such that a_i is the minimum value in the sequence.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9
Input example
6
8 6 9 1 2 1
Output example
Four
Example
Input
6
8 6 9 1 2 1
Output
4 | instruction | 0 | 17,657 | 5 | 35,314 |
"Correct Solution:
```
n = int(input())
l = list(map(int, input().split()))
m = 100000000000000000
index = int()
for i in range(n):
if m > l[i]:
m = l[i]
index = i
print(index+ 1)
``` | output | 1 | 17,657 | 5 | 35,315 |
Provide a correct Python 3 solution for this coding contest problem.
Min Element
Given the sequence a_1, a_2, .., a_N.
Find the minimum number in this sequence.
If the minimum value is in more than one place, answer the one with the lowest number.
input
N
a_1 a_2 ... a_N
output
Output the smallest i such that a_i is the minimum value in the sequence.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9
Input example
6
8 6 9 1 2 1
Output example
Four
Example
Input
6
8 6 9 1 2 1
Output
4 | instruction | 0 | 17,658 | 5 | 35,316 |
"Correct Solution:
```
N = int(input())
a = [int(x) for x in input().split()]
print(a.index(min(a)) + 1)
``` | output | 1 | 17,658 | 5 | 35,317 |
Provide a correct Python 3 solution for this coding contest problem.
Min Element
Given the sequence a_1, a_2, .., a_N.
Find the minimum number in this sequence.
If the minimum value is in more than one place, answer the one with the lowest number.
input
N
a_1 a_2 ... a_N
output
Output the smallest i such that a_i is the minimum value in the sequence.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9
Input example
6
8 6 9 1 2 1
Output example
Four
Example
Input
6
8 6 9 1 2 1
Output
4 | instruction | 0 | 17,659 | 5 | 35,318 |
"Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
print(a.index(min(a)) + 1)
``` | output | 1 | 17,659 | 5 | 35,319 |
Provide a correct Python 3 solution for this coding contest problem.
Min Element
Given the sequence a_1, a_2, .., a_N.
Find the minimum number in this sequence.
If the minimum value is in more than one place, answer the one with the lowest number.
input
N
a_1 a_2 ... a_N
output
Output the smallest i such that a_i is the minimum value in the sequence.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9
Input example
6
8 6 9 1 2 1
Output example
Four
Example
Input
6
8 6 9 1 2 1
Output
4 | instruction | 0 | 17,660 | 5 | 35,320 |
"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)
``` | output | 1 | 17,660 | 5 | 35,321 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1 | instruction | 0 | 17,662 | 5 | 35,324 |
"Correct Solution:
```
class UnionFind:
def __init__(self, n=0):
self.d = [-1]*n
def root(self, x):
if self.d[x] < 0:
return x
self.d[x] = self.root(self.d[x])
return self.d[x]
def unite(self, x, y):
x, y = self.root(x), self.root(y)
if x == y:
return False
if x > y:
x, y = y, x
self.d[x] += self.d[y]
self.d[y] = x
return True
def same(self, x, y):
return self.root(x) == self.root(y)
def size(self, x):
return -self.d[self.root(x)]
def main():
n, _, *A = map(int, open(0).read().split())
uf = UnionFind(n)
for a, x, y in zip(*[iter(A)]*3):
if a == 0:
uf.unite(x, y)
else:
print(1 if uf.same(x, y) else 0)
if __name__ == '__main__':
main()
``` | output | 1 | 17,662 | 5 | 35,325 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1 | instruction | 0 | 17,664 | 5 | 35,328 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(2*10**6)
class UF():
def __init__(self, num):
self.par = [-1]*num
self.size = [1]*num
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
rx, ry = self.find(x), self.find(y)
if rx == ry:
return 0
if rx < ry:
rx, ry = ry, rx
self.par[rx] += self.par[ry]
self.par[rx] = ry
self.size[rx] += self.size[ry]
return 1
def check(self, x, y):
return self.find(x) == self.find(y)
n, q = map(int, input().split())
T = UF(n)
for _ in range(q):
c, x, y = map(int, input().split())
if c == 0:
T.union(x, y)
else:
print(int(T.check(x, y)))
``` | output | 1 | 17,664 | 5 | 35,329 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1 | instruction | 0 | 17,665 | 5 | 35,330 |
"Correct Solution:
```
#!/usr/bin/env python3
from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')
n, q = map(int, input().split())
queries = []
for _ in range(q):
com, x, y = map(int, input().split())
queries.append([com, x, y])
parents = [i for i in range(n)]
size = [1 for _ in range(n)]
def find(x):
if x != parents[x]:
parents[x] = find(parents[x])
return parents[x]
def same(x, y):
return find(x) == find(y)
def unite(x, y):
x_root = find(x)
y_root = find(y)
if x_root == y_root:
return
if x_root < y_root:
x_root, y_root = y_root, x_root
parents[y_root] = x_root
size[x_root] += size[y_root]
for com, x, y in queries:
if com == 0:
unite(x, y)
else:
if same(x, y):
print(1)
else:
print(0)
``` | output | 1 | 17,665 | 5 | 35,331 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1 | instruction | 0 | 17,666 | 5 | 35,332 |
"Correct Solution:
```
n,q = map(int,input().split())
par = [-1]*(n+1)
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return False
else:
if par[x] > par[y]:
x,y = y,x
par[x] += par[y]
par[y] = x
return True
def same(x,y):
return find(x) == find(y)
def size(x):
return -par[find(x)]
for _ in range(q):
c,x,y = map(int,input().split())
if c == 0:
unite(x,y)
else:
if same(x,y):print(1)
else:print(0)
``` | output | 1 | 17,666 | 5 | 35,333 |
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 disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**5)
def solve():
n, q = map(int, sys.stdin.readline().split())
uf = UnionFind(n)
ans = []
for lp in range(q):
c, x, y = map(int, sys.stdin.readline().split())
if c == 0:
uf.unite(x, y)
else:
ans.append(1 if uf.is_same(x, y) else 0)
print(*ans, sep='\n')
class UnionFind:
def __init__(self, n):
self.ds = [i for i in range(n)]
self.root = [i for i in range(n)]
# self.rank = [0] * n
def find_root(self, x):
if x != self.root[x]:
self.root[x] = self.find_root(self.root[x])
return self.root[x]
def is_same(self, x, y):
return self.find_root(x) == self.find_root(y)
def unite(self, x, y):
p = self.find_root(x)
q = self.find_root(y)
self.root[p] = q
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
if __name__ == '__main__':
solve()
``` | instruction | 0 | 17,670 | 5 | 35,340 |
Yes | output | 1 | 17,670 | 5 | 35,341 |
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 disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1
Submitted Solution:
```
import sys
readline = sys.stdin.readline
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1]*n
self.rank = [0]*n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.parents[x] = y
else:
self.parents[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
n, q = map(int, readline().split())
uf = UnionFind(n)
for _ in range(q):
com, x, y = map(int, readline().split())
if com == 0:
uf.union(x, y)
else:
px = uf.find(x)
py = uf.find(y)
print((px == py)*1)
if __name__ == "__main__":
main()
``` | instruction | 0 | 17,671 | 5 | 35,342 |
Yes | output | 1 | 17,671 | 5 | 35,343 |
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 disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1
Submitted Solution:
```
COM_UNITE = 0
COM_SAME = 1
class UnionFind():
def __init__(self, n):
self.parent = list(range(n))
self.rank = [0] * n
def find(self, x):
if self.parent[x] == x:
return x
else:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def unite(self, x, y):
x, y = self.find(x), self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.parent[x] = y
else:
self.parent[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
if __name__ == '__main__':
n, q = (int(s) for s in input().split())
tree = UnionFind(n)
for i in range(q):
com, x, y = (int(s) for s in input().split())
if com == COM_UNITE:
tree.unite(x, y)
else:
print(int(tree.same(x, y)))
``` | instruction | 0 | 17,672 | 5 | 35,344 |
Yes | output | 1 | 17,672 | 5 | 35,345 |
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 disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1
Submitted Solution:
```
# -*- coding:utf-8 -*-
def unite(list_s, x, y):
for idx, elem in enumerate(list_s):
if x in list_s[idx]:
x_list = list_s[idx]
if y in list_s[idx]:
for num in list_s[idx]:
x_list.append(num)
del list_s[idx]
return list_s
def same(list_s, x, y):
result_flg = 0
for idx, elem in enumerate(list_s):
if x in list_s[idx]:
if y in list_s[idx]:
result_flg = 1
break
return result_flg
n, q = map(int, input().split(' '))
S = [[y] for y in [x for x in range(n)]]
for i in range(q):
com, x, y = map(int, input().split(' '))
if com == 0:
S = unite(S, x, y)
elif com == 1:
print(same(S, x, y))
``` | instruction | 0 | 17,673 | 5 | 35,346 |
No | output | 1 | 17,673 | 5 | 35,347 |
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 disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1
Submitted Solution:
```
class UnionFind:
def __init__(self, n):
self.rank = [0]*n
self.parent = [i for i in range(n)]
def find(self, x):
if self.parent[x] == x:
return x
else:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def merge(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.parent[y] = x
elif self.rank[x] > self.rank[y]:
self.parent[x] = y
else:
self.parent[x] = y
self.rank[y] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
n, q = map(int, input().split())
uf = UnionFind(n)
for i in range(q):
com, x, y = map(int, input().split())
if com == 0:
uf.merge(x, y)
else:
print(1 if uf.same(x, y) else 0)
``` | instruction | 0 | 17,674 | 5 | 35,348 |
No | output | 1 | 17,674 | 5 | 35,349 |
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 disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1
Submitted Solution:
```
def find(x):
global set_list
return x if set_list[x] == x else find(set_list[x])
n, q = map(int, input().split())
set_list = list(range(n))
while q:
op, x, y = map(int, input().split())
if op:
print(1 if find(x) == find(y) else 0)
else:
if x > y:
x, y = y, x
set_list[find(y)] = find(x)
q -= 1
``` | instruction | 0 | 17,675 | 5 | 35,350 |
No | output | 1 | 17,675 | 5 | 35,351 |
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 disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1
Submitted Solution:
```
# -*- coding: utf-8 -*-
class DisjointSets:
'''
Implementing disjoint sets using disjoint sets forests structure.
--- methods ---
__init__(size): size should be the number of elements in this disjoint sets
unite(x, y): unite sets that contain x and y into a new set
same(x, y): check if x and y are in the same set
'''
def __init__(self, size):
self.ranks = [0] * size
self.roots = [0] * size
for x in range(size):
self._make_set(x)
def _make_set(self, x):
self.roots[x] = x
self.ranks[x] = 0
def _link(self, x, y):
if self.ranks[x] > self.ranks[y]:
self.roots[y] = x
else:
self.roots[x] = y
if self.ranks[x] == self.ranks[y]:
self.ranks[y] += 1
def _find_set(self, x):
# compression of the path
if x != self.roots[x]:
self.roots[x] = self._find_set(self.roots[x])
return self.roots[x]
def unite(self, x, y):
if self.same(x, y):
raise SameSetError('{} and {} are in the same set'.format(x, y))
self._link(self._find_set(x), self._find_set(y))
def same(self, x, y):
return self._find_set(x) == self._find_set(y)
class SameSetError(Exception):
pass
if __name__ == '__main__':
import sys
n, q = map(int, input().split())
ds = DisjointSets(n)
for line in sys.stdin.readlines():
query, x, y = map(int, line.strip().split())
if query == 0:
ds.unite(x, y)
elif query == 1:
if ds.same(x, y):
print(1)
else:
print(0)
``` | instruction | 0 | 17,676 | 5 | 35,352 |
No | output | 1 | 17,676 | 5 | 35,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Remainder of Big Integers
Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the remainder in a line.
Constraints
* $0 \leq A, B \leq 10^{1000}$
* $B \ne 0$
Sample Input 1
5 8
Sample Output 1
5
Sample Input 2
100 25
Sample Output 2
0
Example
Input
5 8
Output
5
Submitted Solution:
```
a,b = [int(x) for x in input().split()]
print(a%b)
``` | instruction | 0 | 17,685 | 5 | 35,370 |
Yes | output | 1 | 17,685 | 5 | 35,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Remainder of Big Integers
Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the remainder in a line.
Constraints
* $0 \leq A, B \leq 10^{1000}$
* $B \ne 0$
Sample Input 1
5 8
Sample Output 1
5
Sample Input 2
100 25
Sample Output 2
0
Example
Input
5 8
Output
5
Submitted Solution:
```
a = [int (i) for i in input().split()];
print (a[0] % a[1]);
``` | instruction | 0 | 17,686 | 5 | 35,372 |
Yes | output | 1 | 17,686 | 5 | 35,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Remainder of Big Integers
Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the remainder in a line.
Constraints
* $0 \leq A, B \leq 10^{1000}$
* $B \ne 0$
Sample Input 1
5 8
Sample Output 1
5
Sample Input 2
100 25
Sample Output 2
0
Example
Input
5 8
Output
5
Submitted Solution:
```
print(eval(input().replace(' ','%')))
``` | instruction | 0 | 17,687 | 5 | 35,374 |
Yes | output | 1 | 17,687 | 5 | 35,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Remainder of Big Integers
Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the remainder in a line.
Constraints
* $0 \leq A, B \leq 10^{1000}$
* $B \ne 0$
Sample Input 1
5 8
Sample Output 1
5
Sample Input 2
100 25
Sample Output 2
0
Example
Input
5 8
Output
5
Submitted Solution:
```
a,b = map(int,input().split())
print(a//b)
``` | instruction | 0 | 17,689 | 5 | 35,378 |
No | output | 1 | 17,689 | 5 | 35,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given sequence a1, a2, ..., an and m queries lj, rj (1 ≤ lj ≤ rj ≤ n). For each query you need to print the minimum distance between such pair of elements ax and ay (x ≠ y), that:
* both indexes of the elements lie within range [lj, rj], that is, lj ≤ x, y ≤ rj;
* the values of the elements are equal, that is ax = ay.
The text above understands distance as |x - y|.
Input
The first line of the input contains a pair of integers n, m (1 ≤ n, m ≤ 5·105) — the length of the sequence and the number of queries, correspondingly.
The second line contains the sequence of integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).
Next m lines contain the queries, one per line. Each query is given by a pair of numbers lj, rj (1 ≤ lj ≤ rj ≤ n) — the indexes of the query range limits.
Output
Print m integers — the answers to each query. If there is no valid match for some query, please print -1 as an answer to this query.
Examples
Input
5 3
1 1 2 3 2
1 5
2 4
3 5
Output
1
-1
2
Input
6 5
1 2 1 3 2 3
4 6
1 3
2 5
2 4
1 6
Output
2
2
3
-1
2
Submitted Solution:
```
inp = input().split(' ')
n, m = int(inp[0]), int(inp[1])
numbers = {}
inp = input().split(' ')
for i in range(n):
a = int(inp[i])
if numbers.get(a) == None:
numbers[a] = [i]
else:
numbers[a].append(i)
print(numbers)
dists = {}
for a in numbers.keys():
ind = numbers[a]
for i in range(len(ind) - 1):
dists[ind[i]] = ind[i + 1] - ind[i]
queries = [input() for i in range(m)]
for qr in queries:
beg = int(qr.split(' ')[0])
end = int(qr.split(' ')[1])
curmin = -1
for i in range(beg - 1, end):
if dists.get(i, None) != None and i + dists[i] < end:
if curmin == -1 or curmin > dists[i]:
curmin = dists[i]
if (curmin == 1):
break
ans = curmin <= (end - beg) and curmin or -1
print(ans)
``` | instruction | 0 | 18,092 | 5 | 36,184 |
No | output | 1 | 18,092 | 5 | 36,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given sequence a1, a2, ..., an and m queries lj, rj (1 ≤ lj ≤ rj ≤ n). For each query you need to print the minimum distance between such pair of elements ax and ay (x ≠ y), that:
* both indexes of the elements lie within range [lj, rj], that is, lj ≤ x, y ≤ rj;
* the values of the elements are equal, that is ax = ay.
The text above understands distance as |x - y|.
Input
The first line of the input contains a pair of integers n, m (1 ≤ n, m ≤ 5·105) — the length of the sequence and the number of queries, correspondingly.
The second line contains the sequence of integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).
Next m lines contain the queries, one per line. Each query is given by a pair of numbers lj, rj (1 ≤ lj ≤ rj ≤ n) — the indexes of the query range limits.
Output
Print m integers — the answers to each query. If there is no valid match for some query, please print -1 as an answer to this query.
Examples
Input
5 3
1 1 2 3 2
1 5
2 4
3 5
Output
1
-1
2
Input
6 5
1 2 1 3 2 3
4 6
1 3
2 5
2 4
1 6
Output
2
2
3
-1
2
Submitted Solution:
```
#!/usr/bin/env python3
# coding: utf-8
import bisect
n, m = map(int, input().split())
a = map(int, input().split())
intervals = []
last_position = {}
for i, ai in enumerate(a, start=1):
if ai in last_position:
intervals.append((last_position[ai], i))
last_position[ai] = i
del a
del last_position
intervals.sort(key=lambda interval: (interval[0], interval[1] - interval[0]))
ls = [interval[0] for interval in intervals]
for _ in range(m):
l, r = map(int, input().split())
i = bisect.bisect_left(ls, l)
for j in range(i, len(intervals)):
interval = intervals[j]
if l <= interval[0] <= r and l <= interval[1] <= r:
print(interval[1] - interval[0])
break
else:
print(-1)
``` | instruction | 0 | 18,093 | 5 | 36,186 |
No | output | 1 | 18,093 | 5 | 36,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given sequence a1, a2, ..., an and m queries lj, rj (1 ≤ lj ≤ rj ≤ n). For each query you need to print the minimum distance between such pair of elements ax and ay (x ≠ y), that:
* both indexes of the elements lie within range [lj, rj], that is, lj ≤ x, y ≤ rj;
* the values of the elements are equal, that is ax = ay.
The text above understands distance as |x - y|.
Input
The first line of the input contains a pair of integers n, m (1 ≤ n, m ≤ 5·105) — the length of the sequence and the number of queries, correspondingly.
The second line contains the sequence of integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).
Next m lines contain the queries, one per line. Each query is given by a pair of numbers lj, rj (1 ≤ lj ≤ rj ≤ n) — the indexes of the query range limits.
Output
Print m integers — the answers to each query. If there is no valid match for some query, please print -1 as an answer to this query.
Examples
Input
5 3
1 1 2 3 2
1 5
2 4
3 5
Output
1
-1
2
Input
6 5
1 2 1 3 2 3
4 6
1 3
2 5
2 4
1 6
Output
2
2
3
-1
2
Submitted Solution:
```
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
lr = []
result = []
def er(n):
for i in range(n):
print("-1")
for i in range(m):
l, r = [int(z) for z in input().split()]
min_d = -1
for x in range(l-1, r):
try:
y = a.index(a[x], x+1, r)
except ValueError:
continue
else:
d = abs(x-y)
if d < min_d or min_d == -1:
min_d = d
if min_d == 1:
break
if l == 1 and r == n and min_d == -1:
er(n)
break
result.append(str(min_d))
print("\n".join(result))
``` | instruction | 0 | 18,094 | 5 | 36,188 |
No | output | 1 | 18,094 | 5 | 36,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given sequence a1, a2, ..., an and m queries lj, rj (1 ≤ lj ≤ rj ≤ n). For each query you need to print the minimum distance between such pair of elements ax and ay (x ≠ y), that:
* both indexes of the elements lie within range [lj, rj], that is, lj ≤ x, y ≤ rj;
* the values of the elements are equal, that is ax = ay.
The text above understands distance as |x - y|.
Input
The first line of the input contains a pair of integers n, m (1 ≤ n, m ≤ 5·105) — the length of the sequence and the number of queries, correspondingly.
The second line contains the sequence of integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).
Next m lines contain the queries, one per line. Each query is given by a pair of numbers lj, rj (1 ≤ lj ≤ rj ≤ n) — the indexes of the query range limits.
Output
Print m integers — the answers to each query. If there is no valid match for some query, please print -1 as an answer to this query.
Examples
Input
5 3
1 1 2 3 2
1 5
2 4
3 5
Output
1
-1
2
Input
6 5
1 2 1 3 2 3
4 6
1 3
2 5
2 4
1 6
Output
2
2
3
-1
2
Submitted Solution:
```
import sys
def checkEqual2(iterator):
return len(set(iterator)) <= 1
n,m = map(int,sys.stdin.readline().split())
if(n>=1 and n<=500000 and m>=1 and m<=500000):
numbers =list( map(int,sys.stdin.readline().split()))
if(not numbers.__len__() == n):
sys.exit()
answers = []
newNumbersSet = set(numbers)
l = dict(zip(newNumbersSet , map(lambda p: [i for i,z in enumerate(numbers) if z is p], newNumbersSet )))
equals = checkEqual2(numbers)
for index in range(m):
inputString = sys.stdin.readline().split()
if inputString== "":
sys.exit()
x,y = map(int,inputString)
if(x > n or y > n or x < 1 or y < 1 or y<x):
continue
if equals == True:
if y>x:
answers.append(y-x)
else:
answers.append(-1)
else:
resultList = [c[len(c)-1]-c[0] for L,c in l.items() if len(c)>1 and c[0]>=x-1 and c[len(c)-1]<=y-1]
if(len(resultList) == 0):
answers.append(-1)
else:
answers.append(min(resultList ))
for r in answers:
print (r)
``` | instruction | 0 | 18,095 | 5 | 36,190 |
No | output | 1 | 18,095 | 5 | 36,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120. | instruction | 0 | 18,268 | 5 | 36,536 |
Tags: greedy
Correct Solution:
```
n = int(input())
ans = 0
s = list(map(int, input().split()))
#for i in s:
#if(s.count(i) < 2):
#ans += abs(i)
#print(ans)
for i in s:
ans += abs(i)
print(ans)
``` | output | 1 | 18,268 | 5 | 36,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120. | instruction | 0 | 18,269 | 5 | 36,538 |
Tags: greedy
Correct Solution:
```
n = input()
n = input()
x = []
x = n.split()
negative=0
positive=0
for i in x:
if(int(i)>0):
positive = positive + int(i)
else:
negative = negative + int(i)
print(positive-negative)
``` | output | 1 | 18,269 | 5 | 36,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120. | instruction | 0 | 18,270 | 5 | 36,540 |
Tags: greedy
Correct Solution:
```
input()
a = list(map(int, input().split()))
s = 0
for i in range(len(a)):
s += abs(a[i])
print(s)
``` | output | 1 | 18,270 | 5 | 36,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120. | instruction | 0 | 18,271 | 5 | 36,542 |
Tags: greedy
Correct Solution:
```
n=int(input())
print(sum(abs(int(i)) for i in input().split()))
``` | output | 1 | 18,271 | 5 | 36,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120. | instruction | 0 | 18,272 | 5 | 36,544 |
Tags: greedy
Correct Solution:
```
n = input()
numb = [int(i) for i in input().split()]
B, C, = 0, 0
for i in numb:
if i > 0:
B += i
else:
C += i
print(B - C)
``` | output | 1 | 18,272 | 5 | 36,545 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
l = []
for i in a:
if i<0:
l.append(i)
else:
continue
print(sum(a)-2*sum(l))
``` | instruction | 0 | 18,276 | 5 | 36,552 |
Yes | output | 1 | 18,276 | 5 | 36,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.
Submitted Solution:
```
a=eval(input())
b=input().split()
b=[int(x) for x in b]
sum = 0
for i in b:
sum+=abs(i)
print(sum)
``` | instruction | 0 | 18,277 | 5 | 36,554 |
Yes | output | 1 | 18,277 | 5 | 36,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.
Submitted Solution:
```
n=int(input())
a=[]
b=[]
num=[]
str_in=input()
num = [int(n) for n in str_in.split()]
for x in num:
if x>=0:a.append(x)
elif x < 0:b.append(x)
total_a=0
total_b=0
for x in a:
total_a=x+total_a
for x in b:
total_b=x+total_b
print(total_a-total_b)
``` | instruction | 0 | 18,278 | 5 | 36,556 |
Yes | output | 1 | 18,278 | 5 | 36,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
b=[]
c=[]
for i in l:
if i<0:
c.append(i)
else:
b.append(i)
print(sum(b)-sum(c))
``` | instruction | 0 | 18,279 | 5 | 36,558 |
Yes | output | 1 | 18,279 | 5 | 36,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.
Output
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
Examples
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
Note
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.
Submitted Solution:
```
input()
a=input().split()
print(eval(max(a)+'-'+min(a)))
``` | instruction | 0 | 18,280 | 5 | 36,560 |
No | output | 1 | 18,280 | 5 | 36,561 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.