ZhenlongDai/ACPR huggingface dataset:
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,d = map(int,input().split())
try:
  a = [list(map(int,input().split())) for j in range(0,n)]
except EOFError:
  pass
c = 0
r = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    for k in range(0,d):
      c+=(a[i][k]-a[j][k])**2
  if math.sqrt(c)==int(math.sqrt(c)):
    r += 1
print(r)

Failing test case input:
3 2
1 8
5 5
-2 8

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
import math
n,d = map(int,input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        t = 0
        for k in range(d):
            t+=(x[i][k]-x[j][k])**2 
        if math.sqrt(t)==int(math.sqrt(t)):
            ans += 1
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, d = map(int, input().split())
ls = []
for i in range(n):
    s = list(map(int, input().split()))
    
    ls.append(s)

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += abs(ls[i][k] - ls[j][k])
        dist = dist ** (1/2)
        if(dist.is_integer()):
            ans += 1
print(ans)

Failing test case input:
3 2
2 4
5 5
-2 8

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n, d = map(int, input().split())
ls = []
for i in range(n):
    s = list(map(int, input().split()))
    
    ls.append(s)

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += abs(ls[i][k] - ls[j][k])**2
        dist = dist ** (1/2)

        if(dist.is_integer()):
            ans += 1
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N, D = map(int, input().split())
p=[]
for _ in range(N):
    p.append(list(map(int, input().split())))

dis=[]
for a in p:
    for b in p:
        n = 0
        for i in range(D):
            n = n + (a[i]-b[i])**2
        if not n==0:
            dis.append(n)
print(len([d for d in dis if int(math.sqrt(d))**2==d])/2)

Failing test case input:
0 1
0
-2
0
6
1

Expected output:
0


Actual output:
0.0


Fixed submission (verdict: Accepted):
import math
N, D = map(int, input().split())
p=[]
for _ in range(N):
    p.append(list(map(int, input().split())))

dis=[]
for a in p:
    for b in p:
        n = 0
        for i in range(D):
            n = n + (a[i]-b[i])**2
        if not n==0:
            dis.append(n)
print(len([d for d in dis if int(math.sqrt(d))**2==d])
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n, d = map(int, input().split())
x = [[0 for i in range(d)] for j in range(n)]
for i in range(n):
  x[i] = map(int, input().split())

result = 0
for i in range(n):
  for j in range(n-1):
    diff = map(lambda x,y: (x-y)*(x-y), x[i],x[j])
    calc = math.sqrt(sum(diff))
    if calc.is_integer():
      result +=1
print(result)

Failing test case input:
5 1
1
2
3
4
5

Expected output:
10

Actual output:
20


Fixed submission (verdict: Accepted):
import math
n, d = map(int, input().split())
x = [[0 for i in range(d)] for j in range(n)]
for i in range(n):
  x[i] = list(map(int, input().split()))
result = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    diff = list(map(lambda x,y: pow(x-y,2), x[i], x[j]))
    calc = math.sqrt(sum(diff))
    if calc.is_integer():
      result +=1
print(result)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, D = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
res = 0
for i in range(n):
    for j in range(i + 1, n):
        d = sum((l[i][k] - l[j][k]) ** 2 for k in range(D))
        if (d ** 0.5) ** 2 == d:
            res += 1
print(res)

Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3

Expected output:
2

Actual output:
3


Fixed submission (verdict: Accepted):
n, D = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
res = 0
for i in range(n):
    for j in range(i + 1, n):
        d = sum((l[i][k] - l[j][k]) ** 2 for k in range(D))
        if int(d ** 0.5) ** 2 == d:
            res += 1
print(res)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys,math
input = sys.stdin.readline

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
num = 0

print(X)

for i in range(1,N):
  for j in range(1,D):
      
      print(X[i-1][j-1],X[i][j])
  
    
    



Failing test case input:
-1 15
-8 2 8 -1
-18 2 2 2
-2 10 22 -1

Expected output:
0


Actual output:

Fixed submission (verdict: Accepted):
import sys,math
input = sys.stdin.readline

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0

for i in range(N):
  for j in range(N):
    num = 0
    if i < j:
      for k in range(D):
        num += pow(abs(X[i][k] - X[j][k]) ,2)
      if math.floor(math.sqrt(num)) ** 2 == num:
        cnt += 1

print(cnt)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append(list(map(int, input().split())))

dist = 0
cnt = 0
for i in range(N):
    for j in range(N):
        if j == i:
            continue
        for k in range(D):
            dist += (X[i][k] - X[j][k])**2
        dist = math.sqrt(dist)
        if dist == int(dist):
            cnt += 1
cnt /= 2
print(cnt)

Failing test case input:
-2 20
0 3 0 -1
-25 3 2 1
-2 7 2 -1

Expected output:
0


Actual output:
0.0


Fixed submission (verdict: Accepted):
import math

N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append(list(map(int, input().split())))

dist = 0
cnt = 0
for i in range(N):
    for j in range(N):
        dist = 0
        if j == i:
            continue
        for k in range(D):
            dist += (X[i][k] - X[j][k])**2
        dist = math.sqrt(dist)
        if dist == int(dist):
            cnt += 1
cnt /= 2
print(int(cnt))

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, d = map(int, input().split())
lst = []
length = 0
cnt = 0
for i in range(n):
	a = map(int, input().split())
	lst.append(list(a))
for i in range(1, n):
	for j in range(i, n):
		for k in range(d):
			length += (lst[i][k]-lst[j-1][k])**2
		if length%1 == 0:
			cnt += 1
print(cnt)
        

Failing test case input:
3 2
0 4
5 5
-2 8

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
from math import sqrt
n, d = map(int, input().split())
lst = []
cnt = 0
for i in range(n):
    a = tuple(map(int, input().split()))
    lst.append(a)
for i in range(n-1):
    for j in range(i+1, n):
        x = 0
        for k in range(d):
            x += (lst[i][k]-lst[j][k])**2
        length = sqrt(x)
        if length%1 == 0:
            if length != 0:
                cnt += 1
print(cnt)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]

c = 0

for i in range(n-1):
  for j in range(i+1, n):
    for k in range(d):
      diff = sum([(s-t)**2 for s, t in zip(X[i], X[j])])
    if (diff**1/2).is_integer():
      c += 1
      
print(c)
    

Failing test case input:
3 2
0 4
5 5
-2 8

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            diff = sum([(s-t)**2 for s,t in zip(X[i],X[j])])
        if (diff**.5).is_integer():c += 1
print(c)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d=map(int,input().split())

a=[list(map(int,input().split())) for _ in range(n)]

count=0
sum=0
for i in range(n):
    for k in range(i+1,n):
        for j in range(d):
            sum+=int((a[i][j]-a[k][j])*(a[i][j]-a[k][j]))
        for l in range(sum):
            if sum==l*l:
                count+=1
        sum=0

print(count)


Failing test case input:
5 1
1
2
3
4
5

Expected output:
10

Actual output:
6


Fixed submission (verdict: Accepted):
n,d=map(int,input().split())

a=[list(map(int,input().split())) for _ in range(n)]

count=0
sum=0
for i in range(n):
    for k in range(i+1,n):
        for j in range(d):
            sum+=int((a[i][j]-a[k][j])*(a[i][j]-a[k][j]))
        for l in range(sum+1):
            if sum==l*l:
                count+=1
        sum=0

print(count)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,d=map(int,input().split())
za=[list(map(int,input().split())) for i in range(n)]
ans=0
lon=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            lon+=(za[i][k]-za[j][k])**2
            lon=math.sqrt(lon)
        else:
            if lon==int(lon):
                ans+=1
            lon=0
print(ans)

Failing test case input:
3 2
1 8
5 5
-2 8

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import math
n,d=map(int,input().split())
za=[list(map(int,input().split())) for i in range(n)]
ans=0
lon=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            lon+=(za[i][k]-za[j][k])**2
        else:
            lon=math.sqrt(lon)
            if lon==int(lon):
                ans+=1
            lon=0
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d =map(int, input().split())
L=[]
for i in range(n):
    L.append(list(map(int, input().split())))
ans =0

for i in range(n):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis = (L[i][k]-L[j][k])**2
        dis = dis**0.5
        if(dis % 1.0 ==0):
            ans +=1
print(ans)


Failing test case input:
3 2
2 4
5 5
-2 8

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n,d =map(int, input().split())
L=[]
for i in range(n):
    L.append(list(map(int, input().split())))
ans =0

for i in range(n):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis += (L[i][k]-L[j][k])**2
        dis = dis**0.5
        if dis % 1.0 ==0:
            ans +=1
print(ans)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math 

n,d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))

