CodeEff/ECCO huggingface dataset:
# Original solution
from collections import Counter

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

maxA = [0 for _ in range(N + 1)]
minA = [float('inf') for _ in range(N + 1)]

for i, a in enumerate(A):
    minA[i + 1] = min(minA[i], a)
for i, a in enumerate(reversed(A)):
    maxA[-1 - i] = max(maxA[-1 - (i - 1)], a)

maxProfit = 0
for i in range(1, N):
    if maxProfit < maxA[i + 1] - minA[i]:
        maxProfit = maxA[i + 1] - minA[i]

pairs = set([])
for i in range(1, N):
    if maxProfit == maxA[i + 1] - minA[i]:
        pairs.add((minA[i], maxA[i + 1]))

ans = 0
for minVal, maxVal in pairs:
    right = N - 1
    maxCount = 0
    while A[right] != maxVal:
        right -= 1
    for i in range(right):
        if A[i] == minVal:
            maxCount += 1
    left = 0
    minCount = 0
    while A[left] != minVal:
        left += 1
    for i in range(left, N):
        if A[i] == maxVal:
            minCount += 1
    ans += min(maxCount, minCount)

print(ans)

# Optimized solution
from collections import Counter

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

maxA = [0 for _ in range(N + 1)]
minA = [float('inf') for _ in range(N + 1)]

for i, a in enumerate(A):
    minA[i + 1] = min(minA[i], a)
for i, a in enumerate(reversed(A)):
    maxA[-1 - i] = max(maxA[-1 - (i - 1)], a)

maxProfit = 0
for i in range(1, N):
    if maxProfit < maxA[i + 1] - minA[i]:
        maxProfit = maxA[i + 1] - minA[i]

pairs = set([])
for i in range(1, N):
    if maxProfit == maxA[i + 1] - minA[i]:
        pairs.add((minA[i], maxA[i + 1]))

ans = len(pairs)
print(ans)
# Original solution
#!/usr/bin/env python3

import collections


def solve(n, t, xs):
    trades = collections.defaultdict(int)
    for i in range(n):
        for j in range(i + 1, n):
            delta = xs[j] - xs[i]
            if delta > 0:
                trades[delta] += 1
    max_delta = max(trades.keys())
    return trades[max_delta]


def main():
    n, t = list(map(int, input().split()))
    xs = list(map(int, input().split()))
    print((solve(n, t, xs)))


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env pypy3

import collections


INF = 10 ** 10


def solve(n, t, xs):
    trades = collections.Counter()
    maxs = [INF for _ in range(n)]
    maxs[n - 1] = xs[n - 1]
    for i in range(n - 1)[::-1]:
        maxs[i] = max(xs[i], maxs[i + 1])
    for i in range(n):
        delta = maxs[i] - xs[i]
        if delta > 0:
            trades[delta] += 1
    max_delta = max(trades.keys())
    return trades[max_delta]


def main():
    n, t = list(map(int, input().split()))
    xs = list(map(int, input().split()))
    print((solve(n, t, xs)))


if __name__ == '__main__':
    main()
# Original solution
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    b = collections.defaultdict(list)
    m_c = 10 ** 9
    for i, v in enumerate(a):
        if i != 0 and m_c < v:
            b[v-m_c] += [m_c]
        m_c = min(m_c, v)
    b = sorted(list(b.items()), reverse=True)[0]
    print((len(collections.Counter(b[1]))))


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(list)
    min_b = 10 ** 9
    max_p = 0
    for v in a:
        p = v - min_b
        max_p = max(max_p, p)
        d[p] += [min_b]
        min_b = min(min_b, v)
    print((len(d[max_p])))


if __name__ == '__main__':
    slove()
# Original solution
n,t = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]

good = []

for i in range(len(a)-1):
    good.append(max(a[i+1:])-a[i])

m = max(good)

count = 0

for g in good:
    if g==m:count+=1

print(count)


# Optimized solution
n,t = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]

good = []

mmm = []

mmm.append(a[n-1])

for i in range(n-1):
    mmm.append(max(mmm[i],a[n-i-2]))

mmm.reverse()

for i in range(len(a)-1):
    good.append(mmm[i+1]-a[i])

m = max(good)

count = 0

