import java.util.*;
public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int arr[][] = new int[n][d];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		}
		int count=0;
		double dist = 0;
		for(int i=0;i<n-1;i++)
		{
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		}
		System.out.println(count);
		sc.close();
	}

} import java.util.*; util.* java public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int arr[][] = new int[n][d];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		}
		int count=0;
		double dist = 0;
		for(int i=0;i<n-1;i++)
		{
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		}
		System.out.println(count);
		sc.close();
	}

} Main public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int arr[][] = new int[n][d];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		}
		int count=0;
		double dist = 0;
		for(int i=0;i<n-1;i++)
		{
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		}
		System.out.println(count);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int arr[][] = new int[n][d];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		}
		int count=0;
		double dist = 0;
		for(int i=0;i<n-1;i++)
		{
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		}
		System.out.println(count);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int arr[][] = new int[n][d]; arr new int[n][d] n d for(int i=0;i<n;i++)
		{
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		} {
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		} for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			} int j=0; int j=0; j 0 j<d j d j++ j++ j {
				arr[i][j] = sc.nextInt();
			} {
				arr[i][j] = sc.nextInt();
			} arr[i][j] = sc.nextInt() arr[i][j] arr[i] arr i j sc.nextInt() sc.nextInt sc int count=0; count 0 double dist = 0; dist 0 for(int i=0;i<n-1;i++)
		{
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		} int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		} {
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		} for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			} int j = i+1; int j = i+1; j i+1 i 1 j<n j n j++ j++ j {
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			} {
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			} for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				} int k = 0; int k = 0; k 0 k<d k d k++ k++ k {
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				} {
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				} dist += (double)(Math.pow(arr[i][k]- arr[j][k],2)) dist (double)(Math.pow(arr[i][k]- arr[j][k],2)) Math.pow Math arr[i][k]- arr[j][k] arr[i][k] arr[i] arr i k arr[j][k] arr[j] arr j k 2 dist = (double)Math.sqrt(dist) dist (double)Math.sqrt(dist) Math.sqrt Math dist double ans = Math.ceil(dist); ans Math.ceil(dist) Math.ceil Math dist if(ans == dist)
					count++; ans == dist ans dist count++ count dist=0 dist 0 System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int arr[][] = new int[n][d];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		}
		int count=0;
		double dist = 0;
		for(int i=0;i<n-1;i++)
		{
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		}
		System.out.println(count);
		sc.close();
	}

} public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int arr[][] = new int[n][d];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		}
		int count=0;
		double dist = 0;
		for(int i=0;i<n-1;i++)
		{
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		}
		System.out.println(count);
		sc.close();
	}

} Main
import java.util.*;
public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int arr[][] = new int[n][d];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<d;j++)
			{
				arr[i][j] = sc.nextInt();
			}
		}
		int count=0;
		double dist = 0;
		for(int i=0;i<n-1;i++)
		{
			for(int j = i+1;j<n;j++)
			{
				for(int k = 0;k<d;k++)
				{
					dist += (double)(Math.pow(arr[i][k]- arr[j][k],2));
				}
				dist = (double)Math.sqrt(dist);
				//System.out.println(dist);
				double ans = Math.ceil(dist);
				
				if(ans == dist)
					count++;
				dist=0;
			}
		}
		System.out.println(count);
		sc.close();
	}

}