ans = 0
for i in range(n):
    for q in range(n):
        sumv = 0
        if i == q:
            continue
        for j in range(d):
            sumv += (x[i][j] - x[q][j]) ** 2

        if math.sqrt(sumv).is_integer() == True:
            ans += 1

print(ans/2)

Failing test case input:
0 8
-7 1 8 1
-18 1 1 2
-2 8 22 0

Expected output:
0


Actual output:
0.0


Fixed submission (verdict: Accepted):
import math 

n,d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))

ans = 0
for i in range(n):
    for q in range(n):
        sumv = 0
        if i == q:
            continue
        for j in range(d):
            sumv += (x[i][j] - x[q][j]) ** 2

        if math.sqrt(sumv).is_integer() == True:
            ans += 1

print(round(ans/2))

Problem: p02982
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, D = map(int, input().split())

X = [input().split() for i in range(N)]

count = 0
d_2 = 0
d = 0

for i in range(N):
    for j in range(0, i):
        for k in range(D):
            d_2 += (float(X[i][k]) - float(X[j][k]))**2
        d = d_2**(1/2)
        if d.is_integer() == True:
            count += 1

print("{}".format(count))

Failing test case input:
5 1
1
2
3
4
5

Expected output:
10

Actual output:
3


Fixed submission (verdict: Accepted):
N, D = map(int, input().split())

X = [input().split() for i in range(N)]

count = 0
d_2 = 0
d = 0

for i in range(1, N):
    for j in range(0, i):
        d_2 = 0
        d = 0
        for k in range(D):
            d_2 += (float(X[i][k]) - float(X[j][k]))**2
        d = d_2**(1/2)
        if d.is_integer() == True:
            count += 1

