import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		int cnt = 0;
		
		int[][] point = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		}
		
		
		for(int i = 0; i < n-1; i++) {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		}
		
		System.out.println(cnt);
		
		
		
		
		
		
		
	}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		int cnt = 0;
		
		int[][] point = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		}
		
		
		for(int i = 0; i < n-1; i++) {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		}
		
		System.out.println(cnt);
		
		
		
		
		
		
		
	}

} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		int cnt = 0;
		
		int[][] point = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		}
		
		
		for(int i = 0; i < n-1; i++) {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		}
		
		System.out.println(cnt);
		
		
		
		
		
		
		
	} main {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		int cnt = 0;
		
		int[][] point = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		}
		
		
		for(int i = 0; i < n-1; i++) {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		}
		
		System.out.println(cnt);
		
		
		
		
		
		
		
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int d = stdIn.nextInt(); d stdIn.nextInt() stdIn.nextInt stdIn int cnt = 0; cnt 0 int[][] point = new int[n][d]; point new int[n][d] n d for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		} {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		} for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				point[i][j] = stdIn.nextInt();
			} {
				point[i][j] = stdIn.nextInt();
			} point[i][j] = stdIn.nextInt() point[i][j] point[i] point i j stdIn.nextInt() stdIn.nextInt stdIn for(int i = 0; i < n-1; i++) {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		} 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++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		} {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		} for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			} int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			} {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			} int distance = 0; distance 0 for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				} {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				} distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]) distance (point[j][k] - point[i][k])*(point[j][k] - point[i][k]) (point[j][k] - point[i][k]) point[j][k] point[j] point j k point[i][k] point[i] point i k (point[j][k] - point[i][k]) point[j][k] point[j] point j k point[i][k] point[i] point i k if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				} Math.sqrt(distance)==(int)Math.sqrt(distance) Math.sqrt(distance) Math.sqrt Math distance (int)Math.sqrt(distance) Math.sqrt Math distance {
					//System.out.println(distance);
					cnt++;
				} cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		int cnt = 0;
		
		int[][] point = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		}
		
		
		for(int i = 0; i < n-1; i++) {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		}
		
		System.out.println(cnt);
		
		
		
		
		
		
		
	}

} public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		int cnt = 0;
		
		int[][] point = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		}
		
		
		for(int i = 0; i < n-1; i++) {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		}
		
		System.out.println(cnt);
		
		
		
		
		
		
		
	}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		int cnt = 0;
		
		int[][] point = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		}
		
		
		for(int i = 0; i < n-1; i++) {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		}
		
		System.out.println(cnt);
		
		
		
		
		
		
		
	}

}
