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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
The first line contains integer n (1 β€ n β€ 105) β the required permutation size.
Output
Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.
Otherwise, print n distinct integers p1, p2, ..., pn (1 β€ pi β€ n) after a space β the required permutation.
If there are multiple answers, you can print any of them.
Examples
Input
1
Output
1
Input
2
Output
-1
Input
4
Output
2 4 1 3
Input
5
Output
2 5 3 1 4
Submitted Solution:
```
n = int(input())
if n%4 > 1:
print(-1)
exit()
a = [(n+1) // 2] * n
for i in range(n//4):
j = 2*i
a[j], a[j+1], a[-j-2], a[-j-1] = j+2, n-j, j+1, n-j-1
print(' '.join(map(str, a)))
``` | instruction | 0 | 23,174 | 12 | 46,348 |
Yes | output | 1 | 23,174 | 12 | 46,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
The first line contains integer n (1 β€ n β€ 105) β the required permutation size.
Output
Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.
Otherwise, print n distinct integers p1, p2, ..., pn (1 β€ pi β€ n) after a space β the required permutation.
If there are multiple answers, you can print any of them.
Examples
Input
1
Output
1
Input
2
Output
-1
Input
4
Output
2 4 1 3
Input
5
Output
2 5 3 1 4
Submitted Solution:
```
n=int(input())
if(n%4>1):
print(-1)
else:
ans=[0]*(n+1)
i,j,a,b=1,n,1,n
while(i<j and a<=n and b>=1):
ans[i],ans[j]=a+1,b-1
ans[i+1],ans[j-1]=b,a
i+=2
j-=2
a+=2
b-=2
if(i==j):
ans[i]=a
for i in range(1,n+1):
print(ans[i],end=' ')
``` | instruction | 0 | 23,175 | 12 | 46,350 |
Yes | output | 1 | 23,175 | 12 | 46,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
The first line contains integer n (1 β€ n β€ 105) β the required permutation size.
Output
Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.
Otherwise, print n distinct integers p1, p2, ..., pn (1 β€ pi β€ n) after a space β the required permutation.
If there are multiple answers, you can print any of them.
Examples
Input
1
Output
1
Input
2
Output
-1
Input
4
Output
2 4 1 3
Input
5
Output
2 5 3 1 4
Submitted Solution:
```
n = int(input())
if n % 4 > 1:
print(-1)
exit()
a = [i for i in range(0, n+1)]
for i in range(1, n//2+1, 2):
p, q, r, s = i, i+1, n-i,n-i+1
a[p], a[q], a[r], a[s] = a[q], a[s], a[p], a[r]
def check(arr):
for i in range(1, n+1):
k = arr[i]
if arr[arr[k]] != n-k+1:
return False
return True
# print(check(a))
print(*a[1:])
``` | instruction | 0 | 23,176 | 12 | 46,352 |
Yes | output | 1 | 23,176 | 12 | 46,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
The first line contains integer n (1 β€ n β€ 105) β the required permutation size.
Output
Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.
Otherwise, print n distinct integers p1, p2, ..., pn (1 β€ pi β€ n) after a space β the required permutation.
If there are multiple answers, you can print any of them.
Examples
Input
1
Output
1
Input
2
Output
-1
Input
4
Output
2 4 1 3
Input
5
Output
2 5 3 1 4
Submitted Solution:
```
n=int(input())
L=[0]*(n+1)
X=[False]*(n+1)
if(n%4!=0 and n%4!=1):
print(-1)
else:
for i in range(1,n+1):
if(X[i]):
continue
X[i]=True
X[n-i+1]=True
for j in range(i+1,n+1):
if(X[j]):
continue
X[j]=True
X[n-j+1]=True
L[i]=j
L[n-i+1]=n-j+1
L[j]=n-i+1
L[n-j+1]=i
break
if(n%4==1):
L[n//2+1]=n//2+1
for i in range(1,n):
print(L[i],end=" ")
print(L[n])
``` | instruction | 0 | 23,177 | 12 | 46,354 |
Yes | output | 1 | 23,177 | 12 | 46,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
The first line contains integer n (1 β€ n β€ 105) β the required permutation size.
Output
Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.
Otherwise, print n distinct integers p1, p2, ..., pn (1 β€ pi β€ n) after a space β the required permutation.
If there are multiple answers, you can print any of them.
Examples
Input
1
Output
1
Input
2
Output
-1
Input
4
Output
2 4 1 3
Input
5
Output
2 5 3 1 4
Submitted Solution:
```
n=int(input())
if(n%4>1):
print(-1)
else:
ans=[0]*(n+1)
i,j,a,b=1,n,1,n
while(i<j):
ans[i],ans[j]=a+1,b-1
ans[i+1],ans[j-1]=b,a
i+=2
j-=2
a+=2
b+=2
if(i==j):
ans[i]=a
for i in range(1,n+1):
print(ans[i],end=' ')
``` | instruction | 0 | 23,178 | 12 | 46,356 |
No | output | 1 | 23,178 | 12 | 46,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
The first line contains integer n (1 β€ n β€ 105) β the required permutation size.
Output
Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.
Otherwise, print n distinct integers p1, p2, ..., pn (1 β€ pi β€ n) after a space β the required permutation.
If there are multiple answers, you can print any of them.
Examples
Input
1
Output
1
Input
2
Output
-1
Input
4
Output
2 4 1 3
Input
5
Output
2 5 3 1 4
Submitted Solution:
```
n=int(input())
if(n%4>1):
print(-1)
else:
ans=[0]*(n+1)
i,j,a,b=1,n,1,n
while(i<j and a<=n and b>=1):
ans[i],ans[j]=a+1,b-1
ans[i+1],ans[j-1]=b,a
i+=2
j-=2
a+=2
b+=2
if(i==j):
ans[i]=a
for i in range(1,n+1):
print(ans[i],end=' ')
``` | instruction | 0 | 23,179 | 12 | 46,358 |
No | output | 1 | 23,179 | 12 | 46,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
The first line contains integer n (1 β€ n β€ 105) β the required permutation size.
Output
Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.
Otherwise, print n distinct integers p1, p2, ..., pn (1 β€ pi β€ n) after a space β the required permutation.
If there are multiple answers, you can print any of them.
Examples
Input
1
Output
1
Input
2
Output
-1
Input
4
Output
2 4 1 3
Input
5
Output
2 5 3 1 4
Submitted Solution:
```
'''
Created on
@author: linhz
'''
import sys
sys.setrecursionlimit(10000000)
usedNum=0
n=int(input())
p=[0 for i in range(n+1)]
used=[False for i in range(n+1)]
usedNum=0
def loop(i,num):
global usedNum
#print("i: %d num: %d usedNum: %d" %(i,num,usedNum))
#print(p)
if p[i]!=0 and p[i]!=num:
return False
else:
if p[i]==0 and (not used[num]):
p[i]=num
used[num]=True
usedNum+=1
if loop(num,n-i+1):
return True
else:
usedNum-=1
used[num]=False
p[i]=0
return False
elif p[i]==num:
return True
else:
return False
if n==1:
print(1)
if n%4==2 or n%4==3:
print(-1)
else:
i=1
ansFlag=True
while(usedNum<n and ansFlag):
j=1
flag=True
while flag:
while j<=n and used[j]:
j+=1
if(j<=n):
#print("loop i=%d j=%d"%(i,j))
if(loop(i,j)):
#print(p)
flag=False
break
else:
j+=1
else:
ansFlag=False
break
i+=2
ans=""
for i in range(1,n+1):
ans+=str(p[i])+" "
if not ansFlag:
ans="-1"
print(ans)
``` | instruction | 0 | 23,180 | 12 | 46,360 |
No | output | 1 | 23,180 | 12 | 46,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
The first line contains integer n (1 β€ n β€ 105) β the required permutation size.
Output
Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist.
Otherwise, print n distinct integers p1, p2, ..., pn (1 β€ pi β€ n) after a space β the required permutation.
If there are multiple answers, you can print any of them.
Examples
Input
1
Output
1
Input
2
Output
-1
Input
4
Output
2 4 1 3
Input
5
Output
2 5 3 1 4
Submitted Solution:
```
import sys
from collections import deque
n = int(input())
if n % 4 == 2 or n % 4 == 3:
print('-1')
sys.exit(0)
arr = [None] * (n + 1)
qt = deque([i for i in range(1, n + 1)])
mark = set()
while qt:
while qt and qt[0] in mark:
qt.popleft()
if not qt:
break
a = qt.popleft()
while qt and qt[0] in mark:
qt.popleft()
if not qt:
break
b = qt.popleft()
for i in range(4):
mark.add(a)
mark.add(b)
arr[a] = b
arr[b] = n - a + 1
a = b
b = arr[b]
for i in range(1, n + 1):
if not arr[i]:
arr[i] = a
break
``` | instruction | 0 | 23,181 | 12 | 46,362 |
No | output | 1 | 23,181 | 12 | 46,363 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3. | instruction | 0 | 23,398 | 12 | 46,796 |
Tags: binary search, data structures, dp, greedy, implementation, two pointers
Correct Solution:
```
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
arr=[]
for i in range(n):
arr.append(list(map(int,input().split())))
mp = []
for i in range(n):
mp.append(i+1)
for i in range(m):
pre=-1
st=0
for j in range(n):
if arr[j][i]<pre :
pre=arr[j][i]
st=j
mp[j]=min(mp[j],st)
else :
mp[j]=min(mp[j],st)
pre=arr[j][i]
m=int(input())
for i in range(m):
a,b=map(int,input().split())
if mp[b-1]<=a-1 :
print("Yes")
else :
print("No")
``` | output | 1 | 23,398 | 12 | 46,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3. | instruction | 0 | 23,399 | 12 | 46,798 |
Tags: binary search, data structures, dp, greedy, implementation, two pointers
Correct Solution:
```
n,m=map(int,input().split())
A=[]
for _ in range(n):
A.append(list(map(int,input().split())))
dp=[[1 for _ in range(m)] for _ in range(n)]
best=[1 for _ in range(n)]
for i in range(1,n):
for j in range(m):
if A[i][j]>=A[i-1][j]:
dp[i][j]=dp[i-1][j]+1
best[i]=max(best[i],dp[i][j])
# print(best)
ans=""
k=int(input())
for _ in range(k):
l,r=map(int,input().split())
if best[r-1]>=(r-l+1):
ans+="Yes\n"
else:
ans+="No\n"
print(ans)
``` | output | 1 | 23,399 | 12 | 46,799 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3. | instruction | 0 | 23,400 | 12 | 46,800 |
Tags: binary search, data structures, dp, greedy, implementation, two pointers
Correct Solution:
```
import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
# region fastio
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")
stdin, stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
mod = pow(10, 9) + 7
mod2 = 998244353
def inp(): return stdin.readline().strip()
def iinp(): return int(inp())
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
def ceil(a, b): return (a+b-1)//b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def isprime(x):
if x<=1: return False
if x in (2, 3): return True
if x%2 == 0: return False
for i in range(3, int(sqrt(x))+1, 2):
if x%i == 0: return False
return True
n, m = mp()
ml = [lmp() for i in range(n)]
maxEnd = dd(int)
for j in range(m):
c = 1
for i in range(1, n):
if ml[i][j] < ml[i-1][j]:
for x in range(i-c, i):
maxEnd[x] = max(i, maxEnd[x])
c = 1
else:
c += 1
for x in range(n-c, n):
maxEnd[x] = max(n, maxEnd[x])
k = iinp()
for i in range(k):
l, r = mp()
l-=1
print("Yes" if maxEnd[l] >= r else "No")
``` | output | 1 | 23,400 | 12 | 46,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3. | instruction | 0 | 23,401 | 12 | 46,802 |
Tags: binary search, data structures, dp, greedy, implementation, two pointers
Correct Solution:
```
from sys import stdin
n,m =[int(i) for i in stdin.readline().split()]
arr =[[int(i) for i in stdin.readline().split()] for _ in range(n)]
temp = [[1 for i in range(m)] for _ in range(n)]
for i in range(m):
for j in range(n-2,-1,-1):
if arr[j][i]<=arr[j+1][i]:
temp[j][i]+=temp[j+1][i]
l= [0]*(n+1)
for i in range(n):
for j in range(m):
l[i+1] = max(l[i+1],temp[i][j])
k = int(input())
for i in range(k):
l1,r =[int(i) for i in stdin.readline().split()]
if l[l1]>=r-l1+1:
print('Yes')
else:
print('No')
``` | output | 1 | 23,401 | 12 | 46,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3. | instruction | 0 | 23,402 | 12 | 46,804 |
Tags: binary search, data structures, dp, greedy, implementation, two pointers
Correct Solution:
```
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
n,m = ilele()
A = []
for i in range(n):
B = alele()
A.append(B)
dp = [[1 for j in range(m)] for i in range(n) ]
for i in range(1,n):
for j in range(m):
if A[i][j] >= A[i-1][j]:
dp[i][j] = dp[i-1][j] + 1
depth =[0]
for i in dp:
depth.append(max(i))
for _ in range(int(input())):
l,r = ilele()
if l==r:
Yy(1)
else:
Yy(depth[r] >= r-l+1)
``` | output | 1 | 23,402 | 12 | 46,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3. | instruction | 0 | 23,403 | 12 | 46,806 |
Tags: binary search, data structures, dp, greedy, implementation, two pointers
Correct Solution:
```
n,m = map(int,input().split())
M = [list(map(int,input().split())) for i in range(n)]
depth = [[1]*m for i in range(n)]
for col in range(m):
for row in range(1,n):
if M[row][col]>=M[row-1][col]:
depth[row][col] = depth[row-1][col]+1
max_depth = [max(row) for row in depth]
ans = ""
k = int(input())
for i in range(k):
l,r = map(int,input().split())
if max_depth[r-1] >= r-l+1:
ans+="Yes\n"
else:
ans+="No\n"
print(ans)
``` | output | 1 | 23,403 | 12 | 46,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3. | instruction | 0 | 23,404 | 12 | 46,808 |
Tags: binary search, data structures, dp, greedy, implementation, two pointers
Correct Solution:
```
from sys import stdin
input = stdin.readline
n, m = map(int, input().split())
arr = list(list(map(int, input().split())) for _ in range(n))
dp = [[1 for i in range(m)] for j in range(n)]
for i in range(1, n):
for j in range(m):
if arr[i][j] >= arr[i-1][j]:
dp[i][j] = dp[i-1][j] + 1
dp, all_res = [max(i) for i in dp], []
k = int(input())
quries = list(list(map(int, input().split())) for _ in range(k))
for l, r in quries:
all_res.append('Yes' if dp[r-1] >= r-l+1 else 'No')
print('\n'.join(all_res))
``` | output | 1 | 23,404 | 12 | 46,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3. | instruction | 0 | 23,405 | 12 | 46,810 |
Tags: binary search, data structures, dp, greedy, implementation, two pointers
Correct Solution:
```
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = []
for i in range(n):
a.append(list(map(int,input().split())))
count = [[1 for i in range(m)] for j in range(n)]
for i in range(1,n):
for j in range(m):
if a[i][j]>=a[i-1][j]:
count[i][j] = count[i-1][j]+1
maxx = []
for i in range(n):
maxx.append(max(count[i]))
for i in range(int(input())):
l,r = map(int,input().split())
if l==r:
print ("Yes")
continue
if maxx[r-1]>=r-l+1:
print ("Yes")
else:
print ("No")
``` | output | 1 | 23,405 | 12 | 46,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3.
Submitted Solution:
```
from sys import stdin, stdout
n, m = map(int, stdin.readline().strip().split())
arr = [list(map(int, stdin.readline().strip().split())) for i in range(n)]
dp = [[1 for i in range(m)] for i in range(n)]
for i in range(1, n):
for j in range(m):
if arr[i][j] >= arr[i-1][j]: dp[i][j] = dp[i-1][j]+1
# for i in dp:
# print(i)
dp = [max(i) for i in dp]
s = []
for q in range(int(stdin.readline())):
L, R = map(int, stdin.readline().strip().split())
if dp[R-1] >= R-L+1:
s.append("Yes")
else:
s.append("No")
stdout.write("\n".join(s))
``` | instruction | 0 | 23,406 | 12 | 46,812 |
Yes | output | 1 | 23,406 | 12 | 46,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3.
Submitted Solution:
```
import sys
rr=sys.stdin.readline
n,m=map(int,rr().split())
table=[]
for _ in range(n):
table.append(list(map(int,rr().split())))
depth=[[1]*m for _ in range(n)]
for c in range(m):
for r in range(1,n):
if table[r][c]>=table[r-1][c]:
depth[r][c]=depth[r-1][c]+1
max_depth=[max(row) for row in depth]
for _ in range(int(rr())):
l,r=map(int,rr().split())
if l==r:
print("Yes")
else:
if max_depth[r-1]>=r-l+1:
print("Yes")
else:
print("No")
``` | instruction | 0 | 23,407 | 12 | 46,814 |
Yes | output | 1 | 23,407 | 12 | 46,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3.
Submitted Solution:
```
n,m = [int(x) for x in input().split()]
arr = [[int(x) for x in input().split()] for i in range(n)]
val = [ [1]*m for i in range(n)]
for i in range(m):
for j in range(n-2,-1,-1):
if arr[j][i]<=arr[j+1][i]:
val[j][i] = val[j+1][i] + 1
best = [max(i) for i in val]
ans = ""
t = int(input())
for i in range(t):
c,d = [int(x) for x in input().split()]
if best[c-1]>=d-c+1:
ans += "Yes\n"
else:
ans += "No\n"
print(ans)
``` | instruction | 0 | 23,408 | 12 | 46,816 |
Yes | output | 1 | 23,408 | 12 | 46,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3.
Submitted Solution:
```
import sys
n,m = map(int,sys.stdin.readline().rstrip().split())
matrix = []
for _ in range(n):
row = list(map(int,sys.stdin.readline().rstrip().split()))
matrix.append(row)
# initialize table
A = [[1 for _ in range(m)] for _ in range(n)]
for i in range(n-2,-1,-1):
for j in range(m):
if matrix[i][j] <= matrix[i+1][j]:
A[i][j] = A[i+1][j] + 1
# rows = [0] * n
# for i in range(n):
# lst = [A[i][j] for j in range(m)]
# rows[i] = max(lst)
rows = [max(row) for row in A]
ans = ""
k = int(sys.stdin.readline().rstrip())
for _ in range(k):
l,r = map(int,sys.stdin.readline().rstrip().split())
if rows[l-1] >= (r - l + 1):
ans += "Yes\n"
else:
ans += "No\n"
sys.stdout.write(ans)
``` | instruction | 0 | 23,409 | 12 | 46,818 |
Yes | output | 1 | 23,409 | 12 | 46,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3.
Submitted Solution:
```
n,m =[int(i) for i in input().split()]
arr =[[int(i) for i in input().split()] for _ in range(n)]
temp = [[1 for i in range(m)] for _ in range(n)]
for i in range(m):
for j in range(n-2,-1,-1):
if arr[j][i]<=arr[j+1][i]:
temp[j][i]+=temp[j+1][i]
l= [0]*(n+1)
for i in range(n):
for j in range(m):
l[i+1] = max(l[i+1],temp[i][j])
k = int(input())
for i in range(k):
l1,r =[int(i) for i in input().split()]
if l[l1]>=r-l1+1:
print('YES')
else:
print('NO')
``` | instruction | 0 | 23,410 | 12 | 46,820 |
No | output | 1 | 23,410 | 12 | 46,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3.
Submitted Solution:
```
from collections import Counter
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
# print(a)
k = int(input())
lr = [list(map(int, input().split())) for _ in range(k)]
# print(lr)
a = list(zip(*a))
# print(a)
newa = Counter()
for row in a:
start = 0
i = 0
for i in range(n-1):
if row[i+1] < row[i]:
if i - start > newa[start]:
newa[start] = i - start
start = i + 1
if i + 1 - start > newa[start]:
newa[start] = i + 1 - start
# print(newa)
for bound in lr:
if newa[bound[0]-1] >= bound[1] - bound[0]:
print('Yes')
else:
print('No')
``` | instruction | 0 | 23,411 | 12 | 46,822 |
No | output | 1 | 23,411 | 12 | 46,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3.
Submitted Solution:
```
n,m=[int(x)for x in input().split()]
a=[]
for x in range(n):
a+=[[int(f)for f in input().split()]]
for x in range(int(input())):
y=True
l,r=[int(f)for f in input().split()]
for z in range(m):
o=False
t=[]
if abs(l-r)>0:
for y in range(l-1,r-1):
if a[y][z]>=a[y+1][z]:
t+=[True]
else:
t+=[False]
else:y=True
if all(t):
print('YES')
o=True
break
y=False
if o==False:print('NO')
``` | instruction | 0 | 23,412 | 12 | 46,824 |
No | output | 1 | 23,412 | 12 | 46,825 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in non-decreasing order in the column j if ai, j β€ ai + 1, j for all i from 1 to n - 1.
Teacher gave Alyona k tasks. For each of the tasks two integers l and r are given and Alyona has to answer the following question: if one keeps the rows from l to r inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such j that ai, j β€ ai + 1, j for all i from l to r - 1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input
The first line of the input contains two positive integers n and m (1 β€ nΒ·m β€ 100 000) β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai, j (1 β€ ai, j β€ 109).
The next line of the input contains an integer k (1 β€ k β€ 100 000) β the number of task that teacher gave to Alyona.
The i-th of the next k lines contains two integers li and ri (1 β€ li β€ ri β€ n).
Output
Print "Yes" to the i-th line of the output if the table consisting of rows from li to ri inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Example
Input
5 4
1 2 3 5
3 1 3 2
4 5 2 3
5 5 3 2
4 4 3 4
6
1 1
2 5
4 5
3 5
1 3
1 5
Output
Yes
No
Yes
Yes
Yes
No
Note
In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3.
Submitted Solution:
```
n,m = map(int,input().strip().split(' '))
mat = []
for i in range(n):
mat.append(list(map(int,input().strip().split(' '))))
dp = [[0] * m for z in range(n)]
for j in range(m):
for i in range(1,n):
if mat[i][j] >= mat[i-1][j]:
dp[i][j] = dp[i-1][j]+ 1
k = int(input())
for q in range(k):
l,r = map(int,input().strip().split(' '))
i=0
j=m-1
flage = False
while(i < j):
sv1 = dp[r-1][i] - dp[l-1][i]
sv2 = dp[r-1][j] - dp[l-1][j]
if sv1 == r-l or sv2 == r-l:
print('Yes')
flage = True
break
i+=1
j-=1
if flage == False:
print('No')
``` | instruction | 0 | 23,413 | 12 | 46,826 |
No | output | 1 | 23,413 | 12 | 46,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. | instruction | 0 | 23,478 | 12 | 46,956 |
Tags: binary search, math, sortings, two pointers
Correct Solution:
```
from bisect import bisect_left
R=lambda:map(int,input().split())
n,x,k=R()
a=sorted(R())
cnt=0
for u in a:
l=((u+x-1)//x+k-1)*x
cnt+=bisect_left(a,l+x)-bisect_left(a,max(u,l))
print(cnt)
``` | output | 1 | 23,478 | 12 | 46,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. | instruction | 0 | 23,479 | 12 | 46,958 |
Tags: binary search, math, sortings, two pointers
Correct Solution:
```
import bisect
import math
n, x, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans = 0
for i in a:
l = math.ceil(i/x)*x + (k-1)*x
r = l + x - 1
if (l < i): l = i
else: l = l
ans += bisect.bisect_right(a, r) - bisect.bisect_left(a, l)
print(ans)
``` | output | 1 | 23,479 | 12 | 46,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. | instruction | 0 | 23,480 | 12 | 46,960 |
Tags: binary search, math, sortings, two pointers
Correct Solution:
```
from bisect import bisect_left as b
f = lambda: map(int, input().split())
n, x, k = f()
s, t = 0, sorted(f())
p = [(q, ((q - 1) // x + k) * x) for q in t]
for q, d in p: s += b(t, d + x) - b(t, max(q, d))
print(s)
``` | output | 1 | 23,480 | 12 | 46,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. | instruction | 0 | 23,481 | 12 | 46,962 |
Tags: binary search, math, sortings, two pointers
Correct Solution:
```
import random, math
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right
# Function to call the actual solution
def solution(li, x, k):
li.sort()
# print(li)
s = 0
tot = 0
for i in range(len(li)):
l = math.ceil(li[i]/x)*x + (k-1) * x
r = l + x - 1
l = max(l, li[i])
mid = bisect_left(li, l)
up = bisect_right(li, r)
tot += up - mid
# print(l, r)
return tot
# Function to take input
def input_test():
n, x, k = map(int, input().strip().split(" "))
li = list(map(int, input().strip().split(" ")))
out = solution(li, x, k)
print(out)
input_test()
# test()
``` | output | 1 | 23,481 | 12 | 46,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. | instruction | 0 | 23,482 | 12 | 46,964 |
Tags: binary search, math, sortings, two pointers
Correct Solution:
```
import math
import sys
import getpass
import bisect
def ria():
return [int(i) for i in input().split()]
files = True
if getpass.getuser().lower() == 'frohenk' and files:
sys.stdin = open('test.in')
# sys.stdout = open('test.out', 'w')
n, x, k = ria()
ar = ria()
ar = sorted(ar)
suma=0
for i in ar:
l = math.ceil(i / x) * x+x * (k-1)
r = math.ceil(i / x) * x + x * k - 1
#print(l,r)
if k == 0:
l = i
r = math.ceil(i / x) * x + x * k - 1
#print(l, r)
suma-=(bisect.bisect_left(ar, l)- bisect.bisect_right(ar, r))
print(suma)
sys.stdout.close()
``` | output | 1 | 23,482 | 12 | 46,965 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. | instruction | 0 | 23,483 | 12 | 46,966 |
Tags: binary search, math, sortings, two pointers
Correct Solution:
```
import bisect
def lower_bound(A, x):
low = 0
high = len(A)
while(low < high):
mid = (low + high) // 2
if(int(A[mid]) < x):
low = mid + 1
else:
high = mid
return low
def upper_bound(A, x):
low = 0
high = len(A)
while(low < high):
mid = (low + high) // 2
if(int(A[mid]) <= x):
low = mid + 1
else:
high = mid
return low
line = input().split()
n = int(line[0])
x = int(line[1])
k = int(line[2])
a = [int(x) for x in input().split()]
a.sort()
ans = 0
for i in a:
left = (i + x - 1) // x * x
right = left + x * k - 1
left = left + (k - 1) * x
left = max(left, i)
ans = ans + bisect.bisect_right(a, right) - bisect.bisect_left(a, left)
# print(left, right, ans)
print(ans)
``` | output | 1 | 23,483 | 12 | 46,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. | instruction | 0 | 23,484 | 12 | 46,968 |
Tags: binary search, math, sortings, two pointers
Correct Solution:
```
from sys import stdin,stdout
from math import gcd,sqrt,factorial,pi,inf
from collections import deque,defaultdict
from bisect import bisect,bisect_left
from time import time
from itertools import permutations as per
from heapq import heapify,heappush,heappop,heappushpop
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
S=lambda:input().rstrip('\r\n')
L=lambda:list(R())
P=lambda x:stdout.write(str(x)+'\n')
lcm=lambda x,y:(x*y)//gcd(x,y)
nCr=lambda x,y:(f[x]*inv((f[y]*f[x-y])%N))%N
inv=lambda x:pow(x,N-2,N)
sm=lambda x:(x**2+x)//2
N=10**9+7
n,x,k=R()
a=sorted(R())
ans=0
val=x*k
for i in a:
if k==0 and not i%x:
continue
p=i+x-i%x-1+val-(x if i%x==0 else 0)
ans+=bisect(a,p)-bisect_left(a,max(i,p-(x-1)))
#print(p)
print(ans)
``` | output | 1 | 23,484 | 12 | 46,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. | instruction | 0 | 23,485 | 12 | 46,970 |
Tags: binary search, math, sortings, two pointers
Correct Solution:
```
import sys
from bisect import *
import math
N,X,K = map(int, input().split())
p = sorted(list(map(int, input().split())))
def get(l, r):
return (r//X) - (l-1)//X
p = sorted(p)
mp = {}
n = len(p)
for i in range(n):
if p[i] in mp:
continue
else:
mp[p[i]] = i
x = 5
ans = 0
mx = 0
for i in range(0,n):
x = p[i]
a = x//X
mn = 0
mx = 0
if x % X == 0 :
mn = x + (K-1)*X
mx = mn + X-1
else:
mn =(x//X)*X + (K)*X
mx = mn + X-1
if K == 0:
if x%X == 0 :
continue
mn = x
mx = (x//X)*X+X-1
#print(x,mn,mx)
if mn > mx:
continue
ans = ans + bisect_right(p,mx) - bisect_left(p,mn)
print(ans)
``` | output | 1 | 23,485 | 12 | 46,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
Submitted Solution:
```
from bisect import bisect_left as b
R=lambda:map(int,input().split())
n,x,k=R()
a=sorted(R())
print(sum(b(a,l+x)-b(a,max(u,l)) for u,l in ((u,((u-1)//x+k)*x) for u in a)))
``` | instruction | 0 | 23,486 | 12 | 46,972 |
Yes | output | 1 | 23,486 | 12 | 46,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
Submitted Solution:
```
import math
import bisect
n, x, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans = 0
for num in a:
l = math.ceil(num/x)*x + (k-1)*x
r = l + x - 1
l = num if l < num else l
# print(l, r, bisect.bisect_left(a, l), bisect.bisect_right(a, r), bisect.bisect_right(a, r) - bisect.bisect_left(a, l))
ans += bisect.bisect_right(a, r) - bisect.bisect_left(a, l)
print(ans)
'''
7 3 2
1 3 5 9 11 16 25
'''
'''
4 2 0
5 3 1 7
'''
``` | instruction | 0 | 23,489 | 12 | 46,978 |
Yes | output | 1 | 23,489 | 12 | 46,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
Submitted Solution:
```
import sys
from bisect import *
import math
N,X,K = map(int, input().split())
p = sorted(list(map(int, input().split())))
def get(l, r):
return (r//X) - (l-1)//X
p = sorted(p)
mp = {}
n = len(p)
for i in range(n):
if p[i] in mp:
continue
else:
mp[p[i]] = i
x = 5
ans = 0
mx = 0
for i in range(0,n):
x = p[i]
a = x//X
mn = 0
mx = 0
if x % X == 0 :
mn = x + (K-1)*X
mx = mn + X-1
else:
mn = max(x, (x//X)*X + (K)*X)
mx = mn + X-1
#print(x,mn,mx)
if mn > mx:
continue
ans = ans + bisect_right(p,mx) - bisect_left(p,mn)
print(ans)
``` | instruction | 0 | 23,490 | 12 | 46,980 |
No | output | 1 | 23,490 | 12 | 46,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
Submitted Solution:
```
import fileinput
import sys
# http://codeforces.com/contest/895/problem/B
class InputData:
def __init__(self, n, x, k, arr):
self.arr = arr
self.k = k
self.x = x
self.n = n
class Result:
def __init__(self, n):
self.n = n
def __str__(self):
return '{}'.format(self.n)
def get_z_between(a_i, a_j):
if a_i == a_j:
return [a_i]
result = list(range(a_i, a_j))[1:]
return result
def get_nums_devided_by_x(z_between, x):
results = []
for z in z_between:
if z % x == 0:
results.append(z)
return results
def solve(input_data: InputData) -> Result:
arr = input_data.arr
n = input_data.n
x = input_data.x
k = input_data.k
idxs = []
for i, a_i in enumerate(arr):
for j, a_j in enumerate(arr):
if a_i <= a_j:
z_between = get_z_between(a_i, a_j)
nums_devide_by_x = get_nums_devided_by_x(z_between, x)
if len(nums_devide_by_x) == k:
idxs.append((i, j))
return Result(len(idxs))
def get_int_arr(line):
return [int(num) for num in line.replace('\n', '').split(' ')]
def main():
input = fileinput.input(sys.argv[1:])
n, x, k = tuple(get_int_arr(input.readline()))
arr = get_int_arr(input.readline())
input_data = InputData(n, x, k, arr)
result = solve(input_data)
sys.stdout.write(str(result))
if __name__ == '__main__':
main()
``` | instruction | 0 | 23,491 | 12 | 46,982 |
No | output | 1 | 23,491 | 12 | 46,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai β€ aj and there are exactly k integers y such that ai β€ y β€ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
Input
The first line contains 3 integers n, x, k (1 β€ n β€ 105, 1 β€ x β€ 109, 0 β€ k β€ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 β€ ai β€ 109) β the elements of the array a.
Output
Print one integer β the answer to the problem.
Examples
Input
4 2 1
1 3 5 7
Output
3
Input
4 2 0
5 3 1 7
Output
4
Input
5 3 1
3 3 3 3 3
Output
25
Note
In first sample there are only three suitable pairs of indexes β (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
Submitted Solution:
```
n, x, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
def num(i, j):
if j < i:
return -1
return ((j - i) - (i % x)) // x + 1
s = 0
i = j = prev_j = 0
while i < n:
while j < n and num(l[i], l[j]) < k:
j += 1
if j < n:
prev_j = max(0, j - 1)
if num(l[i], l[j]) == k:
old_s = s
# print(l[i], l[j])
s += 1
j += 1
while (j < n and num(l[i], l[j]) == k):
# print(l[i], l[j])
s += 1
j += 1
c = 0
while (i < n-1 and l[i+1] == l[i]):
c += 1
i += 1
s += (s - old_s) * c
i += 1
j = prev_j
else:
break
print(s)
``` | instruction | 0 | 23,493 | 12 | 46,986 |
No | output | 1 | 23,493 | 12 | 46,987 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | instruction | 0 | 23,542 | 12 | 47,084 |
Tags: implementation, sortings
Correct Solution:
```
# explode array
def explode(array):
unique = set(array)
if 0 in unique:
return len(unique) - 1
return len(unique)
if __name__ == "__main__":
n = int(input().strip())
array = list(map(int, input().strip().split()))
print(explode(array))
``` | output | 1 | 23,542 | 12 | 47,085 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | instruction | 0 | 23,543 | 12 | 47,086 |
Tags: implementation, sortings
Correct Solution:
```
n=int(input())
t=list(map(int,input().split()))
t.sort()
x=0
if len(t)>0 and t.count(0)!=len(t):
for b in range(len(t)):
if t[b]<0:
p = -1*(t[b])
break
elif t[b]>0:
p = -1*(t[b])
break
else:
pass
elif t.count(0)==len(t):
print(0)
x+=1
for j in range(len(t)):
if t[j]!=0:
t[j]+=p
if x==0:
if 0 in t:
print(len(set(t)))
else:
print(len(set(t))+1)
``` | output | 1 | 23,543 | 12 | 47,087 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | instruction | 0 | 23,544 | 12 | 47,088 |
Tags: implementation, sortings
Correct Solution:
```
from collections import Counter
n = int(input())
arr = Counter(int(x) for x in input().split())
ans = len(arr) - int(0 in arr)
print(ans)
``` | output | 1 | 23,544 | 12 | 47,089 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | instruction | 0 | 23,545 | 12 | 47,090 |
Tags: implementation, sortings
Correct Solution:
```
n = int(input())
counter = set(list(map(int, input().split())))
print(len(counter)-1 if 0 in counter else len(counter))
``` | output | 1 | 23,545 | 12 | 47,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | instruction | 0 | 23,546 | 12 | 47,092 |
Tags: implementation, sortings
Correct Solution:
```
n = int(input())
arr = input().split(" ")
print (len(set([a for a in arr if int(a) != 0])))
``` | output | 1 | 23,546 | 12 | 47,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | instruction | 0 | 23,547 | 12 | 47,094 |
Tags: implementation, sortings
Correct Solution:
```
n=int(input())
read=lambda:map(int,input().split())
s=set()
for x in list(read()):
if x!=0:
s.add(x)
print(len(s))
``` | output | 1 | 23,547 | 12 | 47,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | instruction | 0 | 23,548 | 12 | 47,096 |
Tags: implementation, sortings
Correct Solution:
```
n = int(input())
nums = list(map(int,input().split()))
counts = set()
for num in nums:
counts.add(num)
if 0 in counts:
counts.remove(0)
print(len(counts))
``` | output | 1 | 23,548 | 12 | 47,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | instruction | 0 | 23,549 | 12 | 47,098 |
Tags: implementation, sortings
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
s = set()
for i in a:
if i != 0:
s.add(i)
print(len(s))
``` | output | 1 | 23,549 | 12 | 47,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
Submitted Solution:
```
a=int(input())
distinct=set()
b=list(map(int,input().split()))
for i in range(a):
distinct.add(b[i])
if 0 in distinct:
distinct.remove(0)
print(len(distinct))
``` | instruction | 0 | 23,550 | 12 | 47,100 |
Yes | output | 1 | 23,550 | 12 | 47,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
Submitted Solution:
```
n = int(input())
l = [int(x) for x in input().split()]
print(len(set(l)) - (0, 1)[0 in l])
``` | instruction | 0 | 23,551 | 12 | 47,102 |
Yes | output | 1 | 23,551 | 12 | 47,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
Submitted Solution:
```
n = int(input())
spisok = list(map(int, input().split()))
if 0 in spisok:
print(len(set(spisok)) - 1)
else:
print(len(set(spisok)))
``` | instruction | 0 | 23,552 | 12 | 47,104 |
Yes | output | 1 | 23,552 | 12 | 47,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
Submitted Solution:
```
input()
s = set(input().split())
print(len(s) - ('0' in s))
``` | instruction | 0 | 23,553 | 12 | 47,106 |
Yes | output | 1 | 23,553 | 12 | 47,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
* When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
Input
The first line contains a single integer n (1 β€ n β€ 105) β the size of the array.
The second line contains n integers a1, a2, ..., an ( - 105 β€ ai β€ 105) β the elements of the array.
Output
Print a single integer β the minimum number of seconds needed to make all elements of the array equal to zero.
Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
Note
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
Submitted Solution:
```
#http://codeforces.com/contest/992/problem/0
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x=Counter(a)
sw=0
print (len(x)-x[0])
``` | instruction | 0 | 23,554 | 12 | 47,108 |
No | output | 1 | 23,554 | 12 | 47,109 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.