print("{}".format(count))

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import sqrt
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]

ans=0
tmp=0

for i in range(n):
  for j in range(i+1, n):
    xi,xj = x[i],x[j]
    for k in range(d):
      tmp += (xi[k]-xj[k]) ** 2  
    if sqrt(tmp)%1==0:
      ans += 1

print(ans)



Failing test case input:
3 2
1 8
5 5
-2 8

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
from math import sqrt
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]

ans=0
tmp=0

for i in range(n):
  for j in range(i+1, n):
    xi,xj = x[i],x[j]
    for k in range(d):
      tmp += (xi[k]-xj[k]) ** 2  
    if sqrt(tmp)%1==0:
      tmp=0
      ans += 1
    else:
      tmp=0

print(ans)
Problem: p02982
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
heihousu = set(int(i**2) for i in range(100))
N,D = list(map(int,input().split()))
X = [list(map(int,input().split()))   for i in range(N)]

cnt = 0
for i in range(N-1):
  for j in range(i+1,N):
    if sum([int((X[i][d]-X[j][d])**2) for d in range(D)]) in heihousu:
      cnt+=1

Failing test case input:
-1 8
-8 2 8 0
-18 2 1 2
-2 10 22 -1

Expected output:
0


Actual output:

Fixed submission (verdict: Accepted):
heihousu = set(int(i**2) for i in range(1000))
N,D = list(map(int,input().split()))
X = [list(map(int,input().split()))   for i in range(N)]

cnt = 0
for i in range(N-1):
  for j in range(i+1,N):
    if sum([int((X[i][d]-X[j][d])**2) for d in range(D)]) in heihousu:
      cnt+=1
print(cnt)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N ,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
LL = 0
for i in range(N-1):
  for j in range(i+1,N):
    for k in range(D):
      LL += ((X[i][k]-X[j][k])**2)
    L = math.sqrt(LL)
    if L.is_integer() == True:
      ans += 1
      L = 0
      LL = 0
print(ans)

Failing test case input:
3 2
2 4
5 5
-2 8

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import math
N ,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
LL = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(D):
      LL += (X[i][k]-X[j][k])**2
    L = math.sqrt(LL)
    if LL == int(L)**2:
      ans += 1
    L = 0
    LL = 0
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, d = map(int, input().split())
x = []
cnt = 0
sum = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)

for i in range(n):
    for j in range(i + 1, n):
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        distance = sum ** 0.5
        if distance.is_integer():
            cnt += 1

print(cnt)


Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3

Expected output:
2

Actual output:
1


Fixed submission (verdict: Accepted):
n, d = map(int, input().split())
x = []
cnt = 0
sum = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        l = 1
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        while (l ** 2 <= sum):
            if l ** 2 == sum:
                cnt += 1
            l += 1

print(cnt)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d =map(int, input().split())
L=[]
for i in range(n):
    L.append(list(map(int, input().split())))
ans =0

for i in range(n):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis = (L[i][k]-L[j][k])**2
        dis = dis**0.5
        if dis == int(dis):
            ans +=1
print(ans)

Failing test case input:
3 2
2 4
5 5
-2 8

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n,d =map(int, input().split())
L=[]
for i in range(n):
    L.append(list(map(int, input().split())))
ans =0

for i in range(n):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis += (L[i][k]-L[j][k])**2
        dis = dis**0.5
        if dis % 1.0 ==0:
            ans +=1
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
cnt=0

for i in range(n-1):
  for i2 in range(i+1,n):
    distance = 0
    for j in range(d):
      distance+=(abs(l[i][j])-abs(l[i2][j]))**2
    
    if (distance**0.5).is_integer():
      cnt+=1
      
print(cnt)

Failing test case input:
3 2
1 4
5 5
-2 8

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
cnt=0

for i in range(n):
  for j in range(i+1,n):
    distance = 0
    for k in range(d):
      distance+=(l[i][k]-l[j][k])**2
    
    if (distance**0.5).is_integer():
      cnt+=1
      
print(cnt)

Problem: p02982
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ret = 0
for i in range(n-1):
    for j in range(i, n):
        meu = 0
        for y, z in zip(x[i], x[j]):
            meu += (y-z)**2
        if meu**0.5 == int(meu**0.5):
            ret += 1
print(ret)

Failing test case input:
5 1
0
2
3
4
5

Expected output:
10


Actual output:
14


Fixed submission (verdict: Accepted):
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ret = 0
for i in range(n-1):
    for j in range(i+1, n):
        meu = 0
        for y, z in zip(x[i], x[j]):
            meu += (y-z)**2
        if (meu**0.5).is_integer():
            ret += 1
print(ret)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N ,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
LL = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(D):
      LL += (X[i][k]-X[j][k])**2
    L = math.sqrt(LL)
    if LL == int(L)**2:
      ans += 1
      L = 0
      LL = 0
print(ans)