for g in good:
    if g==m:count+=1

print(count)
# Original solution
#!/usr/bin/env python3

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

d = -1
cnt, ans = 0, 1
for i in range(N - 1):
    l = A[i]
    r = max(A[i + 1:])
    if l <= r:
        if r - l == d:
            cnt += 1
            ans = max(ans, cnt)
        else:
            cnt = 1
            d = max(d, r - l)

print(ans)


# Optimized solution
#!/usr/bin/env python3

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

d = 0
ans = 1
l = A[0]
for a in A[1:]:
    l = min(l, a)
    r = a
    if r - l == d:
        ans += 1
    elif r - l > d:
        ans = 1
        d = r - l

print(ans)
# Original solution
import math


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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for x1, x2 in zip(lst[i], lst[j]):
            tmp += (x1 - x2) ** 2
        val = math.sqrt(tmp)
        # if val.is_integer():
        if val == int(val):
            ans += 1
print(ans)


# Optimized solution
import math


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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for x1, x2 in zip(lst[i], lst[j]):
            tmp += (x1 - x2) ** 2
        val = math.sqrt(tmp)
        if val.is_integer():
        # if val == int(val):
            ans += 1
print(ans)
# Original solution
import math
def main():

    x = []
    N, D = list(map(int, input().split()))
    for _ in range(N):
        y = list(map(int, input().split()))
        x.append(y)
    ans = 0
    for i in range(N):
        for j in range(i):
            d1 = 0
            for k in range(D):
                d1 += pow(x[i][k]-x[j][k], 2)
            d1 = math.sqrt(d1)
            if d1 == int(d1): ans += 1
    return ans

if __name__ == '__main__':
    print((main()))

# Optimized solution
import math
def main():
    N, D = list(map(int, input().split()))
    pt = []
    for _ in range(N):
        p = list(map(int, input().split()))
        pt.append(p)

    ans = 0
    for i in range(N):
        for j in range(i):
            l = 0
            for k in range(D):
                l += pow(pt[i][k]-pt[j][k], 2)
            l = math.sqrt(l)
            if l == int(l): ans += 1
    return ans

if __name__ == '__main__':
    print((main()))
# Original solution
N, D = list(map(int, input().split()))
l = []
cnt = 0

for i in range (N):
  l.append(list(map(int, input().split())))
    
for j in range (N-1):
  for k in range (j+1, N):
    t = 0
    for d in range (D):
      t += (l[j][d]-l[k][d])**2
      
    if t**(1/2)%1 ==0:
      cnt += 1
      
print(cnt)

# Optimized solution
N, D = list(map(int, input().split()))
X = []
for i in range(N):
  X.append(list(map(int, input().split())))
  
cnt = 0

for j in range (N-1):
  for k in range(j+1, N):
    t = 0
    for l in range(D):
      t += (X[j][l]-X[k][l])**2
      
    if t**(1/2)%1 ==0:
      cnt += 1
      
print(cnt)
# Original solution
f=lambda:list(map(int,input().split()))
n,d=f();x=[list(f()) for _ in range(n)]
print((sum(sum((x[i][k]-x[j][k])**2 for k in range(d))**.5%1==0 for j in range(n) for i in range(j))))

# Optimized solution
f=lambda:list(map(int,input().split()))
n,d=f();x=[list(f()) for _ in range(n)]
print((sum(sum((s-t)**2 for s,t in zip(x[i],x[j]))**.5%1==0 for j in range(n) for i in range(j))))
# Original solution
n,d = list(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):
    s = 0
    for k in range(d):
      s += abs(x[i][k] - x[j][k])**2
    s = s**0.5
    if s.is_integer(): ans += 1
print(ans)

# Optimized solution
n,d = list(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):
    t = 0
    for k in range(d): t += abs(x[i][k] - x[j][k])**2
    t **= 0.5
    if t.is_integer(): ans += 1
print(ans)
# Original solution
N, D = list(map(int, input().split()))
XX = [list(map(int, input().split())) for _ in range(N)]
ans = 0

for i1 in range(N):
    for i2 in range(i1+1, N):
        total = 0
        for index in range(D):
            total += (XX[i1][index] - XX[i2][index])**2
        val = total ** (1/2)
        if isinstance(val, complex):
            val = val.real
        if val.is_integer():
            ans += 1

