message stringlengths 2 433k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 113 108k | cluster float64 12 12 | __index_level_0__ int64 226 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2 | instruction | 0 | 31,293 | 12 | 62,586 |
Tags: implementation
Correct Solution:
```
n = int(input())
a = [int(i) for i in input().split()]
b = [False, False]
for i in range(2,n):
if a[i] == a[i - 1] + a[i - 2]:
b.append(True)
else:
b.append(False)
max = 0
now = 0
for i in b:
if i:
now += 1
else:
if now > max:
max = now
now = 0;
if now > max:
max = now
print(min(n, max + 2))
``` | output | 1 | 31,293 | 12 | 62,587 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2 | instruction | 0 | 31,294 | 12 | 62,588 |
Tags: implementation
Correct Solution:
```
n = int(input())
ls = [int(i) for i in input().split()]
if n == 1 or n == 2:
print(n)
exit()
ans, a = 2, 2
for i in range(2, n):
if ls[i] == ls[i - 1] + ls[i - 2]:
ans += 1
a = max(a, ans)
else:
ans = 2
print(a)
``` | output | 1 | 31,294 | 12 | 62,589 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2 | instruction | 0 | 31,295 | 12 | 62,590 |
Tags: implementation
Correct Solution:
```
L=lambda:list(map(int,input().split()))
M=lambda:map(int,input().split())
I=lambda:int(input())
n=I()
a=L()
if n==1:
print("1")
exit()
else:
x=2
y=2
for i in range(2,n):
if a[i]!=a[i-1]+a[i-2]:
x=max(x,y)
y=2
else:
y+=1
print(max(x,y))
``` | output | 1 | 31,295 | 12 | 62,591 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2 | instruction | 0 | 31,296 | 12 | 62,592 |
Tags: implementation
Correct Solution:
```
def solve(n, seq) :
longest = 0
if n == 2 :
return 2
elif n == 1:
return 1
else :
index = 2
temp = 2
while index < n :
if seq[index] == seq[index-1] + seq[index-2] :
temp += 1
else :
if temp > longest :
longest = temp
temp = 2
index += 1
if temp > longest :
longest = temp
return longest
print (solve(int(input()), list(map(int,input().split()))))
``` | output | 1 | 31,296 | 12 | 62,593 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2 | instruction | 0 | 31,297 | 12 | 62,594 |
Tags: implementation
Correct Solution:
```
n = int(input())
s = list(map(int,input().split()))
a,b=0,0
for i in range(n-2):
#print(i,s[i],s[i+1],s[i+2])
if s[i+2]==s[i]+s[i+1]:
a+=1
b = max(b,a)
else:
a=0
print(min(n,b+2))
``` | output | 1 | 31,297 | 12 | 62,595 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2 | instruction | 0 | 31,298 | 12 | 62,596 |
Tags: implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
if len(a)==1:
print(1)
elif len(a)==2:
print(2)
else:
z=[]
j=2
c=0
while j<n:
if a[j]==a[j-1]+a[j-2]:
c+=1
else:
z.append(c)
c=0
j+=1
z.append(c)
print(max(z)+2)
``` | output | 1 | 31,298 | 12 | 62,597 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2 | instruction | 0 | 31,299 | 12 | 62,598 |
Tags: implementation
Correct Solution:
```
n=int(input())
arr=[int(x) for x in input().split()]
if(n<=2):
print(n)
else:
m,ans=2,2
for i in range(2,n):
if(arr[i]==arr[i-1]+arr[i-2]):
m+=1
else:
m=2
ans=max(ans,m)
print(ans)
``` | output | 1 | 31,299 | 12 | 62,599 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2 | instruction | 0 | 31,300 | 12 | 62,600 |
Tags: implementation
Correct Solution:
```
n = int(input())
ar = list(map(int,input().split()))
l = 0
l_temp = 0
for i in range(n) :
if i > 1 :
if ar[i] == ar[i-1] + ar[i-2] :
l_temp += 1
if l_temp > l :
l = l_temp
else :
l_temp = 0
if n < 2 :
print(n)
else :
print(l+2)
``` | output | 1 | 31,300 | 12 | 62,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2
Submitted Solution:
```
# your code goes here
n = int(input())
array = list(map(int,input().split()))
ans = 1
count = 0
if n>=2:
ans = 2
for i in range(2,n):
if array[i] == array[i-1] + array[i-2]:
count += 1
else:
count = 0
ans = max(ans,count+2)
print(ans)
``` | instruction | 0 | 31,301 | 12 | 62,602 |
Yes | output | 1 | 31,301 | 12 | 62,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
r=min(2,len(a))
k=0
#we will check for all initial point in array
for i in range(2,n):
if a[i]==a[i-1]+a[i-2]:
if k==0:k=3
else:k+=1
r=max(r,k)
#and record max at all step
else:k=0
print(r)
``` | instruction | 0 | 31,302 | 12 | 62,604 |
Yes | output | 1 | 31,302 | 12 | 62,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
if(n<=2):
print(n)
else:
c=2
t=[]
j=2
while(j<n):
for i in range(j, n):
if (l[i] == l[i - 1] + l[i - 2]):
c += 1
else:
break
j=i+1
t.append(c)
c=2
print(max(t))
``` | instruction | 0 | 31,303 | 12 | 62,606 |
Yes | output | 1 | 31,303 | 12 | 62,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2
Submitted Solution:
```
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
r=[]
i=2
a=0
while i<n:
if l[i]==l[i-1]+l[i-2]:
a+=1
else:
r+=[a]
a=0
i+=1
r+=[a]
if len(l)==1:
print("1")
elif len(r)!=0 :
print(2+max(r))
else:
print('2')
``` | instruction | 0 | 31,304 | 12 | 62,608 |
Yes | output | 1 | 31,304 | 12 | 62,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2
Submitted Solution:
```
n = int(input())
arr = [int(i) for i in input().split()]
res = 0
i = 2
if (n > 1):
while (i < n):
temp = 2
while (i < n and arr[i] == arr[i-1] + arr[i-2]):
temp += 1
i += 1
i += 1
res = max(res, temp)
else:
res = n
print(res)
``` | instruction | 0 | 31,305 | 12 | 62,610 |
No | output | 1 | 31,305 | 12 | 62,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split(' ')))
ans = min(n, 2)
cnt = 2
for i in range(2, n):
if a[i] == a[i-1] + a[i-2]:
cnt += 1
ans = max(ans,cnt)
else:
cnt = 0
print(ans)
``` | instruction | 0 | 31,306 | 12 | 62,612 |
No | output | 1 | 31,306 | 12 | 62,613 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
i,ans,c = n-1,0,0
while i-2 >= 0:
if arr[i] == arr[i-1] + arr[i-2]:
c += 1
else:
ans = max(ans, c+1)
c = 0
i -= 1
if c > 0:
print(max(ans, c+2))
else:
if ans == 1 and n > 1:
print(2)
elif n == 1 or n == 2:
print(n)
else:
print(ans)
``` | instruction | 0 | 31,307 | 12 | 62,614 |
No | output | 1 | 31,307 | 12 | 62,615 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have array a1, a2, ..., an. Segment [l, r] (1 β€ l β€ r β€ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 β€ i β€ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the number of elements in the array. The second line contains integers: a1, a2, ..., an (0 β€ ai β€ 109).
Output
Print the length of the longest good segment in array a.
Examples
Input
10
1 2 3 5 8 13 21 34 55 89
Output
10
Input
5
1 1 1 1 1
Output
2
Submitted Solution:
```
n = int(input())
s = [int(i) for i in input().split()]+[-1]
d = 1
if n==1:
print(d)
else:
r = 2
cnt = 0
maxi = 2
while r<=n:
if s[r-1]+s[r-2]==s[r]:
cnt+=1
else:
maxi = max(cnt,maxi+cnt)
cnt = 0
r+=1
print(maxi)
``` | instruction | 0 | 31,308 | 12 | 62,616 |
No | output | 1 | 31,308 | 12 | 62,617 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel is playing a game with numbers now.
Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
Input
The first line contains an integer n (2 β€ n β€ 100). Then the second line contains n integers: x1, x2, ..., xn (1 β€ xi β€ 100).
Output
Output a single integer β the required minimal sum.
Examples
Input
2
1 2
Output
2
Input
3
2 4 6
Output
6
Input
2
12 18
Output
12
Input
5
45 12 27 30 18
Output
15
Note
In the first example the optimal way is to do the assignment: x2 = x2 - x1.
In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1. | instruction | 0 | 31,310 | 12 | 62,620 |
Tags: greedy, math
Correct Solution:
```
from collections import deque
import bisect
n=int(input())
list1=list(map(int,input().split()))
list1.sort()
list1=deque(list1)
while(True):
x=list1.pop()
y=list1.popleft()
if(x>y):
x-=y
bisect.insort(list1,x)
bisect.insort(list1,y)
else:
bisect.insort(list1,x)
bisect.insort(list1,y)
break
# print(list1)
print(sum(list1))
``` | output | 1 | 31,310 | 12 | 62,621 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | instruction | 0 | 31,432 | 12 | 62,864 |
Tags: constructive algorithms, greedy
Correct Solution:
```
import sys
lines = sys.stdin.readlines()
(n, m) = map(int, lines[0].strip().split(" "))
minQLen = n
for i in range(1, m+1):
(l, r) = map(int, lines[i].strip().split(" "))
minQLen = min(minQLen, r - l +1)
print(minQLen)
arr = [ i % minQLen for i in range(n)]
print(" ".join(map(str, arr)))
``` | output | 1 | 31,432 | 12 | 62,865 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | instruction | 0 | 31,433 | 12 | 62,866 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n,m = map(int,input().split())
mn = n
for _ in range(m):
l,r = map(int,input().split())
mn = min(mn,r-l+1)
j = 0
answer = [0]*n
for i in range(n):
answer[i] = j%mn
j += 1
print(mn)
print(*answer)
``` | output | 1 | 31,433 | 12 | 62,867 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | instruction | 0 | 31,434 | 12 | 62,868 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
ml = n
for _ in range(m):
l, r = map(int, input().split())
ml = min(ml, r - l + 1)
ans, cur = [0] * n, 0
for i in range(n):
ans[i] = cur % ml
cur += 1
print(ml)
print(*ans)
``` | output | 1 | 31,434 | 12 | 62,869 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | instruction | 0 | 31,435 | 12 | 62,870 |
Tags: constructive algorithms, greedy
Correct Solution:
```
import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
n,m=(int(i) for i in input().split())
d={}
k=n+1
for i in range(m):
a,b=(int(i) for i in input().split())
k=min(k,b-a+1)
l=[]
for i in range(n):
l.append(i%k)
print(k)
print(*l)
``` | output | 1 | 31,435 | 12 | 62,871 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | instruction | 0 | 31,436 | 12 | 62,872 |
Tags: constructive algorithms, greedy
Correct Solution:
```
import sys
sys = sys.stdin.readline
n, m = map(int, input().split())
mx = 1000000000
for _ in range(m):
l, r = map(int, input().split())
mx = min(mx, r - l + 1)
print(mx)
result = []
j = 0
for i in range(n):
result.append(j)
j += 1
if j == mx:
j = 0
print(' '.join(map(str, result)))
``` | output | 1 | 31,436 | 12 | 62,873 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | instruction | 0 | 31,437 | 12 | 62,874 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
mi = float('inf')
for i in range(m):
l, r = map(int, input().split())
mi = min(mi, r - l + 1)
print(mi)
ans = []
for i in range(n):
ans.append(i % mi)
print(*ans)
``` | output | 1 | 31,437 | 12 | 62,875 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | instruction | 0 | 31,438 | 12 | 62,876 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n,m=map(int,input().split())
Len=float('inf')
for i in range(m):
l,r=map(int,input().split())
Len=min(Len,r-l+1)
ans=[]
for i in range(n):
ans.append(i%Len)
print(Len)
print(*ans)
``` | output | 1 | 31,438 | 12 | 62,877 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | instruction | 0 | 31,439 | 12 | 62,878 |
Tags: constructive algorithms, greedy
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
n,m=map(int,input().split())
a=list()
for i in range (m):
l,r=map(int,input().split())
a.append((r-l+1,l-1,r-1))
a.sort()
l=a[0][0]
b=[0]*n
j=0
for i in range (n):
b[i]=j
j+=1
j%=l
print(l)
print(*b)
``` | output | 1 | 31,439 | 12 | 62,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
Submitted Solution:
```
r=lambda:list(map(int, input().split()))
n,m=r()
d=lambda x:x[1]-x[0]+1
l=min(d(r())for _ in range(m))
print(l)
print(' '.join(str(i % l) for i in range(n)))
``` | instruction | 0 | 31,440 | 12 | 62,880 |
Yes | output | 1 | 31,440 | 12 | 62,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
Submitted Solution:
```
amount, mass = map(int,input().split())
minim = amount
for i in range (mass):
l, r = map(int, input().split())
if (minim > (r - l + 1)):
minim = (r - l + 1)
i = 0
print(minim)
while (i < amount):
print(i % minim, end = ' ')
i += 1
``` | instruction | 0 | 31,441 | 12 | 62,882 |
Yes | output | 1 | 31,441 | 12 | 62,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
Submitted Solution:
```
n,m = map(int, input().split())
ans = min([y-x+1 for x,y in [list(map(int, input().split())) for _ in range(m)]])
print(ans)
num = list(map(str, range(ans))) * (n//ans+1)
print(' '.join(num[:n]))
``` | instruction | 0 | 31,442 | 12 | 62,884 |
Yes | output | 1 | 31,442 | 12 | 62,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
Submitted Solution:
```
from sys import stdin
test = stdin.readlines()
n, m = map(int, test[0].split())
intervals = [[int(c) for c in test[i].split()] for i in range(1, m + 1)]
min_length = min(r - l + 1 for l, r in intervals)
ans = list(range(min_length)) * (n // min_length + 1)
ans = ans[:n]
print(min_length)
print(*ans)
``` | instruction | 0 | 31,443 | 12 | 62,886 |
Yes | output | 1 | 31,443 | 12 | 62,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
Submitted Solution:
```
#!/usr/bin/env python3
n, m = map(int, input().split())
mm = 10**5 + 1
for i in range(m):
l, r = map(int, input().split())
mm = min(mm, r-l)
print(mm+1)
for i in range(n):
if i != n-1:
print(i % (mm+1), end=" ")
else:
print(i % mm)
``` | instruction | 0 | 31,444 | 12 | 62,888 |
No | output | 1 | 31,444 | 12 | 62,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
Submitted Solution:
```
n , m = map(int, input().split())
mn = 10 ** 10
event = set()
for i in range(m):
b, e = map(int, input().split())
if mn > e - b:
mn = e - b + 2
event.add(b - 1)
k = 0
print(mn - 1)
for i in range(n):
if i in event:
k = 0
print(k % mn, end = " ")
k+=1
``` | instruction | 0 | 31,445 | 12 | 62,890 |
No | output | 1 | 31,445 | 12 | 62,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
Submitted Solution:
```
n , m = map(int, input().split())
mn = 10**10
for i in range(m):
b, e = map(int, input().split())
if e - b < mn:
mn = e - b + 2
print(mn - 1)
for i in range(n):
print (i % mn, end = " ")
``` | instruction | 0 | 31,446 | 12 | 62,892 |
No | output | 1 | 31,446 | 12 | 62,893 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
Input
The first line contains two integers n and m (1 β€ n, m β€ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 β€ li β€ ri β€ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
Output
In the first line print single integer β the maximum possible minimum mex.
In the second line print n integers β the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1
Note
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
Submitted Solution:
```
import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65
def getInt():
return int(sys.stdin.readline().rstrip())
def getInts():
return map(int, sys.stdin.readline().rstrip().split(" "))
def getString():
return sys.stdin.readline().rstrip()
def printOutput(ans):
ans1, array = ans
sys.stdout.write(str(ans1) + "\n")
for ele in array:
sys.stdout.write(str(ele) + " ")
sys.stdout.write("\n")
def solve(n, sets):
array = [0 for _ in range(n + 1)]
sets.sort() # sort by start
sets.sort(key=lambda x: x[1] - x[0], reverse=True) # sort by length
#print(sets)
# result, we have smallest lengths last and go from the start
# now we go through and label the array
prev = (0, 0)
ans1 = sets[-1][1] - sets[-1][0] + 1
for i in range(len(sets)):
li, ri = prev
lj, rj = sets[i]
if lj < ri and (ri - li) == (rj - lj):
lj = ri
for k in range(0, rj - lj + 1):
array[lj + k] = k
#print(array)
prev = sets[i]
return ans1, array[1:]
def readinput():
n, m = getInts()
sets = []
for _ in range(m):
li, ri = getInts()
sets.append((li, ri))
printOutput(solve(n, sets))
readinput()
``` | instruction | 0 | 31,447 | 12 | 62,894 |
No | output | 1 | 31,447 | 12 | 62,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4]. | instruction | 0 | 31,830 | 12 | 63,660 |
Tags: bitmasks, dp
Correct Solution:
```
import sys,math
#from threading import Thread,stack_size
from collections import defaultdict as dd,deque
from bisect import bisect_left as bl,bisect as br
from heapq import heappush as push,heappop as pop,heapify
#sys.setrecursionlimit(10**6+999);stack_size(2**27);BUFSIZE=8192;
mod=int(1e9)+7;mod2=998244353;yes='YES';no='NO';Yes='Yes';No='No';
input=sys.stdin.readline;bits=19;inf=int(1e9)+999
################################################################################
def main():
def solve():
for bit in range(bits):
rcnt[bit]=inf
for i in range(n-1,-1,-1):
for bit in range(bits):
nxt[i][bit]=inf
for bit in range(bits):
is_bit_set=a[i]&(1<<bit)
if(is_bit_set):
val=rcnt[bit]
if(val!=inf):
nxt[i][bit]=min(nxt[i][bit],val)
for b2 in range(bits):
nxt[i][b2]=min(nxt[i][b2],nxt[val][b2])
rcnt[bit]=i
###INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT######
n,q=map(int,input().split())
a=[int(i) for i in input().split()]
rcnt=[0]*bits
nxt=[[0]*bits for i in range(n)]
solve()
for Q in range(q):
x,y=map(int,input().split())
x-=1;y-=1;ans=0
for bit in range(bits):
if(a[y]&(1<<bit)):
if(nxt[x][bit]<=y):
ans=1
break
print('Shi' if(ans) else 'Fou')
################################################################################
TC=1
if __name__=='__main__':
for tc in range(TC):
if(1):
main()
else:
t=Thread(target=main)
t.start();t.join()
``` | output | 1 | 31,830 | 12 | 63,661 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4]. | instruction | 0 | 31,831 | 12 | 63,662 |
Tags: bitmasks, dp
Correct Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key,lru_cache
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# import sys
# input = sys.stdin.readline
M = mod = 10**9 + 7
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip().split()]
def st():return str(input().rstrip())[2:-1]
def val():return int(input().rstrip())
def li2():return [str(i)[2:-1] for i in input().rstrip().split()]
def li3():return [int(i) for i in st()]
he = []
n, q = li()
queue = [-1] * 20
ans = [[-1] * 20 for i in range(n + 1)]
l = li()
for i, curr in enumerate(l):
for j in range(20):
if curr >> j & 1:
for k in range(20):
ans[i][k] = max(ans[i][k], ans[queue[j]][k])
ans[i][j] = i
for j in range(20):queue[j] = max(queue[j], ans[i][j])
# for i in ans:print(*i)
for i in range(q):
a, b = li()
a -= 1
b -= 1
currans = 0
for j in range(20):
if (l[a] >> j) & 1 and ans[b][j] >= a:
currans = 1
break
print('Shi' if currans else 'Fou')
``` | output | 1 | 31,831 | 12 | 63,663 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4]. | instruction | 0 | 31,832 | 12 | 63,664 |
Tags: bitmasks, dp
Correct Solution:
```
import sys,math
#from threading import Thread,stack_size
from collections import defaultdict as dd,deque
from bisect import bisect_left as bl,bisect as br
from heapq import heappush as push,heappop as pop,heapify
#sys.setrecursionlimit(10**6+999);stack_size(2**27);BUFSIZE=8192;
mod=int(1e9)+7;mod2=998244353;yes='YES';no='NO';Yes='Yes';No='No';
input=sys.stdin.readline
bits=19;inf=int(1e9)+999
################################################################################
def main():
def solve():
for bit in range(bits):
rcnt[bit]=inf
for i in range(n-1,-1,-1):
for bit in range(bits):
nxt[i][bit]=inf
for bit in range(bits):
is_bit_set=a[i]&(1<<bit)
if(is_bit_set):
val=rcnt[bit]
if(val!=inf):
nxt[i][bit]=min(nxt[i][bit],val)
for b2 in range(bits):
nxt[i][b2]=min(nxt[i][b2],nxt[val][b2])
rcnt[bit]=i
###INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT######
n,q=map(int,input().split())
a=[int(i) for i in input().split()]
rcnt=[0]*bits
nxt=[[0]*bits for i in range(n)]
solve()
for Q in range(q):
x,y=map(int,input().split())
x-=1;y-=1;ans=0
for bit in range(bits):
if(a[y]&(1<<bit)):
if(nxt[x][bit]<=y):
ans=1
break
print('Shi' if(ans) else 'Fou')
################################################################################
TC=1
if __name__=='__main__':
for tc in range(TC):
if(1):
main()
else:
t=Thread(target=main)
t.start();t.join()
``` | output | 1 | 31,832 | 12 | 63,665 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4]. | instruction | 0 | 31,833 | 12 | 63,666 |
Tags: bitmasks, dp
Correct Solution:
```
import sys,math
#from threading import Thread,stack_size
from collections import defaultdict as dd,deque
#from bisect import bisect_left as bl,bisect as br
#from heapq import heappush as push,heappop as pop,heapify
#sys.setrecursionlimit(10**6+999);stack_size(2**27);BUFSIZE=8192;
mod=int(1e9)+7;mod2=998244353;yes='YES';no='NO';Yes='Yes';No='No';
input=lambda:sys.stdin.readline().rstrip("\r\n");bits=19;inf=int(1e9)+999
################################################################################
def main():
def solve():
for bit in range(bits):
rcnt[bit]=inf
for i in range(n-1,-1,-1):
for bit in range(bits):
nxt[i][bit]=inf
for bit in range(bits):
is_bit_set=a[i]&(1<<bit)
if(is_bit_set):
val=rcnt[bit]
if(val!=inf):
nxt[i][bit]=min(nxt[i][bit],val)
for b2 in range(bits):
nxt[i][b2]=min(nxt[i][b2],nxt[val][b2])
rcnt[bit]=i
###INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT######
n,q=map(int,input().split())
a=[int(i) for i in input().split()]
rcnt=[0]*bits
nxt=[[0]*bits for i in range(n)]
solve()
for Q in range(q):
x,y=map(int,input().split())
x-=1;y-=1;ans=0
for bit in range(bits):
if(a[y]&(1<<bit)):
if(nxt[x][bit]<=y):
ans=1
break
print('Shi' if(ans) else 'Fou')
################################################################################
TC=1
if __name__=='__main__':
if(1):
main()
else:
t=Thread(target=main)
t.start();t.join()
``` | output | 1 | 31,833 | 12 | 63,667 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4]. | instruction | 0 | 31,834 | 12 | 63,668 |
Tags: bitmasks, dp
Correct Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key,lru_cache
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# import sys
# input = sys.stdin.readline
M = mod = 10**9 + 7
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip().split()]
def st():return str(input().rstrip())[2:-1]
def val():return int(input().rstrip())
def li2():return [str(i)[2:-1] for i in input().rstrip().split()]
def li3():return [int(i) for i in st()]
he = []
n, q = li()
queue = [-1] * 20
ans = [[-1] * 20 for i in range(n + 1)]
l = li()
for i, curr in enumerate(l):
for j in range(20):
if curr >> j & 1:
for k in range(20):
ans[i][k] = max(ans[i][k], ans[queue[j]][k])
ans[i][j] = i
for j in range(20):queue[j] = max(queue[j], ans[i][j])
queries = []
for i in range(q):queries.append(li())
for i in range(q):
a, b = queries[i]
a -= 1
b -= 1
currans = 0
for j in range(20):
if (l[a] >> j) & 1 and ans[b][j] >= a:
currans = 1
break
print('Shi' if currans else 'Fou')
``` | output | 1 | 31,834 | 12 | 63,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4]. | instruction | 0 | 31,835 | 12 | 63,670 |
Tags: bitmasks, dp
Correct Solution:
```
import sys,math
#from threading import Thread,stack_size
from collections import defaultdict as dd,deque
#from bisect import bisect_left as bl,bisect as br
#from heapq import heappush as push,heappop as pop,heapify
#sys.setrecursionlimit(10**6+999);stack_size(2**27);BUFSIZE=8192;
mod=int(1e9)+7;mod2=998244353;yes='YES';no='NO';Yes='Yes';No='No';
input=sys.stdin.readline;bits=19;inf=int(1e9)+999
'''
def si():
return input()
def msi():
return input().split()
def mii():
return [int(i) for i in input().split()]
'''
################################################################################
def main():
def solve():
for bit in range(bits):
rcnt[bit]=inf
for i in range(n-1,-1,-1):
for bit in range(bits):
nxt[i][bit]=inf
for bit in range(bits):
is_bit_set=a[i]&(1<<bit)
if(is_bit_set):
val=rcnt[bit]
if(val!=inf):
nxt[i][bit]=min(nxt[i][bit],val)
for b2 in range(bits):
nxt[i][b2]=min(nxt[i][b2],nxt[val][b2])
rcnt[bit]=i
###INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT######
n,q=map(int,input().split())
a=[int(i) for i in input().split()]
rcnt=[0]*bits
nxt=[[0]*bits for i in range(n)]
solve()
for Q in range(q):
x,y=map(int,input().split())
x-=1;y-=1;ans=0
for bit in range(bits):
if(a[y]&(1<<bit)):
if(nxt[x][bit]<=y):
ans=1
break
print('Shi' if(ans) else 'Fou')
################################################################################
TC=1
if __name__=='__main__':
if(1):
main()
else:
t=Thread(target=main)
t.start();t.join()
``` | output | 1 | 31,835 | 12 | 63,671 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4]. | instruction | 0 | 31,836 | 12 | 63,672 |
Tags: bitmasks, dp
Correct Solution:
```
import sys,math
#from threading import Thread,stack_size
from collections import defaultdict as dd,deque
#from bisect import bisect_left as bl,bisect as br
#from heapq import heappush as push,heappop as pop,heapify
#sys.setrecursionlimit(10**6+999);stack_size(2**27);BUFSIZE=8192;
mod=int(1e9)+7;mod2=998244353;yes='YES';no='NO';Yes='Yes';No='No';
input=sys.stdin.readline
bits=19;inf=int(1e9)+999
################################################################################
def main():
def solve():
for bit in range(bits):
rcnt[bit]=inf
for i in range(n-1,-1,-1):
for bit in range(bits):
nxt[i][bit]=inf
for bit in range(bits):
is_bit_set=a[i]&(1<<bit)
if(is_bit_set):
val=rcnt[bit]
if(val!=inf):
nxt[i][bit]=min(nxt[i][bit],val)
for b2 in range(bits):
nxt[i][b2]=min(nxt[i][b2],nxt[val][b2])
rcnt[bit]=i
###INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT#INPUT######
n,q=map(int,input().split())
a=[int(i) for i in input().split()]
rcnt=[0]*bits
nxt=[[0]*bits for i in range(n)]
solve()
for Q in range(q):
x,y=map(int,input().split())
x-=1;y-=1;ans=0
for bit in range(bits):
if(a[y]&(1<<bit)):
if(nxt[x][bit]<=y):
ans=1
break
print('Shi' if(ans) else 'Fou')
################################################################################
TC=1
if __name__=='__main__':
for tc in range(TC):
main()
``` | output | 1 | 31,836 | 12 | 63,673 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4]. | instruction | 0 | 31,837 | 12 | 63,674 |
Tags: bitmasks, dp
Correct Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop,heapify
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
n, q = li()
queue = [-1] * 20
ans = [[-1] * 20 for i in range(n + 1)]
l = li()
for i, curr in enumerate(l):
for j in range(20):
if curr >> j & 1:
for k in range(20):
ans[i][k] = max(ans[i][k], ans[queue[j]][k])
ans[i][j] = i
for j in range(20):queue[j] = max(queue[j], ans[i][j])
queries = []
for i in range(q):queries.append(li())
for i in range(q):
a, b = queries[i]
a -= 1
b -= 1
currans = 0
for j in range(20):
if (l[a] >> j) & 1 and ans[b][j] >= a:
currans = 1
break
print('Shi' if currans else 'Fou')
``` | output | 1 | 31,837 | 12 | 63,675 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4].
Submitted Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key,lru_cache
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# import sys
# input = sys.stdin.readline
M = mod = 10**9 + 7
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip().split()]
def st():return str(input().rstrip())[2:-1]
def val():return int(input().rstrip())
def li2():return [str(i)[2:-1] for i in input().rstrip().split()]
def li3():return [int(i) for i in st()]
he = []
n, q = li()
l = li()
queries = []
for i in range(q):
queries.append(li())
ma = 0
for i in l:
curr = i
tot = 0
while curr:
tot += 1
curr = curr >> 1
ma = max(ma, tot)
queue = [-1] * ma
ans = [[-1] * ma for i in range(n + 1)]
for i in range(n - 1, -1, -1):
myheap = []
curr = l[i]
mask = 0
for j in range(ma):
if (curr >> j) & 1:
if queue[j] != -1:
heappush(myheap, queue[j])
ans[i][j] = i
mask += 1 << j
queue[j] = i
while myheap:
ind = heappop(myheap)
curr = l[ind]
for j in range(ma):
if (curr >> j) & 1 == 1:
if ans[i][j] == -1:
ans[i][j] = ind
elif ans[ind][j] != -1 and (mask >> j) & 1 == 0:
heappush(myheap, ans[ind][j])
mask += 1 << j
# print(l)
# for i in ans:print(*i)
for i in range(q):
a, b = queries[i]
a -= 1
b -= 1
currans = 0
if a < b:
for j in range(ma):
if (l[b] >> j) & 1 and ans[a][j] <= b and ans[a][j] != -1:
currans = 1
break
print('Shi' if currans else 'Fou')
``` | instruction | 0 | 31,838 | 12 | 63,676 |
No | output | 1 | 31,838 | 12 | 63,677 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Pimple has an array of integers a_1, a_2, β¦, a_n.
We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < β¦ < p_k=y, and a_{p_i} \& a_{p_{i+1}} > 0 for all integers i such that 1 β€ i < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).
You are given q pairs of indices, check reachability for each of them.
Input
The first line contains two integers n and q (2 β€ n β€ 300 000, 1 β€ q β€ 300 000) β the number of integers in the array and the number of queries you need to answer.
The second line contains n space-separated integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 300 000) β the given array.
The next q lines contain two integers each. The i-th of them contains two space-separated integers x_i and y_i (1 β€ x_i < y_i β€ n). You need to check if y_i is reachable from x_i.
Output
Output q lines. In the i-th of them print "Shi" if y_i is reachable from x_i, otherwise, print "Fou".
Example
Input
5 3
1 3 0 2 1
1 3
2 4
1 4
Output
Fou
Shi
Shi
Note
In the first example, a_3 = 0. You can't reach it, because AND with it is always zero. a_2 \& a_4 > 0, so 4 is reachable from 2, and to go from 1 to 4 you can use p = [1, 2, 4].
Submitted Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key,lru_cache
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# import sys
# input = sys.stdin.readline
M = mod = 10**9 + 7
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip().split()]
def st():return str(input().rstrip())[2:-1]
def val():return int(input().rstrip())
def li2():return [str(i)[2:-1] for i in input().rstrip().split()]
def li3():return [int(i) for i in st()]
he = []
n, q = li()
l = li()
queries = []
for i in range(q):
queries.append(li())
ma = 0
for i in l:
curr = i
tot = 0
while curr:
tot += 1
curr = curr >> 1
ma = max(ma, tot)
queue = [float('inf')] * ma
ans = [[float('inf')] * ma for i in range(n + 1)]
for i in range(n - 1, -1, -1):
myheap = []
curr = l[i]
mask = 0
for j in range(ma):
if (curr >> j) & 1:
if queue[j] != float('inf'):
heappush(myheap, queue[j])
ans[i][j] = i
mask += 1 << j
queue[j] = i
while myheap:
ind = heappop(myheap)
curr = l[ind]
for j in range(ma):
if (curr >> j) & 1 == 1:
ans[i][j] = min(ans[i][j], ind)
elif ans[ind][j] != float('inf') and (mask >> j) & 1 == 0:
heappush(myheap, ans[ind][j])
mask += 1 << j
# print(l)
# for i in ans:print(*i)
for i in range(q):
a, b = queries[i]
a -= 1
b -= 1
currans = 0
if a < b and l[a] and l[b]:
for j in range(ma):
if (l[b] >> j) & 1 and ans[a][j] <= b and ans[a][j] != -1:
currans = 1
break
print('Shi' if currans else 'Fou')
``` | instruction | 0 | 31,839 | 12 | 63,678 |
No | output | 1 | 31,839 | 12 | 63,679 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!
An array a of length n is called complete if all elements are positive and don't exceed 1000, and for all indices x,y,z (1 β€ x,y,z β€ n), a_{x}+a_{y} β a_{z} (not necessarily distinct).
You are given one integer n. Please find any complete array of length n. It is guaranteed that under given constraints such array exists.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 1000) β the number of test cases. Description of the test cases follows.
The only line of each test case contains one integer n (1 β€ n β€ 1000).
It is guaranteed that the sum of n over all test cases does not exceed 1000.
Output
For each test case, print a complete array on a single line. All elements have to be integers between 1 and 1000 and for all indices x,y,z (1 β€ x,y,z β€ n) (not necessarily distinct), a_{x}+a_{y} β a_{z} must hold.
If multiple solutions exist, you may print any.
Example
Input
2
5
4
Output
1 5 3 77 12
384 384 44 44
Note
It can be shown that the outputs above are valid for each test case. For example, 44+44 β 384.
Below are some examples of arrays that are NOT complete for the 1st test case:
[1,2,3,4,5]
Notice that a_{1}+a_{2} = a_{3}.
[1,3000,1,300,1]
Notice that a_{2} = 3000 > 1000. | instruction | 0 | 31,900 | 12 | 63,800 |
Tags: constructive algorithms, implementation
Correct Solution:
```
for _ in range(int(input())):
i_liczb = int(input())
print("1 " * i_liczb)
``` | output | 1 | 31,900 | 12 | 63,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!
An array a of length n is called complete if all elements are positive and don't exceed 1000, and for all indices x,y,z (1 β€ x,y,z β€ n), a_{x}+a_{y} β a_{z} (not necessarily distinct).
You are given one integer n. Please find any complete array of length n. It is guaranteed that under given constraints such array exists.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 1000) β the number of test cases. Description of the test cases follows.
The only line of each test case contains one integer n (1 β€ n β€ 1000).
It is guaranteed that the sum of n over all test cases does not exceed 1000.
Output
For each test case, print a complete array on a single line. All elements have to be integers between 1 and 1000 and for all indices x,y,z (1 β€ x,y,z β€ n) (not necessarily distinct), a_{x}+a_{y} β a_{z} must hold.
If multiple solutions exist, you may print any.
Example
Input
2
5
4
Output
1 5 3 77 12
384 384 44 44
Note
It can be shown that the outputs above are valid for each test case. For example, 44+44 β 384.
Below are some examples of arrays that are NOT complete for the 1st test case:
[1,2,3,4,5]
Notice that a_{1}+a_{2} = a_{3}.
[1,3000,1,300,1]
Notice that a_{2} = 3000 > 1000. | instruction | 0 | 31,901 | 12 | 63,802 |
Tags: constructive algorithms, implementation
Correct Solution:
```
t=int(input())
while t>0:
t-=1
n=int(input())
l=[2]*n
for i in l:
print(i,end=" ")
print()
``` | output | 1 | 31,901 | 12 | 63,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!
An array a of length n is called complete if all elements are positive and don't exceed 1000, and for all indices x,y,z (1 β€ x,y,z β€ n), a_{x}+a_{y} β a_{z} (not necessarily distinct).
You are given one integer n. Please find any complete array of length n. It is guaranteed that under given constraints such array exists.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 1000) β the number of test cases. Description of the test cases follows.
The only line of each test case contains one integer n (1 β€ n β€ 1000).
It is guaranteed that the sum of n over all test cases does not exceed 1000.
Output
For each test case, print a complete array on a single line. All elements have to be integers between 1 and 1000 and for all indices x,y,z (1 β€ x,y,z β€ n) (not necessarily distinct), a_{x}+a_{y} β a_{z} must hold.
If multiple solutions exist, you may print any.
Example
Input
2
5
4
Output
1 5 3 77 12
384 384 44 44
Note
It can be shown that the outputs above are valid for each test case. For example, 44+44 β 384.
Below are some examples of arrays that are NOT complete for the 1st test case:
[1,2,3,4,5]
Notice that a_{1}+a_{2} = a_{3}.
[1,3000,1,300,1]
Notice that a_{2} = 3000 > 1000. | instruction | 0 | 31,902 | 12 | 63,804 |
Tags: constructive algorithms, implementation
Correct Solution:
```
for _ in range(int(input())):
print(*(int(input()) * [1]))
``` | output | 1 | 31,902 | 12 | 63,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!
An array a of length n is called complete if all elements are positive and don't exceed 1000, and for all indices x,y,z (1 β€ x,y,z β€ n), a_{x}+a_{y} β a_{z} (not necessarily distinct).
You are given one integer n. Please find any complete array of length n. It is guaranteed that under given constraints such array exists.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 1000) β the number of test cases. Description of the test cases follows.
The only line of each test case contains one integer n (1 β€ n β€ 1000).
It is guaranteed that the sum of n over all test cases does not exceed 1000.
Output
For each test case, print a complete array on a single line. All elements have to be integers between 1 and 1000 and for all indices x,y,z (1 β€ x,y,z β€ n) (not necessarily distinct), a_{x}+a_{y} β a_{z} must hold.
If multiple solutions exist, you may print any.
Example
Input
2
5
4
Output
1 5 3 77 12
384 384 44 44
Note
It can be shown that the outputs above are valid for each test case. For example, 44+44 β 384.
Below are some examples of arrays that are NOT complete for the 1st test case:
[1,2,3,4,5]
Notice that a_{1}+a_{2} = a_{3}.
[1,3000,1,300,1]
Notice that a_{2} = 3000 > 1000. | instruction | 0 | 31,903 | 12 | 63,806 |
Tags: constructive algorithms, implementation
Correct Solution:
```
from collections import deque
import copy
for i in range(int(input())):
n=int(input())
print('22 '*n)
``` | output | 1 | 31,903 | 12 | 63,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!
An array a of length n is called complete if all elements are positive and don't exceed 1000, and for all indices x,y,z (1 β€ x,y,z β€ n), a_{x}+a_{y} β a_{z} (not necessarily distinct).
You are given one integer n. Please find any complete array of length n. It is guaranteed that under given constraints such array exists.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 1000) β the number of test cases. Description of the test cases follows.
The only line of each test case contains one integer n (1 β€ n β€ 1000).
It is guaranteed that the sum of n over all test cases does not exceed 1000.
Output
For each test case, print a complete array on a single line. All elements have to be integers between 1 and 1000 and for all indices x,y,z (1 β€ x,y,z β€ n) (not necessarily distinct), a_{x}+a_{y} β a_{z} must hold.
If multiple solutions exist, you may print any.
Example
Input
2
5
4
Output
1 5 3 77 12
384 384 44 44
Note
It can be shown that the outputs above are valid for each test case. For example, 44+44 β 384.
Below are some examples of arrays that are NOT complete for the 1st test case:
[1,2,3,4,5]
Notice that a_{1}+a_{2} = a_{3}.
[1,3000,1,300,1]
Notice that a_{2} = 3000 > 1000. | instruction | 0 | 31,904 | 12 | 63,808 |
Tags: constructive algorithms, implementation
Correct Solution:
```
t=int(input())
for a in range(t):
n=int(input())
for i in range(n):
print(1,end=' ')
print()
``` | output | 1 | 31,904 | 12 | 63,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!
An array a of length n is called complete if all elements are positive and don't exceed 1000, and for all indices x,y,z (1 β€ x,y,z β€ n), a_{x}+a_{y} β a_{z} (not necessarily distinct).
You are given one integer n. Please find any complete array of length n. It is guaranteed that under given constraints such array exists.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 1000) β the number of test cases. Description of the test cases follows.
The only line of each test case contains one integer n (1 β€ n β€ 1000).
It is guaranteed that the sum of n over all test cases does not exceed 1000.
Output
For each test case, print a complete array on a single line. All elements have to be integers between 1 and 1000 and for all indices x,y,z (1 β€ x,y,z β€ n) (not necessarily distinct), a_{x}+a_{y} β a_{z} must hold.
If multiple solutions exist, you may print any.
Example
Input
2
5
4
Output
1 5 3 77 12
384 384 44 44
Note
It can be shown that the outputs above are valid for each test case. For example, 44+44 β 384.
Below are some examples of arrays that are NOT complete for the 1st test case:
[1,2,3,4,5]
Notice that a_{1}+a_{2} = a_{3}.
[1,3000,1,300,1]
Notice that a_{2} = 3000 > 1000. | instruction | 0 | 31,905 | 12 | 63,810 |
Tags: constructive algorithms, implementation
Correct Solution:
```
from sys import stdin, stdout
for i in range(int(stdin.readline())) :
print(*[1 for i in range(int(stdin.readline()))])
``` | output | 1 | 31,905 | 12 | 63,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!
An array a of length n is called complete if all elements are positive and don't exceed 1000, and for all indices x,y,z (1 β€ x,y,z β€ n), a_{x}+a_{y} β a_{z} (not necessarily distinct).
You are given one integer n. Please find any complete array of length n. It is guaranteed that under given constraints such array exists.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 1000) β the number of test cases. Description of the test cases follows.
The only line of each test case contains one integer n (1 β€ n β€ 1000).
It is guaranteed that the sum of n over all test cases does not exceed 1000.
Output
For each test case, print a complete array on a single line. All elements have to be integers between 1 and 1000 and for all indices x,y,z (1 β€ x,y,z β€ n) (not necessarily distinct), a_{x}+a_{y} β a_{z} must hold.
If multiple solutions exist, you may print any.
Example
Input
2
5
4
Output
1 5 3 77 12
384 384 44 44
Note
It can be shown that the outputs above are valid for each test case. For example, 44+44 β 384.
Below are some examples of arrays that are NOT complete for the 1st test case:
[1,2,3,4,5]
Notice that a_{1}+a_{2} = a_{3}.
[1,3000,1,300,1]
Notice that a_{2} = 3000 > 1000. | instruction | 0 | 31,906 | 12 | 63,812 |
Tags: constructive algorithms, implementation
Correct Solution:
```
for t in range(int(input())):
n=int(input())
for i in range(n):
print(1,end=' ')
print('')
``` | output | 1 | 31,906 | 12 | 63,813 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.