Failing test case input:
3 2
2 4
5 5
-2 8

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import math
N ,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
LL = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(D):
      LL += (X[i][k]-X[j][k])**2
    L = math.sqrt(LL)
    if LL == int(L)**2:
      ans += 1
    L = 0
    LL = 0
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d=map(int,input().split())
x=[[int(a) for a in input().split(" ")] for _ in range(n)]
cnt=0
dis=0
for i in range(n-1):
  for j in range(i+1,n):
    for k in range(d):
      dis+=(x[i][k]-x[j][k])**2
      if (dis**0.5).is_integer:
        cnt+=1
print(cnt)

Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 13 0

Expected output:
1


Actual output:
12


Fixed submission (verdict: Accepted):
n,d=map(int,input().split())
x=[[int(a) for a in input().split(" ")] for _ in range(n)]
cnt=0
for i in range(n-1):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis+=(x[i][k]-x[j][k])**2
    if (dis**0.5).is_integer():
        cnt+=1
print(cnt)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, D = map(int, input().split())
X = [[int(i) for i in input().split()] for _ in range(N)]
count = 0
for i in range(N):
  for j in range(i + 1, N):
    res = sum([(X[i][k] - X[j][k])**2 for k in range(D)])
    if (res**0.5).is_integer:
      count += 1
print(count)

Failing test case input:
3 2
1 4
5 5
-2 8

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
N, D = map(int, input().split())
X = [[int(i) for i in input().split()] for _ in range(N)]
count = 0
for i in range(N):
  for j in range(i + 1, N):
    res = sum([(X[i][k] - X[j][k])**2 for k in range(D)])
    if (res**0.5) % 1 == 0:
      count += 1
print(count)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, d = map(int,input().split())
x=[]
dist=0
count=0
for i in range(n):
  x.append(list(map(int,input().split())))

for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      dist+=(x[i][k]-x[j][k])**2
    dist=dist**0.5
    if dist.is_integer():
      count+=1
print(count)

Failing test case input:
5 1
0
2
3
4
5

Expected output:
10


Actual output:
1


Fixed submission (verdict: Accepted):
n, d = map(int,input().split())
x=[]
dist=0
count=0
for i in range(n):
  x.append(list(map(int,input().split())))

for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      dist+=(x[i][k]-x[j][k])**2
    dist=dist**0.5
    if dist.is_integer():
      count+=1
    dist=0
print(count)
Problem: p02982
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from math import sqrt

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0

for i in range(N - 1):
    dist = 0

    for j in range(i + 1, N):
        for k in range(D):
            dist += (X[i][k] - X[j][k]) ** 2
        
        if sqrt(dist) % 1 == 0:
            ans += 1
    
print(ans)

Failing test case input:
5 1
0
2
3
4
5

Expected output:
10


Actual output:
4


Fixed submission (verdict: Accepted):
from math import sqrt

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        dist = 0
    
        for k in range(D):
            dist += (X[i][k] - X[j][k])**2
        
        if sqrt(dist) % 1 == 0:
            ans += 1
    
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,D = map(int,input().split())
X = [0]+[list(map(int,input().split()))for _ in range(N)]
List = []
ans = 0
for j in range(1,N):
    for i in range(j+1,N+1):
        v = 0
        for k in range(D):
            v+=(X[j][k]-X[i][k])**2
        for l in range(v):
            List.append(l**2)
        if v in List:
            ans+=1
            
print(ans)


Failing test case input:
5 1
1
2
3
4
5

Expected output:
10

Actual output:
9


