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: Accepted

Solution code:
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()))
count=0
for i in range(n-1):
  for j in range(i+1,n):
    r2=0
    for k in range(d):
      r2+=(x[i][k]-x[j][k])**2
    r=r2**(1/2)
    if r.is_integer():
      count+=1
print(count)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)


def d(yy,zz):
    ans = 0
    for i in range(len(yy)):
        ans += (yy[i]-zz[i])**2
    return sqrt(ans)

def main():
    N,D = map(int, input().split())
    xx = []
    for _ in range(N):
        xx.append(list(map(int,input().split())))
    
    c = 0
    for i in range(N):
        for j in range(i+1,N):
            if d(xx[i], xx[j]).is_integer():
                c += 1
    
    print(c)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def do(a,b):
    the=math.sqrt(sum([(a[i] - b[i])**2 for i in range(D)]))
    return the.is_integer()

r=0
for i in range(N):
    for j in range(i+1, N):
        if do(X[i], X[j]):
            r+=1
print(r)

Submission status: Accepted

Solution code:
import numpy as np

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

num = 0
for i in range(n):
    for j in range(i+1, n):
        xi = x[i]
        xj = x[j]
        dist = 0
        for k in range(d):
            dist += (xi[k] - xj[k])**2
        if np.sqrt(dist).is_integer():
            num += 1

print(num)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def check(a):
    flag=False
    for i in range(1,100000):
        if a==i*i:
            flag=True
    return flag
    

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

ans=0
for i in range(n):
    for j in range(i+1,n):
        D=0
        for di in range(d):
            D+=(X[i][di]-X[j][di])**2
        if check(D):
            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
for i, Xi in enumerate(X):
    for j, Xj in enumerate(X):
        if i == j:
            continue
        dist = 0
        for y, z in zip(Xi, Xj):
            dist += (y - z) ** 2
        dist **= .5
        if dist == int(dist):
            ans += 1
print(ans // 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


def calcDist(A, B):
    sqSum = 0
    for i in range(len(A)):
        sqSum += (A[i] - B[i]) ** 2
    return math.sqrt(sqSum)


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

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


count_int = 0
for i in range(N):
    for j in range(i + 1, N):
        if (calcDist(X[i], X[j]).is_integer()):
            count_int += 1

print(count_int)

Submission status: Accepted

Solution code:
def euclid(A, B):
    c2 = 0
    for a,b in zip(A,B):
        c2 += (a-b)**2
    return c2**0.5

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):
        c = euclid(X[i], X[j])
        if c.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math


def solve():
    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 - 1):
        for j in range(i + 1, N):
            distance = 0
            for d in range(D):
                distance += (X[i][d] - X[j][d]) ** 2
            if math.sqrt(distance) % 1 == 0:
                # print('i:', i, 'j', j)
                count += 1
    print(count)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt

def judge(a,b):
    s = 0
    for i in range(len(a)):
        s+=(a[i]-b[i])**2
    q = sqrt(s)
    return q.is_integer()


n,d = map(int,input().split())
x = []

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

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += judge(x[i],x[j])
    
print(ans)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
li = [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 a,b in zip(li[i],li[j]):
            sum += (a-b)**2
        sum = math.sqrt(sum)
        if sum.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

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-i-1):
    a = i
    b = i+j+1
    t = 0
    for k in range(d):
      t += math.pow(abs(x[a][k] - x[b][k]),2)

    t = math.sqrt(t)
    if(is_integer_num(t)):
      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

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

for i in range(n-1):
    for j in range(i+1,n):
        t = 0
        for x in range(d):
            t += (X[i][x]-X[j][x])**2
        t **= 0.5
        if is_integer_num(t):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
#print(n,d,l)

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        dist = 0
        for k in range(d):
            dist += (l[i][k] - l[j][k])**2
        sqrt = int(dist**.5)
        if sqrt**2 == dist:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N, D = list(map(int,input().split()))
    X=[]
    for i in range(N):
        X.append(LI())
    out=0
    for i in range(N-1):
        for j in range(N-1-i):
            tmp=0
            for d in range(D):
                tmp+=(X[i][d]-X[N-1-j][d])**2
            tmp=math.sqrt(tmp)
            if tmp%1==0:
                out+=1
    print(out)
    # print(A,B)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A

if __name__ == '__main__':
    N, D = InputToInt()

    X = np.empty((N, D))
    for i in range(N):
        X[i, :] = InputToInt()

    count = 0
    for i in range(N-1):
        for j in range(i+1, N):
            d = np.linalg.norm(X[i,:]-X[j,:], ord=2)
            if d == int(d):
                count += 1

    print(count)

Submission status: Accepted

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, 200)])
    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: Accepted

Solution code:
#B

import math

n,d = (int(x) for x in input().split())
x = []

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

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

Submission status: Accepted

Solution code:
import numpy as np
n,d = map(int,input().split())
x = [[0 for _ in range(d)] for _ in range(n)]

for i in range(n):
	X = list(map(int,input().split()))
	x[i] = X
	