print(ans)


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

for i1 in range(N):
    for i2 in range(i1+1, N):
        total = 0
        for index in range(D):
            total += (XX[i1][index] - XX[i2][index])**2
        val = int(total ** (1/2))
        if total == val ** 2:
            ans += 1

print(ans)
# Original solution
n,d = list(map(int, input().split()))
a =[[int(x) for x in input().split()] for i in range(n)]
cnt =0
sei = [i*i for i in range(10000)]

for i in range(n):
  for j in range(i):
    dis = sum( [((a[i][k] - a[j][k] )*(a[i][k] - a[j][k])) for k in range(d)])
    if dis in sei:
        cnt +=1
print(cnt)

# Optimized solution
n,d = list(map(int, input().split()))
xd = [(list(int(_) for _ in input().split())) for i in range(n)]
ans =0
for i in range(n):
  x1 = xd[i]
  for j in range(i+1,n):
    x2 = xd[j]
    dis =0
    for x,y in zip(x1,x2):
      dis += (y-x) **2
    k = dis **0.5

    if int(k)**2 ==dis:
      ans +=1
print(ans)
# Original solution
import itertools
import math

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

for n in N_list:
    length = 0
    for x_1, x_2 in zip(X[n[0]], X[n[1]]):
        length += (x_1-x_2)**2
    length = math.sqrt(length)
    if length == int(length):
        cnt += 1
        
print(cnt)

# Optimized solution
import math

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

for i in range(N):
    for j in range(i+1, N):
        length = 0
        for x_i, x_j in zip(X[i], X[j]):
            length += (x_i-x_j)**2
        length = math.sqrt(length)
        if length == int(length):
            cnt += 1

print(cnt)
# Original solution
N, D = list(map(int, input().split()))
X = []
for i in range(N):
  X.append(list(map(int, input().split())))
#print(X)

ans = 0
for i in range(N):
  for j in range(i+1, N):
    dist_sq = 0
    for x, y in zip(X[i], X[j]):
      dist_sq += (x - y) ** 2

    dist = dist_sq ** 0.5
    #print(i, j, dist)

    if dist - int(dist) == 0:
      ans += 1

print(ans)

# Optimized solution
import math

def abc133_b():
    N, D = list(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):
            sq = 0
            for k in range(D):
                sq += (X[i][k] - X[j][k]) ** 2
            rt = math.floor(math.sqrt(sq) + 0.5)
            if rt * rt == sq: ans += 1
    print(ans)

abc133_b()
# Original solution
def solve():
    n,d = list(map(int, input().split()))
    l = [[int(x) for x in input().split()] for _ in range(n)]
    count = 0
    for i in range(n):
        Y = l[i]
        for Z in l[i+1:]:
            total = 0
            for y,z in zip(Y,Z):
                total += (y-z)**2
            d = total**0.5
            if d == int(d):
                count += 1
    return count

if __name__ == '__main__':
    print((solve()))

# Optimized solution
import sys

def solve():
    n,d = list(map(int, input().split()))
    l = [list(map(int, X.split())) for X in sys.stdin.readlines()]
    count = 0
    for i in range(n):
        Y = l[i]
        for Z in l[i+1:]:
            total = 0
            for y,z in zip(Y,Z):
                total += (y-z)**2
            d = total**0.5
            if d == int(d):
                count += 1
    return count

if __name__ == '__main__':
    print((solve()))
# Original solution
a, b = list(map(int, input().split()))
c = []
e = 0
for i in range(a):
    c.append(list(map(int, input().split())))
for i in range(a):
    for j in range(i + 1, a):
        d = 0
        for k in range(b):
            d += (c[i][k] - c[j][k]) ** 2
        d = d ** 0.5
        if d == int(d):
            e += 1
print(e)


# Optimized solution
a, b = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(a)]
e = 0
for i in range(a):
    for j in range(i+1, a):
        d = 0
        for k in range(b):
            d += (c[i][k] - c[j][k]) ** 2
        d = d ** 0.5
        if d % 1 == 0:
            e += 1
print(e)
# Original solution
import math

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

