import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] X = new int[N][D];
		for(int i = 0;i < N;i++) {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		}
		sc.close();
		int ans = 0;
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] X = new int[N][D];
		for(int i = 0;i < N;i++) {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		}
		sc.close();
		int ans = 0;
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] X = new int[N][D];
		for(int i = 0;i < N;i++) {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		}
		sc.close();
		int ans = 0;
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] X = new int[N][D];
		for(int i = 0;i < N;i++) {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		}
		sc.close();
		int ans = 0;
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int D = Integer.parseInt(sc.next()); D Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[][] X = new int[N][D]; X new int[N][D] N D for(int i = 0;i < N;i++) {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		} {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		} for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			} int  j = 0; int  j = 0; j 0 j < D j D j++ j++ j {
				X[i][j] = Integer.parseInt(sc.next());
			} {
				X[i][j] = Integer.parseInt(sc.next());
			} X[i][j] = Integer.parseInt(sc.next()) X[i][j] X[i] X i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int ans = 0; ans 0 for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		} {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		} for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			} int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			} {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			} int norm = 0; norm 0 for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				} {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				} int diff = Math.abs(X[i][k] - X[j][k]); diff Math.abs(X[i][k] - X[j][k]) Math.abs Math X[i][k] - X[j][k] X[i][k] X[i] X i k X[j][k] X[j] X j k norm += Math.pow(diff,2) norm Math.pow(diff,2) Math.pow Math diff 2 boolean flg = false; flg false for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				} int k = 0; int k = 0; k 0 k <= norm k norm k++ k++ k {
					if(k * k == norm) {
						flg = true;
					}
				} {
					if(k * k == norm) {
						flg = true;
					}
				} if(k * k == norm) {
						flg = true;
					} k * k == norm k * k k k norm {
						flg = true;
					} flg = true flg true if(flg) {
					ans++;
				} flg {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] X = new int[N][D];
		for(int i = 0;i < N;i++) {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		}
		sc.close();
		int ans = 0;
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] X = new int[N][D];
		for(int i = 0;i < N;i++) {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		}
		sc.close();
		int ans = 0;
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] X = new int[N][D];
		for(int i = 0;i < N;i++) {
			for(int  j = 0;j < D;j++) {
				X[i][j] = Integer.parseInt(sc.next());
			}
		}
		sc.close();
		int ans = 0;
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				int norm = 0;
				for(int k = 0;k < D;k++) {
					int diff = Math.abs(X[i][k] - X[j][k]);
					norm += Math.pow(diff,2);
				}
				boolean flg = false;
				for(int k = 0;k <= norm;k++) {
					if(k * k == norm) {
						flg = true;
					}
				}
				if(flg) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}