c = 0
for i in range(n):
	for j in range(i+1,n):
		if(i == j):continue
		
		dist = 0.0
		for k in range(d):
			dist += (x[i][k] - x[j][k]) ** 2.0
		dist = np.sqrt(dist)
		if(dist % 1.0 < 0.001):c+=1
print(c)

Submission status: Accepted

Solution code:
import numpy as np

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

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

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
list1=[]
count=0
for i in range(N):
    list1.append(list(map(int,input().split())))
for i in range(N):
    for j in range(i+1,N):
        templen=0
        for k in range(D):
            templen+=(list1[i][k]-list1[j][k])**2
        templen=templen**(1/2)
        if templen==int(templen):
            count+=1
print(count)

Submission status: Accepted

Solution code:
import itertools
import math

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

ans = 0
for i in itertools.permutations(range(n), 2):
    if i[0] < i[1]:
        x1 = X[i[0]]
        x2 = X[i[1]]
        check = 0
        for j in range(d):
            check += abs(x2[j] - x1[j]) ** 2
        if math.sqrt(check).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:

import math

N, D = [int(x) for x in input().split(' ')]
points = []
for i in range(N):
    points.append([int(x) for x in input().split(' ')])

count = 0
for i in range(0, N):
    for j in range(i + 1, N):
        p1 = points[i]
        p2 = points[j]
        distance = 0
        for k in range(D):
            distance += math.pow(p1[k] - p2[k], 2)
        distance = math.sqrt(distance)
        if distance == int(distance):
            count += 1

print(count)

Submission status: Accepted

Solution code:
import sys
import math

n, d = [ int(x) for x in sys.stdin.readline().split() ]
r = []
for _ in range(n): r.append( [ int(x) for x in sys.stdin.readline().split() ] )

count = 0
for i in range(n):
    ri = r[i]
    for j in range(i+1,n):
        rj = r[j]
        #
        d2 = 0
        for k in range(d):
            d2+= (ri[k]-rj[k])**2
        #
        sq = math.sqrt(d2)
        if abs(int(sq)-sq)<1.e-10: count+=1
#
print( count )

Submission status: Accepted

Solution code:
import numpy as np
N, M = list(map(int, input().split()))
X = [np.asarray(list(map(int, input().split()))) for i in range(N)]
count = 0
for i in range(N):
  for j in range(i+1, N):
    vec = X[i] - X[j]
    vec = np.dot(vec, vec.T)
    sq = int(np.sqrt(vec))
    if sq ** 2 == vec:
      count += 1
print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D, X):
    p = set([i**2 for i in range(1, int(math.sqrt(16000)))])
    ans = 0
    for i, j in combinations(range(N), 2):
        d = 0
        for k in range(D):
            d += (X[i][k]-X[j][k])**2
        if d in p:
            ans += 1
    return ans


def main():
    N, D = read_int_n()
    X = [read_int_n() for _ in range(N)]
    print(slv(N, D, X))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!venv/bin/python
#from collections import defaultdict 
from itertools import combinations
import math
import datetime
N, D = [int(x) for x in input().split()]
X = []
for _i in range(N):
    X.append([int(x) for x in input().split()])
ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist2 = 0
        for x1, x2 in zip(X[i], X[j]):
            dist2 += (x1 - x2)**2
        if math.sqrt(dist2) == int(math.sqrt(dist2)):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
n, d = [int(item) for item in input().split()]
x = []
for i in range(n):
    x.append([int(item) for item in input().split()])
ans = 0
for i in range(n):
    for j in range(i+1, n):
        val = 0
        for k in range(d):
            val += (x[i][k] - x[j][k]) ** 2.0 
        if math.sqrt(val).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

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

import numpy as np
X = np.zeros((N, D))
for i in range(N):
    x = list(map(int, input().split()))
    X[i] = x

def isSq(n):
    a = np.sqrt(n)
    return n == int(a) * int(a)

p = 0
for i in range(N-1):
    for j in range(i+1, N):
        a = X[i] - X[j]
        s = a.dot(a)
        if isSq(s):
            p += 1

print(p)

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