Fixed submission (verdict: Accepted):
N,D = map(int,input().split())
X = [0]+[list(map(int,input().split()))for _ in range(N)]
List = []
ans = 0
for j in range(1,N):
    for i in range(j+1,N+1):
        v = 0
        for k in range(D):
            v+=(X[j][k]-X[i][k])**2
        for l in range(v+1):
            List.append(l**2)
        if v in List:
            ans+=1
      
            
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,d = map(int,input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
  for j in range(i+1,n):
    sq= 0
    for k in range(d):
      sq += (x[i][k]-x[j][k])**2
      if math.sqrt(sq).is_integer():
        ans += 1
print(ans)

Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 13 0

Expected output:
1


Actual output:
5


Fixed submission (verdict: Accepted):
import math

n,d = map(int,input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
  for j in range(i+1,n):
    sq= 0
    for k in range(d):
      sq += (x[i][k]-x[j][k])**2
    if math.sqrt(sq).is_integer():
      ans += 1
print(ans)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,d=map(int,input().split())
l=[]
ans=0
cnt=0
for i in range(n):
    l.append(list(map(int,input().split())))

for i in range (n-1):
    for j in range(d):
        ans+=((l[i][j])-(l[i+1][j]))**2
    if float.is_integer(math.sqrt(ans))==True:
        cnt+=1
print(cnt)


Failing test case input:
5 1
1
2
3
4
5

Expected output:
10

Actual output:
2


Fixed submission (verdict: Accepted):
import math
n,d = map(int,input().split())
l = []
for i in range(n):
  l.append(list(map(int,input().split())))
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans = 0
    for k in range(d):
      ans += (int(l[i][k])-int(l[j][k]))**2

    if float.is_integer(math.sqrt(ans)) == True:
      count += 1
print(count)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, d = map(int, input().split())
x = [[int(i) for i in input().split()] for i in range(n)] 
dist2 = 0
count = 0
for i in range(n): 
    for j in range(i+1,n):
        for k in range(d):
            dist2 += (x[i][k]-x[j][k])**2
        dist = dist2**0.5 
        if dist.is_integer():
            count += 1 
print(count)

Failing test case input:
5 1
1
2
3
4
5

Expected output:
10

Actual output:
2


Fixed submission (verdict: Accepted):
n, d = map(int, input().split())
x = [[int(i) for i in input().split()] for i in range(n)] 
dist2 = 0
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            dist2 += (x[i][k]-x[j][k])**2
        dist = dist2**0.5 
        dist2=0
        if dist.is_integer():
            count += 1 
print(count)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, D = map(int, input().split())
X=[]
f=0
for i in range(N):
    X.append(list(map(int,input().split())))
for i in range(N-1):
    for j in range(i+1, N):
        ans=0
        print(X[i] , X[j])
        for k in range(D):
            ans = ans + (X[i][k] - X[j][k])**2
        ans = (ans)**0.5
        print(ans)
        if ans==int(ans):
            f+=1
print(f)

Failing test case input:
3 2
1 8
5 5
-2 8

Expected output:
2


Actual output:
[1, 8] [5, 5]
5.0
[1, 8] [-2, 8]
3.0
[5, 5] [-2, 8]
7.615773105863909
2


Fixed submission (verdict: Accepted):
N, D = map(int, input().split())
X=[]
f=0
for i in range(N):
    X.append(list(map(int,input().split())))
for i in range(N-1):
    for j in range(i+1, N):
        ans=0
        for k in range(D):
            ans = ans + (X[i][k] - X[j][k])**2
        ans = (ans)**0.5
        if ans==int(ans):
            f+=1
print(f)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n, d = map(int, input().split())
points = [list(map(int, input().split())) for i in range(n)]

cnt = 0

def distance(x, y):
  ans = 0
  for dd in range(d):
    ans += abs(x[dd] - y[dd]) ** 2
  return math.sqrt(ans)


for i in range(n):
  for j in range(i+1, n):
    if distance(points[i], points[j]):
      cnt += 1

print(cnt)


Failing test case input:
3 2
2 4
5 5
-2 8

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
import math
n, d = map(int, input().split())
points = [list(map(int, input().split())) for i in range(n)]

cnt = 0

def distance(x, y):
  ans = 0
  for dd in range(d):
    ans += abs(x[dd] - y[dd]) ** 2
  return math.sqrt(ans)


for i in range(n):
  for j in range(i+1, n):
    if distance(points[i], points[j]).is_integer():
      cnt += 1

print(cnt)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

n, d = map(int, input().split())
a = []
for i in range(n):
  a.append(list(map(int, input().split())))

b = 0
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      b+= (abs(a[i][k] + a[j][k]))
      
    b= math.sqrt(b)
    
    if b%1==0:
      ans += 1
    b = 0
print(ans)

Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
import math

n, d = map(int, input().split())
a = []
for i in range(n):
  a.append(list(map(int, input().split())))

b = 0
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      b+= (a[i][k] - a[j][k])**2
      
    b= math.sqrt(b)
    
    if b%1==0:
      ans += 1
    b = 0
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

n, d = map(int, input().split())
x = [list(map(int, input().split()))for _ in range(n)]
cnt = 0
for i in range(n-1):
    for j in range(i+1,n-1):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k])**2
        if math.sqrt(s) % 1 == 0:
            cnt += 1
print(cnt)

Failing test case input:
5 1
0
2
3
4
5

Expected output:
10


Actual output:
6


Fixed submission (verdict: Accepted):
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k])**2
        if math.sqrt(s) % 1 == 0:
            cnt += 1
print(cnt)
Problem: p02982
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,d=map(int, input().rstrip().split())
m=[]
for _ in range(n):
    arr=list(map(int, input().rstrip().split()))
    m.append(arr)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        a = 0
        for k in range(d):
            a += (m[i][k] - m[j][k])**2
        x = int(a**(1/2))
        if x*2 == a:
            ans+=1
print(ans)
        
        

Failing test case input:
3 2
1 2
5 5
-2 8

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
n,d=map(int, input().rstrip().split())
m=[]
for _ in range(n):
    arr=list(map(int, input().rstrip().split()))
    m.append(arr)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        a = 0
        for k in range(d):
            a += (m[i][k] - m[j][k])**2
        x = int(a**(1/2))
        if x**2 == a:
            ans+=1
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d=map(int,input().split())
x=[[int(i) for i in input().split()] for i in range(n)] 
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        check = 0
        for k in range(d):
            check += (x[i][k]-x[j][k])**2
        if isinstance(check,int):
            ans+=1
print(ans)

Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3

Expected output:
2

Actual output:
3


Fixed submission (verdict: Accepted):
n,d=map(int,input().split())
x=[[int(i) for i in input().split()] for _ in range(n)] 
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        check = 0
        for k in range(d):
            check += (x[i][k]-x[j][k])**2
        if check**.5==int(check**.5):
            ans+=1
print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d=map(int,input().split())
lists=[list(map(int,input().split())) for x in range(n)]
answer=0
for i in range(1,n):
  for j in range(i+1,n+1):
    for y in range(d):
      count=0
      count+=(lists[j-1][y]-lists[i-1][y])**2
      t=count**(1/2)
      if t.is_integer():
        answer+=1
