Problem:


Score : 200 points

Problem Statement

There are N points in a D-dimensional space.

The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).

The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}.

How many pairs (i, j) (i < j) are there such that the distance between the i-th point and the j-th point is an integer?

Constraints

All values in input are integers.

2 \leq N \leq 10

1 \leq D \leq 10

-20 \leq X_{ij} \leq 20

No two given points have the same coordinates. That is, if i \neq j, there exists k such that X_{ik} \neq X_{jk}.

Input

Input is given from Standard Input in the following format:

N D
X_{11} X_{12} ... X_{1D}
X_{21} X_{22} ... X_{2D}
\vdots
X_{N1} X_{N2} ... X_{ND}

Output

Print the number of pairs (i, j) (i < j) such that the distance between the i-th point and the j-th point is an integer.

Sample Input 1

3 2
1 2
5 5
-2 8

Sample Output 1

1

The number of pairs with an integer distance is one, as follows:

The distance between the first point and the second point is \sqrt{|1-5|^2 + |2-5|^2} = 5, which is an integer.

The distance between the second point and the third point is \sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58}, which is not an integer.

The distance between the third point and the first point is \sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5}, which is not an integer.

Sample Input 2

3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3

Sample Output 2

2

Sample Input 3

5 1
1
2
3
4
5

Sample Output 3

10



Sample input:
3 2
1 2
5 5
-2 8


Sample output:
1

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(N)]
import numpy as np
def dist(X, Y, D):
    s = 0
    for i in range(D):
        s += (X[i] - Y[i]) * (X[i] - Y[i])
    sq = int(np.sqrt(s))
    if np.abs(s - sq * sq) < 0.0001:
        return True
    return False
c = 0
for i in range(N):
    for j in range(i+1, N):
        print("{} {}".format(i, j))
        if dist(data[i], data[j], D):
            c += 1

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

Submission status: Wrong Answer

Solution code:
import math

N, D = map(int, input().split())

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k])
        for z in range(30):
            if d == z**2:
                ans += 1
                break

print(ans)

Submission status: Wrong Answer

Solution code:
import math


def distance(X, Y):
    d = 0
    for x, y in zip(X, Y):
        d += (x - y)**2
    return math.sqrt(d)


str = input()

N, D = map(int, str.split(" "))

X = []
for i in range(N):
    x = input()
    x = x.split(" ")
    x = map(int, x)
    X.append(x)

X = list(map(list, X))

count = 0
for i in range(N):
    for j in range(i + 1, N):
        d = distance(X[i], X[j])
        print(d)
        if d.is_integer():
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import math
n, a = map(int, input().split())

vc = []

def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

for i in range(n):
    v = list(map(int, input().split()))
    vc.append(v)

cc = 0
for i in vc:
    if len(vc) < 2:
        break
    vc.remove(i)
    for v in vc:
        s = [abs(x - y) ** 2 for (x, y) in zip(i, v)]
        summ = 0
        for bb in s:
            summ += bb

        if isqrt(summ) == math.sqrt(summ):
            cc += 1




print(cc)

Submission status: Wrong Answer

Solution code:
import math

n, d = map(int, input().split())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
cnt = 0
for i in range(n):
    for j in range(n):
        if i == n - 1:
            if j == n - 1:
                print(cnt/2)
                exit(0)
            countwa = 0
            for k in range(d):
                countwa += abs(a[i][k] - a[0][k]) ** 2

            if float(math.sqrt(countwa)).is_integer():
                cnt += 1

        elif i != j:
            countwa = 0
            for k in range(d):
                countwa += abs(a[i][k] - a[i + 1][k]) ** 2

            if float(math.sqrt(countwa)).is_integer():
                cnt += 1

Submission status: Wrong Answer

Solution code:
import math
n,d=map(int,input().split())
x=[[int(i)for i in input().split()] for j in range(n)]
ct=0
print(x)

for i in x:
  for j in x:
    if i!=j:
      tmp=0
      for k in range(d):
        tmp+=math.sqrt(abs(i[k]**2-j[k]**2))
      if isinstance(tmp,int):
        ct+=1
print(ct)

Submission status: Wrong Answer

Solution code:
import math

