message stringlengths 2 433k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 113 108k | cluster float64 12 12 | __index_level_0__ int64 226 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to ... | instruction | 0 | 12,013 | 12 | 24,026 |
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
s = sum(a)
if s % 3 != 0:
print(0)
else:
b = [a[0]]
s = s//3
for i in range(1,n):
b.append(b[i-1]+a[i])
if s==0:
m = b.count(0)
pri... | output | 1 | 12,013 | 12 | 24,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to ... | instruction | 0 | 12,014 | 12 | 24,028 |
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
m = 0
c = 0
ans = 0
if s % 3 == 0:
s //= 3
for i in range(n-1):
m += a[i]
if m == s * 2:
ans += c
if m == s:
c... | output | 1 | 12,014 | 12 | 24,029 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to ... | instruction | 0 | 12,015 | 12 | 24,030 |
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
ret, s = 0, sum(a)
if s % 3 == 0:
p1 = s // 3
p2 = s - p1
s = c = 0
for i in range(n - 1):
s += a[i]
if s == p2:
ret += c
if... | output | 1 | 12,015 | 12 | 24,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to ... | instruction | 0 | 12,016 | 12 | 24,032 |
Tags: binary search, brute force, data structures, dp, two pointers
Correct Solution:
```
def countways(a, n):
cnt = [0 for i in range(n)]
s = 0
s = sum(a)
if (s % 3 != 0):
return 0
s //= 3
ss = 0
for i in range(n - 1, -1, -1):
ss += a[i]
if (ss == s):
cnt... | output | 1 | 12,016 | 12 | 24,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each ... | instruction | 0 | 12,017 | 12 | 24,034 |
Yes | output | 1 | 12,017 | 12 | 24,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each ... | instruction | 0 | 12,019 | 12 | 24,038 |
Yes | output | 1 | 12,019 | 12 | 24,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each ... | instruction | 0 | 12,020 | 12 | 24,040 |
Yes | output | 1 | 12,020 | 12 | 24,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each ... | instruction | 0 | 12,022 | 12 | 24,044 |
No | output | 1 | 12,022 | 12 | 24,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each ... | instruction | 0 | 12,023 | 12 | 24,046 |
No | output | 1 | 12,023 | 12 | 24,047 |
Provide tags and a correct Python 2 solution for this coding contest problem.
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of... | instruction | 0 | 12,218 | 12 | 24,436 |
Tags: constructive algorithms
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
mod=1000000007
def in_num():
return int(raw_input())
def in_arr():
return map(int,raw_in... | output | 1 | 12,218 | 12 | 24,437 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater th... | instruction | 0 | 12,227 | 12 | 24,454 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
a = [int(s) for s in input().split(' ')]
e = 0
for i in range(1, n - 1):
if a[i] > max(a[i - 1], a[i + 1]) or a[i] < min(a[i - 1], a[i + 1]):
e += 1
print(e)
``` | output | 1 | 12,227 | 12 | 24,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater th... | instruction | 0 | 12,228 | 12 | 24,456 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
x = list(map(int,input().split()))
r = 0
if n<=2:
print(0)
else:
for i in range(1,n-1):
if x[i]>x[i-1] and x[i]>x[i+1]:
r+=1
if x[i]<x[i-1] and x[i]<x[i+1]:
r+=1
print(r)
``` | output | 1 | 12,228 | 12 | 24,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater th... | instruction | 0 | 12,229 | 12 | 24,458 |
Tags: brute force, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
from math import*
############ ---- Input Functions ---- ############
def inp():
return(int(input().strip()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1... | output | 1 | 12,229 | 12 | 24,459 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater th... | instruction | 0 | 12,230 | 12 | 24,460 |
Tags: brute force, implementation
Correct Solution:
```
number = int(input())
num = 0
lst = [int(i) for i in input().split()][:number]
for i in range(len(lst)):
if not(i == 0 or i == len(lst)-1) and (lst[i] > lst[i-1] and lst[i]>lst[i+1] or lst[i]<lst[i-1] and lst[i]<lst[i+1]):
num+=1
print(num)
``` | output | 1 | 12,230 | 12 | 24,461 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater th... | instruction | 0 | 12,231 | 12 | 24,462 |
Tags: brute force, implementation
Correct Solution:
```
def find_extrema(n, lst):
maxima = list()
minima = list()
if n >= 3:
for i in range(1, n - 1):
if lst[i] > lst[i - 1] and lst[i] > lst[i + 1]:
maxima.append(lst[i])
elif lst[i] < lst[i - 1] and lst[i] < l... | output | 1 | 12,231 | 12 | 24,463 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater th... | instruction | 0 | 12,232 | 12 | 24,464 |
Tags: brute force, implementation
Correct Solution:
```
def main():
input()
nums = list(map(int, input().split()))
lastn = nums.pop(0)
mc = 0
while len(nums) > 1:
buff = nums.pop(0)
if (lastn < buff and buff > nums[0]) or (lastn > buff and buff < nums[0]):
mc += 1
lastn = buff
return mc
if __name__ ... | output | 1 | 12,232 | 12 | 24,465 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater th... | instruction | 0 | 12,233 | 12 | 24,466 |
Tags: brute force, implementation
Correct Solution:
```
x=input()
x=int(x)
y=input()
y=y.split()
min1=0
max1=0
for i in range(1,x-1):
if int(y[i]) < int(y[i-1]) and int(y[i])<int(y[i+1]):
min1=min1+1
if int(y[i])>int(y[i+1]) and int(y[i])>int(y[i-1]):
max1=max1+1
res=min1+max1
if x==2 or x==1:
print... | output | 1 | 12,233 | 12 | 24,467 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater th... | instruction | 0 | 12,234 | 12 | 24,468 |
Tags: brute force, implementation
Correct Solution:
```
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# from math import *
# from itertools import *
# import random
n = int(input())
arr = list(map(int, input().split()))
count_ = 0
for i in range(1, n-1):
if (arr[i] < arr[i-1] and arr[i] < arr[i+1]) or (arr[i] > a... | output | 1 | 12,234 | 12 | 24,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be cal... | instruction | 0 | 12,235 | 12 | 24,470 |
Yes | output | 1 | 12,235 | 12 | 24,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be cal... | instruction | 0 | 12,236 | 12 | 24,472 |
Yes | output | 1 | 12,236 | 12 | 24,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be cal... | instruction | 0 | 12,237 | 12 | 24,474 |
Yes | output | 1 | 12,237 | 12 | 24,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be cal... | instruction | 0 | 12,238 | 12 | 24,476 |
Yes | output | 1 | 12,238 | 12 | 24,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be cal... | instruction | 0 | 12,239 | 12 | 24,478 |
No | output | 1 | 12,239 | 12 | 24,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be cal... | instruction | 0 | 12,240 | 12 | 24,480 |
No | output | 1 | 12,240 | 12 | 24,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be cal... | instruction | 0 | 12,241 | 12 | 24,482 |
No | output | 1 | 12,241 | 12 | 24,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be cal... | instruction | 0 | 12,242 | 12 | 24,484 |
No | output | 1 | 12,242 | 12 | 24,485 |
Provide a correct Python 3 solution for this coding contest problem.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longest decreasing subsequence is B.
If it exists, construc... | instruction | 0 | 12,349 | 12 | 24,698 |
"Correct Solution:
```
N, A, B = map(int, input().split())
if N < A + B - 1 :
print(-1)
else :
if A > B :
mode = 0
A -= 1
else :
mode = 1
B -= 1
ret = []
u = N - A + 1
l = B
while len(ret) < N :
if (mode and A == 0) or (not mode and B ==... | output | 1 | 12,349 | 12 | 24,699 |
Provide a correct Python 3 solution for this coding contest problem.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longest decreasing subsequence is B.
If it exists, construc... | instruction | 0 | 12,350 | 12 | 24,700 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
"""
n-増大列、m-減少列まで -> 長さ nm 以下であることを示す。帰納法。
(n+1)m + 1 項があるとする。(n+2増大 or m+1減少)の存在をいう。
A:左 nm 項 B:右 m+1 項
Aに1項加えると、(n+1,m+1)のどちらかができる。(n+1)-増大ができるとしてよい。
Bの各項 b に対して、bで終わる(n+1)-増大列が存在する。
Bの中に2-増大列があれば(n+2)増大列ができる。そうでなければBが(m+1)-減少列なのでよい
"""
N,A,B = map(int,i... | output | 1 | 12,350 | 12 | 24,701 |
Provide a correct Python 3 solution for this coding contest problem.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longest decreasing subsequence is B.
If it exists, construc... | instruction | 0 | 12,351 | 12 | 24,702 |
"Correct Solution:
```
N, A, B = map(int, input().split())
if A * B < N:
print(-1)
elif A + B - 1 > N:
print(-1)
else:
P = [0] * N
b = (N - A) // (B - 1) if B > 1 else 0
r = (N - A) % (B - 1) + 1 if B > 1 else 1
i = 1
pos = 0
while i <= N:
if b:
for j in range(B):
P[pos + B - j - 1] =... | output | 1 | 12,351 | 12 | 24,703 |
Provide a correct Python 3 solution for this coding contest problem.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longest decreasing subsequence is B.
If it exists, construc... | instruction | 0 | 12,352 | 12 | 24,704 |
"Correct Solution:
```
N, A, B = map(int, input().split())
ans = list(range(A))
m = 0
rest = N - A
B -= 1
if rest < B:
print(-1)
exit()
if rest / A > B:
print(-1)
exit()
while rest > B:
s = min(A, rest - B + 1)
ans += list(range(m - s, m))
m -= s
rest -= s
B -= 1
ans += list(range(m - B, m))[::-1]
... | output | 1 | 12,352 | 12 | 24,705 |
Provide a correct Python 3 solution for this coding contest problem.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longest decreasing subsequence is B.
If it exists, construc... | instruction | 0 | 12,353 | 12 | 24,706 |
"Correct Solution:
```
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, A, B = mapint()
from collections import deque
if A+B-1>N or N>A*B:
print(-1)
else:
blocks = []
blocks.append(' '.join(map(str, range(B, 0, -1))))... | output | 1 | 12,353 | 12 | 24,707 |
Provide a correct Python 3 solution for this coding contest problem.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longest decreasing subsequence is B.
If it exists, construc... | instruction | 0 | 12,354 | 12 | 24,708 |
"Correct Solution:
```
n,a,b=map(int,input().split())
if a+b-1>n:exit(print(-1))
if a*b<n:exit(print(-1))
ans=[]
c=0
nn=n
for i in range(a):
ans.append([])
t=0--nn//(a-i)
if i==0:
t=b
nn-=min(t,b)
for j in range(min(b,t)):
ans[-1].append((i+1)*b-j)
c+=1
if c==n:break
if c==n:break
anss=[]
fo... | output | 1 | 12,354 | 12 | 24,709 |
Provide a correct Python 3 solution for this coding contest problem.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longest decreasing subsequence is B.
If it exists, construc... | instruction | 0 | 12,355 | 12 | 24,710 |
"Correct Solution:
```
r,p=range,print
n,a,b=map(int,input().split())
if a+b>n+1or a*b<n:exit(p(-1))
l=[[]for i in r(b-1)]+[list(r(1,a+1))]
for i in r(a,n):l[-2-(i-a)%(b-1)]+=[i+1]
for i in l:p(*i,end=" ")
``` | output | 1 | 12,355 | 12 | 24,711 |
Provide a correct Python 3 solution for this coding contest problem.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longest decreasing subsequence is B.
If it exists, construc... | instruction | 0 | 12,356 | 12 | 24,712 |
"Correct Solution:
```
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A, B):
if A + B - 1 > N or A * B < N:
print(-1)
return
P = []
r = A * B - N
for b in range(B):
for a in range(A):
if b >= 1 and a >= 1 and r > 0:
if r >= A - 1... | output | 1 | 12,356 | 12 | 24,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longes... | instruction | 0 | 12,358 | 12 | 24,716 |
Yes | output | 1 | 12,358 | 12 | 24,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longes... | instruction | 0 | 12,361 | 12 | 24,722 |
No | output | 1 | 12,361 | 12 | 24,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:
* The length of its longest increasing subsequence is A.
* The length of its longes... | instruction | 0 | 12,364 | 12 | 24,728 |
No | output | 1 | 12,364 | 12 | 24,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
The first line of each test c... | instruction | 0 | 12,698 | 12 | 25,396 |
Tags: data structures, hashing, math
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
x = a[i]-i
if x in d:
d[x] += 1
else:
d[x] = 1
count = 0
for i in d:
count += ((d[i]*(d[i]-1))//2)
print(count)
``` | output | 1 | 12,698 | 12 | 25,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
The first line of each test c... | instruction | 0 | 12,699 | 12 | 25,398 |
Tags: data structures, hashing, math
Correct Solution:
```
cases = int(input())
for _ in range(cases):
n = int(input())
ints = [int(n) for n in input().split(" ")]
counts = {}
for i in range(n):
if ints[i]-i not in counts.keys():
counts[ints[i]-i] = 0
counts[ints[i]-i] += 1... | output | 1 | 12,699 | 12 | 25,399 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
The first line of each test c... | instruction | 0 | 12,700 | 12 | 25,400 |
Tags: data structures, hashing, math
Correct Solution:
```
def main():
n=int(input())
a=list(map(int,input().split()))
dictt={}
for i in range(n):
a[i]-=i
# print(a)
for x in a:
if x in dictt:
dictt[x]=dictt[x]+1
else:
dictt[x]=1
ans=0
for ... | output | 1 | 12,700 | 12 | 25,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
The first line of each test c... | instruction | 0 | 12,701 | 12 | 25,402 |
Tags: data structures, hashing, math
Correct Solution:
```
def solve(l,n):
t={}
for i in range(n):
if (l[i]-i) in t:
t[l[i]-i]+=1
else:
t[l[i]-i]=1
ans=0
for i in t.values():
ans=ans+(i*(i-1))//2
return ans
for _ in range(int(input())):
n = int(input())
l = li... | output | 1 | 12,701 | 12 | 25,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
The first line of each test c... | instruction | 0 | 12,702 | 12 | 25,404 |
Tags: data structures, hashing, math
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
s = 0
k = {}
for i in range(n):
k[a[i]-i] = k.get(a[i]-i,0) + 1
for u in k.keys():
s += (k[u]*(k[u]-1))//2
print(s)
print()
... | output | 1 | 12,702 | 12 | 25,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
The first line of each test c... | instruction | 0 | 12,703 | 12 | 25,406 |
Tags: data structures, hashing, math
Correct Solution:
```
from collections import defaultdict
t=int(input())
for i in range(t):
n=int(input())
ar=list(map(int,input().split()))
d=defaultdict(int)
ans=0
for i in range(n):
ans+=d[ar[i]-i]
d[ar[i]-i]+=1
print(ans)
``` | output | 1 | 12,703 | 12 | 25,407 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
The first line of each test c... | instruction | 0 | 12,704 | 12 | 25,408 |
Tags: data structures, hashing, math
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().strip().split()))
d={}
for i in range(n):
l[i]=l[i]-i
d[l[i]]=d.get(l[i],0)+1
c=0
for i in d:
if(d[i]>=2):
c=c+(d[i]-1)*d[i]//2
p... | output | 1 | 12,704 | 12 | 25,409 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
The first line of each test c... | instruction | 0 | 12,705 | 12 | 25,410 |
Tags: data structures, hashing, math
Correct Solution:
```
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
#import io,os; input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #for pypy
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]
for _ in range(1,inp(... | output | 1 | 12,705 | 12 | 25,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i.
Input
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t te... | instruction | 0 | 12,708 | 12 | 25,416 |
Yes | output | 1 | 12,708 | 12 | 25,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj.
Input
The first line contains two integers n, m (1 ≤ n, m ... | instruction | 0 | 12,907 | 12 | 25,814 |
Tags: binary search, data structures, sortings, two pointers
Correct Solution:
```
import bisect
if __name__ == "__main__":
n , m = [int(x) for x in input().strip().split()]
a = sorted([int(x) for x in input().strip().split()])
b = [int(x) for x in input().strip().split()]
res = []
for bi in b:
... | output | 1 | 12,907 | 12 | 25,815 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj.
Input
The first line contains two integers n, m (1 ≤ n, m ... | instruction | 0 | 12,908 | 12 | 25,816 |
Tags: binary search, data structures, sortings, two pointers
Correct Solution:
```
#editorial approch
from bisect import bisect_right
x, y = map(int, input().split())
*li1, = map(int, input().split())
*li2, = map(int, input().split())
li1.sort()
li3 = []
for i in li2:
li3.append(bisect_right(li1,i))
print(*li3)
``` | output | 1 | 12,908 | 12 | 25,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj.
Input
The first line contains two integers n, m (1 ≤ n, m ... | instruction | 0 | 12,909 | 12 | 25,818 |
Tags: binary search, data structures, sortings, two pointers
Correct Solution:
```
# @oj: codeforces
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-11-25 17:08
# @url:https://codeforc.es/contest/600/problem/B
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
... | output | 1 | 12,909 | 12 | 25,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj.
Input
The first line contains two integers n, m (1 ≤ n, m ... | instruction | 0 | 12,911 | 12 | 25,822 |
Tags: binary search, data structures, sortings, two pointers
Correct Solution:
```
import bisect
def less_than_or_equal(x, y):
x.sort()
queries = {}
res = []
for num in y:
if num in queries:
res.append(queries[num])
else:
ind = bisect.bisect(x, num)
r... | output | 1 | 12,911 | 12 | 25,823 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.