print(answer)

Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 13 0

Expected output:
1


Actual output:
12


Fixed submission (verdict: Accepted):
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(n-1):
  for j in range(i+1,n):
    sum=0
    for dd in range(d):
      sum+=(l[i][dd]-l[j][dd])**2
    if sum**0.5==int(sum**0.5):
      cnt+=1
print(cnt)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
ans=0
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            siki=((l[i][k]-l[j][k])**2)
            ans+=siki
        flag=False
        for o in range(ans):
            if o*o==ans:
                flag=True
        if flag:
        	cnt+=1 
print(cnt)

Failing test case input:
3 2
2 4
5 5
-2 8

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
ans=0
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        siki=0
        for k in range(d):
            siki+=((l[i][k]-l[j][k])**2)
        han=siki**0.5
        if han%1 == 0:
            cnt += 1
print(cnt)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dist = sum(map(lambda v1, v2: (v1 - v2) ** 2, x[i], x[j]))
        print(dist)
        if math.sqrt(dist) == int(math.sqrt(dist)):
            ans += 1

print(ans)

Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 9 0

Expected output:
1


Actual output:
121
7
154
1


Fixed submission (verdict: Accepted):
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dist = sum(map(lambda v1, v2: (v1 - v2) ** 2, x[i], x[j]))
        if math.sqrt(dist) == int(math.sqrt(dist)):
            ans += 1

print(ans)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,d=map(int,input().split())
d_list=[]
ans=0
for i in range(n):
    d_list.append(list(map(int,input().split())))
for i in range(n-1):
    kyori=0
    for j in range(i+1,n):
        for k in range(d):
            kyori+=(d_list[i][k]-d_list[j][k])**2
    if math.sqrt(kyori)**2==kyori:
        ans+=1
print(ans)

Failing test case input:
3 2
0 4
5 5
-2 8

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import math
n,d=map(int,input().split())
d_list=[]
ans=0
for i in range(n):
    d_list.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        kyori=0
        
        for k in range(d):
            kyori+=(d_list[i][k]-d_list[j][k])**2
        
        if int(math.sqrt(kyori))**2==kyori:
            ans+=1
print(ans)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
cnt=0

for i in range(n):
  for i2 in range(i+1,n):
    distance = 0
    for j in range(d):
      distance+=(abs(l[i][j])-abs(l[i2][j]))**2
    
    if float.is_integer(math.sqrt(distance)):
      cnt+=1
      
print(cnt)

Failing test case input:
3 2
1 4
5 5
-2 8

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
cnt=0

for i in range(n):
  for j in range(i+1,n):
    distance = 0
    for k in range(d):
      distance+=(l[i][k]-l[j][k])**2
    
    if (distance**0.5).is_integer():
      cnt+=1
      
print(cnt)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

cnt=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            sum=0
            sum += (x[i][k]-x[j][k])**2
            route = sum**0.5
            if route.is_integer:
                cnt += 1
print(cnt)

Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 9 0

Expected output:
1


Actual output:
12


Fixed submission (verdict: Accepted):
n,d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt=0

for i in range(n):
    for j in range(i+1,n):
        distance=0
        for k in range(d):
            distance += (x[i][k]-x[j][k])**2
        if (distance**0.5).is_integer():
            cnt += 1
print(cnt)

Problem: p02982
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,D = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(N)]
count = 0
for j in range(N-1):
    for i in range(j,N-1):
        a = 0
        for d in range(D):
            
            a+= (abs(lst[i][d] - lst[i+1][d]))**2
        if (a**0.5 % 1 == 0):
            count+=1
        
print(count)

Failing test case input:
3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3

Expected output:
2

Actual output:
1


Fixed submission (verdict: Accepted):



N,D = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(N)]
count = 0
for j in range(N-1):
    for i in range(j+1,N):
        a = 0
        for d in range(D):
           
            a+= (abs(lst[j][d] - lst[i][d]))**2
        if (a**0.5 % 1 == 0):
            count+=1
        
print(count)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n,d=map(int,input().split())
X=[]
for i in range(n):
    x=list(map(int,input().split()))
    X.append(x)
cnt=0
for i in range(n):
    for j in range(i+1,n):
        s=0
        for a,b in zip(X[i],X[j]):
            s+=(a-b)**2
        s=math.sqrt(s)
        print(s)
        if s.is_integer():
            cnt+=1
print(cnt)

Failing test case input:
3 2
1 8
5 5
-2 8

Expected output:
2


Actual output:
5.0
3.0
7.615773105863909
2


Fixed submission (verdict: Accepted):
import math
n,d=map(int,input().split())
X=[]
for i in range(n):
    x=list(map(int,input().split()))
    X.append(x)
cnt=0
for i in range(n):
    for j in range(i+1,n):
        s=0
        for a,b in zip(X[i],X[j]):
            s+=(a-b)**2
        s=math.sqrt(s)
        if s.is_integer():
            cnt+=1
print(cnt)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

cnt=0
for i in range(n):
    for j in range(i+1,n):
        sum=0
        for k in range(d):
            sum += (x[i][k]-x[j][k])**2
        route = sum**0.5
        if route.is_integer:
            cnt += 1