n, d = map(int, input().split())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
cnt = 0
for i in range(n):
    for j in range(n):
        if i == n - 1:
            if j == n - 1:
                print(cnt//2)
                exit(0)
            countwa = 0
            for k in range(d):
                countwa += abs(a[i][k] - a[0][k]) ** 2

            if float(math.sqrt(countwa)).is_integer():
                cnt += 1

        elif i != j:
            countwa = 0
            for k in range(d):
                countwa += abs(a[i][k] - a[i + 1][k]) ** 2

            if float(math.sqrt(countwa)).is_integer():
                cnt += 1

Submission status: Wrong Answer

Solution code:
def sqrtjudge(n):
    m = int(pow(n,0.5))
    return 1 if abs(m*m - n) < 1e-6 else 0

n,d = [int(i) for i in input().split()]
x = [[int(i) for i in input().split()] for j in range(n)]
ans = 0

for i in range(1,n):
    for j in range(i,n):
        ans += sqrtjudge(sum(pow(x[i][k]-x[j][k],2) for k in range(d)))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
"""
def distance(a,b):
    ans=0
    for (i,j) in zip(a,b):
        ans+=(i-j)**2
    return math.sqrt(ans)
"""
n,d=map(int,input().split())
x=[]
for j in range(n):
    tmp=list(map(int,input().split()))
    x.append(tmp)

count=0
for i in range(n-1):
    for j in range(i+1,n):
        ans=0
        for (a,b) in zip(x[i],x[j]):
            ans+=(a-b)**2
        print(math.sqrt(ans))
        if math.sqrt(ans).is_integer():
            count+=1

print(count)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(N)]

import numpy as np
def dist(X, Y, D):
    s = 0
    for i in range(D):
        s += (X[i] - Y[i]) * (X[i] - Y[i])
    sq = np.ceil(np.sqrt(s))
    if np.abs(s - sq * sq) < 0.0001:
        return True
    return False

c = 0
for i in range(N):
    for j in range(i+1, N):
        print("{} {}".format(i, j))
        if dist(data[i], data[j], D):
            c += 1

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

Submission status: Wrong Answer

Solution code:
import math
n,d = map(int,input().split())
li = []
li2 = []
cnt = 0
for i in range(n):
    li.append(list(map(int,input().split())))

for i in range(n):
    for j in range(n):
        if i <  j:
            x = 0
            for k in range(d):
                x += (li[i][k] - li[j][k]) ** 2
            li2.append(x)
for a in li2:
    for i in range(a//2 + 1):
        if a == i**2:
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np


# なんこか入力
n,d = map(int, input().split())

# n行の複数列ある数値を二次元配列へ。x[n][?]
x = [[int(i) for i in input().split()] for i in range(n)] 
print(x)
answer = 0
for j in range(n):
    for i in range(j):
        dist2 = 0
        for k in range(d):
            dist2 += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k])
            print(dist2)
        dist = math.sqrt(dist2)
        print(dist)
#        if dist.is_integer() == "True" :
        if round(dist)*dist == dist2:
            answer += 1

print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,D = map(int,input().split())
XD = [list(map(int,input().split()))  for i in range(N)]
dis = 0
count = 0
for i in range(N):
    for j in range(N-i):
        if j == 0:
            continue
        for k in range(D):
            dis = (abs(XD[i][k]-XD[j+i][k]))**2
        if int(np.sqrt(dis)) == np.sqrt(dis):
            count += 1
        dis = 0

print(count)

Submission status: Wrong Answer

Solution code:
def issq(n):
    for i in range(2 * n):
        if i * i == n:
            return True
    return False
    

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

count = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        for k in range(d):
            sqdist = 0
            sqdist = sqdist + (x[i][k] - x[j][k]) ** 2
        if issq(sqdist) == True:
            count = count + 1

print(count)

Submission status: Wrong Answer

Solution code:
import math

def dist(x1,x2):
    tmp = 0
    for i,j in zip(x1,x2):
        tmp += (i - j) * (i - j)
    return math.sqrt(tmp)

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

count = 0
for i in range(n):
    for j in range(i+1,n):
        tmp = dist(x[i],x[j])
        if abs(tmp - round(tmp)) < 0.01:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys, math

a = [int(i) for i in input().split()]
N = a[0]
D = a[1]
X = []
for i in range(N):
  tmp = [int(i) for i in input().split()]
  X.append(tmp)