print((ans-n)//2)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
import numpy as np
# from fractions import gcd
import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def main():
    def kyori(a, b):
        a = np.array(a)
        b = np.array(b)
        c = a-b
        c = c ** 2
        c = np.sum(c)
        return np.sqrt(c)

    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n, d = ip.IL()
    x = ip.SILS(n)
    memo = list(itertools.combinations(range(n), 2))
    # print(memo)
    ans = 0
    for y in memo:
        x1 = y[0]
        x2 = y[1]
        # print(x[x1])
        res = kyori(x[x1], x[x2])
        res2 = int(res)
        if res == res2:
            ans += 1
        # print(res)
    print(ans)


main()

Submission status: Accepted

Solution code:
import math

def main():
  n, d = map(int, input().split())
  xlist = []
  for _ in range(n):
    xlist.append(list(map(int, input().split())))
  ans = 0
  for i in range(n):
    for j in range(n):
      if i == j:
        continue
      dist = 0
      for k in range(d):
        dd = xlist[i][k] - xlist[j][k]
        dist += dd*dd
      if int(math.sqrt(dist)) * int(math.sqrt(dist)) == dist:
        ans += 1
  print(ans // 2)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000000)
input=lambda : sys.stdin.readline().rstrip()

def dist(a,b):
    ans=0
    for x,y in zip(a,b):
        ans+=(x-y)**2
    return ans**0.5

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(i+1,n):
        if abs(int(dist(x[i],x[j])+0.5)-dist(x[i],x[j]))<0.000000001:
            count+=1
print(count)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    for j in range(i):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        if abs(int(dist ** 0.5) ** 2 - dist) < 1e-6: 
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def calc_distance(x, y, D):
    distance = 0
    for i in range(D):
        distance += (x[i] - y[i])**2
    distance = np.sqrt(distance)
    return distance

def main():
    N, D = map(int, input().split())
    X = []
    for _ in range(N):
        line = [int(i) for i in input().split()]
        X.append(line)
    
    num = 0
    for i in range(N):
        for j in range(i + 1, N):
            distance = calc_distance(X[i], X[j], D)
            if isinstance(distance, int) or distance.is_integer():
                num += 1
    print(num)




    



if __name__ == '__main__':
    main()

Submission status: Accepted

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])**2
        dist = dist ** (1/2)

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

Submission status: Accepted

Solution code:
N,D = map( int, input().split())
X = [0 for i in range(10) for j in range(10)]
for i in range(N):
  X[i] = list(map( int, input().split()))
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    len = 0
    for a in range(D):
      len += (X[i][a] - X[j][a]) ** 2
    len = len ** 0.5
    if len == int(len):
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--



def main():
    N, D = map(int, input().split())
    X = [tuple(map(int, input().split())) for _ in range(N)]
    c = 0
    
    for i, x1 in enumerate(X):
        for x2 in X[i+1:]:
            d = sum((x1[j] - x2[j])**2 for j in range(D))
            if round(d**.5)**2 == d:
                c += 1

    print(c)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

N, D = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N):
    for j in range(N):
        if j == i:
            continue
        dist = np.sqrt(sum([(points[i][d] - points[j][d]) ** 2 for d in range(D)]))
        if dist.is_integer():
            count += 1
print(count // 2)

Submission status: Accepted

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

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

import math

ans = 0
for i, x_i in enumerate(X):
    for j, x_j in enumerate(X[i+1:]):
        l = sum([ (a-b)**2 for a, b in zip(x_i, x_j)])
        ans += math.sqrt(l).is_integer()
        
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

n,d=intinput()
p=[]
for i in range(n):
    p.append(list(intinput()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        tmp=0
        for k in range(d):
            tmp+=(p[i][k]-p[j][k])**2
        if int(tmp**0.5)**2==tmp:
            ans+=1
print(ans)

Submission status: Accepted

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

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: Accepted

Solution code:
import math
n, d = list(map(int, input().split(' ')))
tmp = []
for _ in range(n):
    res = list(map(int, input().split(' ')))
    tmp.append(res)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        dis = 0
        for x, y in zip(tmp[i], tmp[j]):
            dis += pow((x-y), 2)

        root = int(math.sqrt(dis))
        if root * root == dis:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

# N, A, B = l_inpl()

# print(min(N*A, B))
N, D = l_inpl()
X = []

for _ in range(N):
    Xi = l_inpl()
    X.append(Xi)

ans = 0
for yi, zi in combinations(list(range(N)), 2):
    tmp = 0
    for y, z in zip(X[yi], X[zi]):
        tmp += (abs(y - z)) ** 2
    
    if (tmp**(1/2)).is_integer():
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
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 - 1):
    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 == int(distance ** 0.5):
            count += 1
print(count)

Submission status: Accepted

Solution code:
from math import sqrt

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):
        dis = sqrt(float(sum([(X[i][c] - X[j][c])**2 for c in range(D)])))
        if float(int(dis)) == dis:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        temp = 0
        for d in range(D):
            temp += (X[i][d] - X[j][d])**2
        temp = temp**0.5
        if float.is_integer(temp):
            ans += 1 
print(ans)

Submission status: Accepted

Solution code:
import math

N, D = (map(int, input().split()))
X = []
output = 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):
		# X[i]とX[j]の距離を求める
		tmp = 0
		for k in range(D):
			tmp += (X[i][k] - X[j][k]) ** 2
		if math.sqrt(tmp) - int(math.sqrt(tmp)) == 0:
			output += 1
			
print(output)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
ans = 0
X = []
for i in range(N):
  x = [int(i) for i in input().split()]
  X.append(x)
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 ((tmp)**(1/2))%1 != 0:
      continue
    else:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys, math

readline = sys.stdin.readline

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

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

count = 0
for i in range(0, N):
    for j in range(i + 1, N):
        l2 = sum([(x - y) ** 2 for x,y in zip(X[i], X[j])])
        l_floor = math.floor(l2 ** 0.5)
        if l2 == l_floor ** 2:
            count += 1

print(count)