print(cnt)

Failing test case input:
3 2
0 4
5 5
-2 8

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n,d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt=0

for i in range(n):
    for j in range(i+1,n):
        distance=0
        for k in range(d):
            distance += (x[i][k]-x[j][k])**2
        if (distance**0.5).is_integer():
            cnt += 1
print(cnt)

Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, D = map(int, input().split())
X =[]
for i in range(N):
  X.append(list(map(int, input().split())))
ans=0
dist=0
for i in range(N):
  for j in range(N):
    if i < j:
      for k in range(D):
        dist += abs(X[i][k] - X[j][k])**2
      dist = dist**(1/2)
      if round(dist,0) == dist:
        ans += 1
      
print(ans)

Failing test case input:
3 2
1 4
5 5
-2 8

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N,D = map(int,input().split())
X=[]
for i in range(N):
    X.append(list(map(int, input().split())))
    
ans=0

for i in range(N):
    for j in range(N):
        if i < j:
            dist=0
            for k in range(D):
                dist += (X[i][k] - X[j][k])**2
            dist = dist ** 0.5
            if round(dist,0) == dist:
                ans += 1
           
print(ans)
Problem: p02982
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, D = map(int,input().split())
li = []
for _ in range(N):
    li.append(list(map(int,input().split())))

s = 0
c = 0
for n in range(-1,N-1):
    for d in range(D):
        s = s + abs(li[n][d] - li[n+1][d]) ** 2
    s_float = float(s**(1/2))
    if s_float.is_integer():
        c += 1
    s = 0
print(c)

Failing test case input:
5 1
1
2
3
4
5

Expected output:
10

Actual output:
5


Fixed submission (verdict: Accepted):
N, D = map(int,input().split())
li = []
for _ in range(N):
    li.append(list(map(int,input().split())))

s = 0
c = 0
for n1 in range(-1,N-1):
    for n2 in range(n1+1,N-1):
        for d in range(D):
            s = s + abs(li[n1][d] - li[n2][d]) ** 2
        s_float = float(s**(1/2))
        if s_float.is_integer():
            c += 1
        s = 0
print(c)
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
mod = 1000000007
ans = 1
l = []
for i in range(n):
  if a[i] == 0:
    l.append(0)
    ans = ans*(4-len(l))%mod
  else:
    id = -1
    count = 0
    for j in range(len(l)):
      if l[j] == a[i] - 1:
        count += 1
        id = j
    if id == -1:
      break
    ans = (ans*count)%mod
    l[id] = a[i]
  if ans == 0:
    break
print(ans%mod)

Failing test case input:
6
0 2 1 1 2 5

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
mod = 1000000007
ans = 1
l = []
for i in range(n):
  if a[i] == 0:
    l.append(0)
    ans = ans*(4-len(l))%mod
  else:
    id = -1
    count = 0
    for j in range(len(l)):
      if l[j] == a[i] - 1:
        count += 1
        id = j
    if id == -1:
      ans = 0
      break
    ans = (ans*count)%mod
    l[id] = a[i]
  if ans == 0:
    break
print(ans%mod)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
As = list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*3 for _ in range(N+1)]
ans = 1
for i in range(N):
    a = As[i]
    dplis = dp[i]
    cnt = 0
    dp[i+1] = dplis[:]
    for j, d in enumerate(dplis):
        if a==d:
            cnt += 1
            if cnt==1:
                dp[i+1][j] = a+1
    if cnt==0:
        print(0)
        break
    ans *= cnt
    ans %= mod
print(ans)
    
    

Failing test case input:
6
1 8 3 2 3 6

Expected output:
0


Actual output:
0
1


Fixed submission (verdict: Accepted):
N = int(input())
As = list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*3 for _ in range(N+1)]
ans = 1
for i in range(N):
    a = As[i]
    dplis = dp[i]
    cnt = 0
    dp[i+1] = dplis[:]
    for j, d in enumerate(dplis):
        if a==d:
            cnt += 1
            if cnt==1:
                dp[i+1][j] = a+1
    if cnt==0:
        print(0)
        break
    ans = ans*cnt%mod
else:
    print(ans%mod)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)

ans=1
for num in a:
    if num==0:
        last_cnt=3
    else:
        last_cnt=d[num-1]

    tmp = last_cnt - d[num]
    if tmp <= 0:
        tmp=1
    ans*=tmp
    ans%=1000000007
    d[num]+=1

print(ans)

Failing test case input:
6
0 0 1 0 8 6

Expected output:
0


Actual output:
12


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)

ans=1
for num in a:
    if num==0:
        ans*= (3 - d[0])
    else:
        ans*= (d[num-1] - d[num])

    ans%=1000000007
    d[num]+=1

print(ans)
Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
from bisect import *
import math

input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
mod = 1000000007

cnum = A.count(0)
amax = max(A)

numind = [[] for i in range(amax+1)]
for i,ai in enumerate(A):
	numind[ai].append(i)

res = 1
for i in range(amax):
	for order, j in enumerate(numind[i+1]):
		res = (res * (bisect(numind[i],j)-order)) % mod



print(res)

Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
115295190