if D == 1:
  print(int(N*(N-1)/2))
  sys.exit(0)
count = 0
for n in range(0,N-1):
  result = 0
  for d in range(D):
    result = (X[n][d]-X[n+1][d])**2
  if math.sqrt(result).is_integer():
    count+=1;
print(int(count))

Submission status: Wrong Answer

Solution code:
import math

n, d = tuple([int(s) for s in input().split()])
x = [[0]*d for i in range(n)]

for i in range(n):
    x_t = [int(s) for s in input().split()]
    x[i] = x_t

cnt_fit = 0

for i in range(n-1):
    for j in range(i+1, n):
        sumd = 0
        for k in range(d):
            sumd += (x[i][k] - x[j][k]) ** 2
        sumd = math.sqrt(sumd)
        print(sumd)
        if sumd - int(sumd) == 0.0:
            cnt_fit += 1

print(cnt_fit)

Submission status: Wrong Answer

Solution code:
N, D = list(map(int, input().split()))
X = []
for _ in range(N):
    x = list(map(int, input().split()))
    X.append(x)
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        s = [xi - xj for xi, xj in zip(X[i], X[j])]
        e = [ss**2 for ss in s]
        t = sum(e)
        for k in range(21):
            if t == k**2:
                ans += 1
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math


def main():
    N, D = [int(s) for s in sys.stdin.readline().strip().split()]
    X = []
    for i in range(N):
        Xi = [int(s) for s in sys.stdin.readline().strip().split()]
        X.append(Xi)

    max_val = math.sqrt(20 * 2 * D)
    sqrts = set()
    sqrts.add(0)
    for i in range(math.floor(max_val) + 1):
        sqrts.add(i * i)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,D=map(int,input().split())

X=[list(map(int,input().split())) for i in range(N)]

S=[n**2 for n in range(1,41)]

c=0

for i in range(N):
    for j in range(i,N):
        d=0
        for k in range(D):
            d+=(X[i][k]-X[j][k])**2
        for k in range(40):
            if d==S[k]:
                c+=1

print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
square=[i**2 for i in range(41)]
x=np.array(x)
# print(x)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        # print(x[i],x[j],np.sum((x[i]-x[j])**2))
        if np.sum((x[i]-x[j])**2) in square:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
X = list()
for i in range(N) :
	X.append(list(map(int, input().split())))

cnt = 0
for i in range(N - 1) :
	for j in range(i + 1, N) :
		s = 0
		for k in range(D) :
			s += (X[i][k] - X[j][k]) ** 2
		d = s ** 1/2
		if(d == int(d)) :
			cnt += 1
		else :
			pass
	
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import math


def main():
    N, D = [int(s) for s in sys.stdin.readline().strip().split()]
    X = []
    for i in range(N):
        Xi = [int(s) for s in sys.stdin.readline().strip().split()]
        X.append(Xi)

    max_val = math.sqrt(20 * 2 * D)
    sqrts = set()
    for i in range(math.floor(max_val) + 1):
        sqrts.add(i * i)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, d = map(int, input().split())
Xlist = []

for i in range(n):
    l = list(map(int, input().split()))
    Xlist.append(l)

ans = 0
tmp = 0

for i in range(n-1):
    for j in range(i+1, n):
        for k in range(d):
            tmp += (Xlist[i][k] - Xlist[j][k]) ** 2
        a = int(tmp ** 0.5) ** 2
        print(a)
        print(tmp)

        if a == tmp:
            ans += 1
        tmp = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, d = tuple([int(s) for s in input().split()])
x = [[0]*d for i in range(n)]

for i in range(n):
    x_t = [int(s) for s in input().split()]
    x[i] = x_t

cnt_fit = 0

for i in range(n-1):
    for j in range(i+1, n):
        sumd = 0
        for k in range(d):
            sumd += (x[i][k] - x[j][k]) ** 2
        sumd = math.sqrt(sumd)
        print(sumd)
        if sumd - int(sumd) == 0:
            cnt_fit += 1

print(cnt_fit)

Submission status: Wrong Answer

Solution code:
import math
N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int,input().split())))

ans = 0

def ks(x,y):
    p = 0
    for i in range(D):
        p += (x[i]-y[i])**2
    return p**(1/2)



