import java.util.*;

public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}
		int out = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		}
		System.out.println(out);
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
} import java.util.*; util.* java public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}
		int out = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		}
		System.out.println(out);
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
} Main void solve() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}
		int out = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		}
		System.out.println(out);
		scan.close();
	} solve {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}
		int out = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		}
		System.out.println(out);
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int d = scan.nextInt(); d scan.nextInt() scan.nextInt scan 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] = scan.nextInt();
			}
		} 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] = scan.nextInt();
			}
		} {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		} for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				x[i][j] = scan.nextInt();
			} {
				x[i][j] = scan.nextInt();
			} x[i][j] = scan.nextInt() x[i][j] x[i] x i j scan.nextInt() scan.nextInt scan int out = 0; out 0 for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		} 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++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		} {
			for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		} for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			} {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			} double distance = 0; distance 0 for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				} {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				} distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) distance (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k distance = Math.sqrt(distance) distance Math.sqrt(distance) Math.sqrt Math distance if(distance % 1 == 0) out++; distance % 1 == 0 distance % 1 distance 1 0 out++ out System.out.println(out) System.out.println System.out System System.out out scan.close() scan.close scan public static void main(String[] args) {
		new Main().solve();
	} main {
		new Main().solve();
	} new Main().solve() new Main().solve new Main() String[] args args public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}
		int out = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		}
		System.out.println(out);
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
} public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}
		int out = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		}
		System.out.println(out);
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
} Main
import java.util.*;

public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}
		int out = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double distance = 0;
				for(int k = 0; k < d; k++) {
					distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance % 1 == 0) out++;
			}
		}
		System.out.println(out);
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}