Actual output:
19215865


Fixed submission (verdict: Accepted):
import sys
from bisect import *
import math

input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
mod = 1000000007

cnum = A.count(0)
amax = max(A)

numind = [[] for i in range(amax+1)]
for i,ai in enumerate(A):
	numind[ai].append(i)

if cnum==0 or cnum>3:
	res = 0
else:
	res = 1
	for i in range(amax):
		if len(numind[i+1])==0 or len(numind[i+1])>3:
			res = 0
			break
		for order, j in enumerate(numind[i+1]):
			res = (res * (bisect(numind[i],j)-order)) % mod

	res = (res*math.factorial(3)

print(res)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 +7

if a[0] != 0:
    print(0)
    exit()

col = [1,0,0]

ans = 3
cnt = 2

for i in range(1,n):
    if col.count(a[i]) == 0:
        print(0)
    else:
        ans *= col.count(a[i])
        ans %= mod
        col[col.index(a[i])] += 1

print(ans)

Failing test case input:
6
0 0 1 8 11 6

Expected output:
0


Actual output:
0
0
0
12


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 +7

col = [0,0,0]

ans = 1

for i in range(n):
    if not a[i] in col:
        print(0)
        exit()
    else:
        ans *= col.count(a[i])
        ans %= mod
        col[col.index(a[i])] += 1

if sum(col) != n:
    print(0)
    exit()

print(ans%mod)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
l=[[] for _ in range(3)]
ans=1
p=10**9+7
flag=1
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if l[j]==piv:
            cnt=cnt+1
            ind.append(j)
    if len(ind)==0:
        flag=0
        break
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    
    
if flag==1:
    print(ans%p)
else:
    print(flag)



Failing test case input:
6
0 1 2 0 3 4

Expected output:
6


Actual output:
0


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
l=[[] for _ in range(3)]
ans=1
p=10**9+7
flag=1
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    if len(ind)==0:
        flag=0
        break
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    
    
if flag==1:
    print(ans%p)
else:
    print(flag)
Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
mod=1000000007

N=int(input())
A=list(map(int,input().split()))

ans=1
c1=c2=c3=0
for Ai in A:
    if c1==c2==c3==Ai:
        c1+=1
        ans=ans*3%mod
    elif c1==c2==Ai:
        c1+=1
        ans=ans*2%mod
    elif c2==c3==Ai:
        c2+=1
        ans=ans*2%mod
    elif c1==Ai:
        c1+=1
    elif c2==Ai:
        c2+=1
    elif c3==Ai:
        c3+=1

print(ans)

Failing test case input:
6
0 2 2 1 5 6

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
mod=1000000007

N=int(input())
A=list(map(int,input().split()))

ans=1
c1=c2=c3=0
for Ai in A:
    if c1==c2==c3==Ai:
        c1+=1
        ans=ans*3%mod
    elif c1==c2==Ai:
        c1+=1
        ans=ans*2%mod
    elif c2==c3==Ai:
        c2+=1
        ans=ans*2%mod
    elif c1==Ai:
        c1+=1
    elif c2==Ai:
        c2+=1
    elif c3==Ai:
        c3+=1
    else:
        ans=0
        break

print(ans)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
mod = 1000000007
memo = [[] for i in range(m+1)]
a.reverse()
d = {}
for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1
    if ai + 1 in d:
        memo[ai].append(d[ai+1])
    else:
        memo[ai].append(3)
ans = 1
for l in memo:
    i = 0
    for li in l:
        ans = ans * (li - i) %  mod
        i += 1
print(ans)


Failing test case input:
6
0 0 2 4 7 6

Expected output:
0


Actual output:
486


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
mod = 1000000007
memo = [[] for i in range(m+1)]
d = {-1: 3}
ans = 1
for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1
    if ai - 1 in d:
        memo[ai].append(d[ai-1])
    else:
        ans  = 0
for l in memo:
    i = 0
    for li in l:
        ans = ans * (li - i) %  mod
        i += 1
print(ans)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))

mod=1000000007
ans=1
r,b,g=0,0,0
for i in a:
    if i==r and i==b and i==g:
        ans*=3
        ans%=mod
        r+=1
    elif (i==r and i==b) or (i==g and i==r):
        ans*=2
        ans%=mod
        r+=1
    elif i==b and i==g:
        ans*=2
        ans%=mod
        g+=1
    elif i==r:
        r+=1
    elif i==b:
        b+=1
    elif i==g:
        g+=1
print(ans)

Failing test case input:
6
0 1 2 3 4 7

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))

mod=1000000007
ans=1
r,b,g=0,0,0
r2,b2,g2=-1,-1,-1
for i in a:
    if r2==r and b2==b and g2==g:
        print(0)
        exit()
    r2=r
    b2=b
    g2=g
    if i==r and i==b and i==g:
        ans*=3
        ans%=mod
        r+=1
    elif (i==r and i==b) or (i==g and i==r):
        ans*=2
        ans%=mod
        r+=1
    elif i==b and i==g:
        ans*=2
        ans%=mod
        g+=1
    elif i==r:
        r+=1
    elif i==b:
        b+=1
    elif i==g:
        g+=1

    else:
        print(0)
        exit()

print(ans)