for j in range(N-1):
    l = ks(X[j], X[j+1])
    if l % 1 == 0:
        ans += 1
l = ks(X[N-1], X[0])
if l % 1 == 0:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

Solution code:
N,D = map(int, input().split())
field = []
for i in range(N):
    field.append(list(map(int, input().split())))


def calc(i,j):
    dist2d = [x**2 for x in range(100)]
    ci = field[i]
    cj = field[j]
    dist2 = [(di-dj)**2 for di,dj in zip(ci,cj)] 

    
    if sum(dist2) in dist2d:
        return True
    else:
        return False

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += calc(i,j)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

N,D = list(map(int,input().split()))
points = [list(map(int,input().split())) for i in range(N)]

all_d = []

for i in range(N-1):
  nijo = []
  nijo_sum = 0
  for j in range(D):
    nijo.append((points[i][j]-points[i+1][j])**2)
  for j in range(D):
    nijo_sum += nijo[j]
  all_d.append(math.sqrt(nijo_sum))
    
Nijo = []
Nijo_sum = 0
for i in range(D):
  Nijo.append((points[-1][i]-points[0][i])**2)
for i in range(D):
  Nijo_sum += Nijo[i]
all_d.append(math.sqrt(nijo_sum))
  
count = 0
for i in range(N):
  if (all_d[i]%1) == 0:
    count += 1
if D != 1:
  print(count)