for i in range(N):
    r1 = X[i]
    for j in range(N):
        t = str(i)+str(j)
        if i == j or t in tmp or str(j)+str(i) in tmp:
            continue

        r2 = X[j]
        ls = [(r1[j] - r2[j])**2 for j in range(D)]
        res = math.sqrt(sum(ls))

        if res % 1 == 0:
            count += 1
        tmp.append(t)

print(count)

# Optimized solution
import math
N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
count = 0

for i in range(N):
    r1 = X[i]
    for j in range(N-1, -1, -1):
        if i == j:
            break
        r2 = X[j]
        ls = [(r1[j] - r2[j])**2 for j in range(D)]
        res = math.sqrt(sum(ls))
        if res % 1 == 0:
            count += 1

print(count)
# Original solution
import math

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):
    for j in range(i, N):
        tmp = 0
        if i == j:
            continue
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if math.sqrt(tmp).is_integer():
            cnt += 1
        
print(cnt)

# Optimized solution
import math

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):
    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).is_integer():
            cnt += 1
        
print(cnt)
# Original solution
N, D = list(map(int, input().split()))
X = []
for _ in range(N):
    X.append([int(x) for x in input().split()])
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        s = sum((X[i][d] - X[j][d])**2 for d in range(D))
        if any(i**2 == s for i in range(1000)):
            ans += 1

print(ans)


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

X = [list(map(int, input().split())) for _ in range(N)]
S = {i**2 for i in range(1000)}
ans = sum(
    a != b and sum((x - y)**2 for x, y in zip(a, b)) in S
    for a in X
    for b in X
) // 2

print(ans)
# Original solution
import math
N,D = list(map(int,input().split()))
X = [list(map(int,input().split()))for _ in range(N)]

count = 0
a = 0
for i in range(N):
    for j in range(i + 1,N):
        for k in range(D):
            a += (X[i][k] - X[j][k])**2
        if math.sqrt(a) == int(math.sqrt(a)):
            count += 1
        a = 0

print(count)

# Optimized solution
import math
n,d=list(map(int,input().split()))
x=[list(map(int,input().split())) for _ in range(n)]

count=0
for i in range(n-1):
      for j in range(i+1,n):
            c=0
            for k in range(d):
                  c+=(x[i][k]-x[j][k])**2
            if math.sqrt(c)==int(math.sqrt(c)):
                  count+=1
print(count)
# Original solution
import math
n, d = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(n)]

flag = 0
for y in range(len(x)):
    for z in range(y+1, len(x)):
        distance2 = 0
        for i in range(d):
            distance2 += (x[y][i] - x[z][i]) ** 2
        distance = math.sqrt(distance2)
        distance = float(distance)
        if distance.is_integer():
            flag += 1
print(flag)


# Optimized solution
import math
N, D = list(map(int, input().split()))

x_list = []
for i in range(N):
    x = list(map(int,input().split()))
    x_list.append(x)
count = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        if i >= j:
            continue
        distance2 = 0
        for num in range(D):
            distance2 += (x_list[i - 1][num] - x_list[j - 1][num]) ** 2
        if math.sqrt(distance2).is_integer():
            count += 1
            
print(count)
# Original solution
N,D=list(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):
		t=0
		for x, y in zip(X[i],X[j]):
			t+=(x-y)**2	

		for h in range(1,10000):
			if t==h**2:
				ans+=1
				break

print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
import sys
N,D=list(map(int, sys.stdin.readline().split()))
X=[ list(map(int, sys.stdin.readline().split())) for _ in range(N) ]

L=[]  #2乗した数  
for i in range(201):
    L.append(i**2)

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        t=0
        for x1,x2 in zip(X[i],X[j]):
            t+=(x1-x2)**2
        if t in L:
            ans+=1
print(ans)
# Original solution
N,D=list(map(int,input().split()))
X=[list(map(int,input().split())) for i in range(N)]
l=len(X)
cnt=0
for i in range(l):
 for j in range(i+1,l):
  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5
  if t==int(t):cnt+=1
print(cnt)

# Optimized solution
N,D=list(map(int,input().split()))
X=[list(map(int,input().split())) for i in range(N)]
l=len(X)
cnt=0
for i in range(l):
 for j in range(i+1,l):
  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5
  cnt+=t==int(t)