else:
  print(N*(N-1)//2)

Submission status: Wrong Answer

Solution code:
N, D = (int(x) for x in input().split())
X = [None]*N
sq_list = [x**2 for x in range(41)]
def is_distance_sq(x: list, y: list) -> bool:
    distance_sq = sum([(x[i]-y[i])**2 for i in range(D)])
    return distance_sq in sq_list

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if is_distance_sq(X[i], X[j]):
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

  ans = 0
for i in range(1,n):
  for j in range(i):
    print(i, j)
    list1 = x_array[i]
    list2 = x_array[j]
    count = 0
    for k in range(len(list1)):
      count += (list1[k]-list2[k]) ** 2

    if math.sqrt(count) == int(math.sqrt(count)):
      ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  7 20:59:16 2019

@author: sp8783
"""
import math

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

ans = 0

for i in range(n):
    for j in range(1,n):
        if i != j:          
            tmp = 0
            for k in range(d):
                tmp = tmp + (lst[i][k] - lst[j][k])**2
            dis = math.sqrt(tmp)
            if dis == math.floor(dis):
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n,d = list(map(int,input().split()))
l = [0]*n
print(l)
for i in range(n):
    ipt = list(map(int,input().split()))
    l[i] = ipt
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        sm = 0
        for k in range(d):
            sm += abs(l[i][k] - l[j][k])**2
        sm = math.sqrt(sm)
        if sm%1 == 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-


N,D = map(int, input().split())
Xn = []
sqrt = [i**2 for i in range(1,101)]
for _ in range(N):
  Xn.append(list(map(int, input().split())))

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

Submission status: Wrong Answer

Solution code:
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
print(cnt)

Submission status: Wrong Answer

Solution code:
#B問題
N,D = map(int,input().split())
X = [list(map(int,input().split())) for i in range(N)]
count = 0
for i in range(N):
    for j in range(N-i-1):
        J=i+j+1
        dist = 0
        for k in range(D):
            dist+=(X[i][k]-X[J][k])**2
        flag = 0
        for d in range(dist):
            if (dist/(d+1)) == d+1:
                print(d+1)
                flag = 1
        if flag == 1:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import math

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

ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist = 0
        for d in range(D):
            dist += pow(X[i][d]-X[j][d], 2)
        for k in range(4*int(math.sqrt(1000))):
            if k*k == dist:
                ans += 1
                break

print(ans)

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
p=0
def c(i,j):
  global x
  s=0
  for k in range(d):
    s+=(x[i][k]-x[j][k])**2
  if s**(1/2).is_integer()==True:
    return 1
  else:
    return 0
for i in range(n):
  for j in range(i+1,n):
    p+=c(i,j)
print(p)

Submission status: Wrong Answer

Solution code:
N, D = [int(x) for x in input().split()]
x_list = [[int(x) for x in input().split()] for _ in range(N)]
sq = [n*n for n in range(41)]
cnt = 0
for i, xi in enumerate(x_list):
    for xj in x_list[i+1:]:
        dist = sum([(y-z)*(y-z) for y, z in zip(xi, xj)])
        cnt += (dist in sq)
print(cnt)

Submission status: Wrong Answer

Solution code:
N,D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]

dbl = []
for i in range(1,100):
        dbl.append(i**2)

ans = 0
for idx,val in enumerate(X):
        for idx2, val2 in enumerate(X):
                if idx == idx2:
                        continue
                elif idx < idx2:
                        break
                tmp = 0
                for d in range(D):
                        tmp += abs(val[d] - val2[d]) ** 2
                if tmp in dbl:
                        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
x=[]
for i in range(n):
	p=list(map(int,input().split()))
	x.append(p)
heihoukon=[]
for i in range(42):
	heihoukon.append(i**2)
ans=0
for a in range(n):
	for b in range(n):
		cnt=0
		for c in range(d):
			cnt+=(x[a-1][c]-x[b-1][c])**2
		if cnt in heihoukon and a!=b:
			ans+=1
print(ans//2)

Submission status: Wrong Answer

Solution code:
N, D = list(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):
        r = 0
        for d in range(D):
            r += (X[i][d] - X[j][d]) ** 2
        for n in range(70):
            if r == n ** 2:
                cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split()) # 横に2個
X = []
c = 0
for _ in range(N):
    Xi = list(map(int, input().split())) # １行に別れてるとき
    for x in X:
        dis = 0
        for i in range(D):
            dis += (x[i] - Xi[i])**2
        for k in range(100):
            if dis == k**2:
                c += 1
    X.append(Xi)

print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
square=[i**2 for i in range(40)]
x=np.array(x)
# print(x)
ans=0
for i in range(n):
    for j in range(i+1,n):
        # print(x[i],x[j],np.sum((x[i]-x[j])**2))
        if np.sum((x[i]-x[j])**2) in square:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n, d = map(int, input().split())
    xl = [[int(i) for i in input().split()] for _ in range(n)]
    ans = 0
    valid = set([i ** 2 for i in range(1, 50)])
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            s = 0
            for k in range(d):
                s += (xl[i][k] - xl[j][k]) ** 2
            if s in valid:
                ans += 1
    print(ans // 2)

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from math import sqrt, floor

N, D = [int(elem) for elem in input().split()]
coords = [[int(elem) for elem in input().split()] for _ in range(N)]
assert len(coords[0]) == D

num_pairs = 0
for i in range(N):
    c1 = coords[i]
    for j in range(i + 1, N):
        c2 = coords[j]
        sqaured_dist = sum((p1 - p2) ** 2 for p1, p2 in zip(c1, c2))
        dist = floor(sqrt(sqaured_dist))
        if sqaured_dist // dist == dist:
            num_pairs += 1
print(num_pairs)

Submission status: Wrong Answer

Solution code:
N,D=map(int,input().split())
L=[]
hei=[i**2 for i in range(100)]

for i in range(N):
  l=list(map(int,input().split()))
  L.append(l)
ans=0
for i in range(N):
  for j in range(i+1,N):
    if sum((L[i][k]-L[j][k])**2 for k in range(D)) in hei:
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n, d = map(int, input().split())
ls = []
for i in range(n):
    s = list(map(int, input().split()))
    #print(s)
    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)

Submission status: Wrong Answer

Solution code:
n,d =  list(map(int,input().split(" ")))
dots = [list(map(int,input().split(" ")))  for _ in range(n)]

sqs = [i ** 2 for i in range(100)]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        d1 = dots[i]
        d2 = dots[j]
        temp = 0
        for dd1,dd2 in zip(d1,d2):
            temp += (dd1 - dd2) ** 2
        if temp in sqs:
            ans += 1



print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt
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(i+1,N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k]-X[j][k])**2
        if int(sqrt(tmp) * 10) % 10 == 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,D = map(int, input().split())
field = []
for i in range(N):
    field.append(list(map(int, input().split())))


def calc(i,j):
    dist2d = [x**2 for x in range(1,80)]
    ci = field[i]
    cj = field[j]
    dist2 = [(di-dj)**2 for di,dj in zip(ci,cj)] 

    
    if sum(dist2) in dist2d:
        return True
    else:
        return False

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += calc(i,j)

print(ans)

Submission status: Wrong Answer

Solution code:
N,D = map(int,input().split())

Xs = []

targets = []
count = 0
for i in range(0, 50):
    targets.append(i**2)

for i in range(0,N):
    Xs.append(list(map(int,input().split())))

for i in range(0,N):
    for h in range(i,N):
        if i == h:
            continue

        dist = 0
        for index in range(len(Xs[0])):
            dist += (Xs[i][index] - Xs[h][index])**2

        if dist in targets:
            count += 1


print(count)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
N,D=map(int,input().split())
L=[]
hei=[i**2 for i in range(70)]

for i in range(N):
  l=list(map(int,input().split()))
  L.append(l)
ans=0
for i in range(N):
  for j in range(i+1,N):
    if sum((L[i][k]-L[j][k])**2 for k in range(D)) in hei:
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n):
  l[i]=list(map(int,input().split()))
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    c=0
    for h in range(d):
      c+=abs(l[i][h]**2-l[j][h]**2)
    if int(c**(1/2))==c**(1/2):
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append([int(x) for x in input().split()])
ans = 0
S = {i**2 for i in range(100)}
for i in range(N):
    for j in range(i + 1, N):
        if sum((X[i][d] - X[j][d])**2 for d in range(D)) in S:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
N,D=map(int,input().split())
X=[[int(i) for i in input().split()] for i in range(N)]
num=0
for i in range(N):
    for j in range(i+1,N):
        a=0
        for k in range(D):
            a+=(X[i][k]-X[j][k])**2
        #print(a)
        for x in range(101):
            if x**2==a:
                num+=1
                break
print(num)

Submission status: Wrong Answer

Solution code:
import numpy as np
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


def dist(x,y):
    ans = 0
    for i in range(len(x)):
        ans += (x[i]-y[i])*(x[i]-y[i])
    return np.sqrt(ans)

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

ans = 0

for i in range(n):
    for j in range(i+1,n):
        d = dist(arr[i],arr[j])
        if abs(d-int(d)) < 0.01:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
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):
        if np.linalg.norm(np.array(X[i])-np.array(X[j])).is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split(" "))
clist = []

for i in range(n):
    xlist = list(map(int,input().split(" ")))
    clist.append(xlist)

def dis(ylist,zlist):
    distance = 0
    for i in range(d):
        distance += (ylist[i] - zlist[i]) ** 2
    sqdis = math.sqrt(distance)
    return(sqdis)

countdis = 0

for i in range(n-1):
    for j in range(i+1,n):
        if dis(clist[i],clist[j]) % 1 == 0:
            countdis += 1

print(countdis)

Submission status: Accepted

Solution code:
import itertools

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

combi=list(itertools.combinations([i for i in range(N)],2 ))

ans=0

for c in combi:
	temp=0
	for d in range(D):
		temp+=(X[c[0]][d]-X[c[1]][d])**2
	temp=temp**.5
	if float.is_integer(temp):ans+=1

print(ans)

Submission status: Accepted

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

def check_dist(i, j):
  quad = sum([(xi - xj) * (xi - xj) for xi,xj in zip(X[i], X[j])])
  dist = 1
  while dist * dist <= quad:
    if dist * dist == quad:
      return True
    dist += 1
  return False

count = 0
for i in range(N-1):
  for j in range(i+1, N):
    count += check_dist(i, j)
print(count)

Submission status: Accepted

Solution code:
import math

N,D = map(int,input().split())
L = []
ans = 0 
for _ in range(N):
  X = list(map(int,input().split()))
  L.append(X)
for i in range(N - 1):
  for j in range(i + 1,N):
    con = 0
    for k in range(D):
      con += (L[i][k] - L[j][k]) ** 2
    if  int(math.sqrt(con)) ** 2 == con:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
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):
        tmp=0
        for k in range(d):
            tmp+=(x[i][k]-x[j][k])**2
        if math.sqrt(tmp)==int(math.sqrt(tmp)):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
ans = 0
from itertools import combinations
from os import kill
for i, j in combinations(range(N), 2):
    d = sum([(X[i][k]-X[j][k])**2 for k in range(D)])
    if int(d**0.5) == d**0.5:
        ans += 1
print(ans)