print(cnt)
# Original solution
from math import sqrt
n, d = list(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)

# Optimized solution
n, d = list(map(int, input().split()))
lst = []
cnt = 0
for i in range(n):
    a = list(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
        dist = x ** 0.5
        if dist%1 == 0:
            if dist != 0:
                cnt += 1
print(cnt)
# Original solution
import math

n, d = list(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
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        distance = math.sqrt(sum)
        if distance.is_integer():
            cnt += 1

print(cnt)


# Optimized solution
n, d = list(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
        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)
# Original solution
n, d = list(map(int, input().split()))
X = []
for _ in range(n):
    X.append([int(x) for x in input().split()])
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        s = sum((X[i][d] - X[j][d])**2 for d in range(d))
        if any(k**2 == s for k in range(1000)):
            ans += 1
print(ans)


# Optimized solution
n, d = list(map(int, input().split()))
X = []
for _ in range(n):
    X.append([int(x) for x in input().split()])
ans = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    s = sum((X[i][d] - X[j][d])**2 for d in range(d))
    if (s ** .5).is_integer():
        ans += 1
print(ans)
# Original solution
import math

def main():
    n, d, *x = list(map(int, open(0).read().split()))

    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist = 0
            for cur_y, cur_z in zip(y, z):
                dist += (cur_y - cur_z) ** 2
            dist = math.sqrt(dist)
            if dist == int(dist):
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()


# Optimized solution
def main():
    n, d, *x = list(map(int, open(0).read().split()))

    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist_double = 0
            for cur_y, cur_z in zip(y, z):
                dist_double += (cur_y - cur_z) ** 2
            dist = int(dist_double ** 0.5 + 0.5)
            if dist ** 2 == dist_double:
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()
# Original solution
n,d = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(n)]

def dist_squere(x, y):
    d = 0
    for i,j in zip(x,y):
        d += (i-j)**2
    return d

squares = set([i*i for i in range(10000)])
def is_square(x):
    return x in squares

from itertools import combinations

ans = 0
for x,y in combinations(X, 2):
    if is_square(dist_squere(x, y)):
        ans += 1

print(ans)

# Optimized solution
n,d = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(n)]

def dist_squere(x, y):
    d = 0
    for i,j in zip(x,y):
        d += (i-j)**2
    return d**.5

from itertools import combinations

ans = 0
for x,y in combinations(X, 2):
    if dist_squere(x, y).is_integer():
        ans += 1

print(ans)
# Original solution
import math

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

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

for i in range(N-1):
  for j in range(i+1,N):
    for k in range(D):
      s+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k])
    s=math.sqrt(s)
    #print(s)
    if s==int(s):
      cnt+=1
    s=0
print(cnt)

# Optimized solution
import math

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

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

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])*(x[i][k]-x[j][k])

    dis=math.sqrt(dis)
    if dis==int(dis):
      cnt+=1

print(cnt)
# Original solution
N, D = list(map(int, input().split()))
X = [[int(j) for j in input().split()] for i in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        acum = 0.0
        for k in range(D):
            acum += (X[j][k] - X[i][k]) ** 2
        if float.is_integer(acum ** 0.5):
            ans += 1
print(ans)


# Optimized solution
N, D = list(map(int, input().split()))
X = [[int(j) for j in input().split()] for i in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        acum = 0.0
        for k in range(D):
            acum += (X[j][k] - X[i][k]) ** 2
        if (acum ** 0.5).is_integer():
            ans += 1
print(ans)
# Original solution
n,d=list(map(int,input().split()))
X=[]
for _ in range(n):
    X.append(list(map(int,input().split())))

f=0
for i in range(n-1):
  for j in range(i+1,n):
    l=0
    for a in range(d):
      l+=(X[i][a]-X[j][a])**2
    if int(l**(1/2))==l**(1/2):
        f+=1
print(f)

# Optimized solution
n,d=list(map(int,input().split()))
X=[list(map(int,input().split())) for _ in range(n)]
f=0
for i in range(n-1):
  for j in range(i+1,n):
    l=0
    for a in range(d):
      l+=(X[i][a]-X[j][a])**2
    if int(l**(1/2))==l**(1/2):
        f+=1
print(f)