import java.util.*;

public class Main {

	public static boolean dis(int x[], int y[], int d){
		long ans = 0;
		for(int i = 0; i < d; ++i){
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		}
		double ansd = Math.sqrt((double)ans);
		return (ansd == Math.floor(ansd));
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt();
		int x[][] = new int[n][d];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < d; ++j)
				x[i][j] = sc.nextInt();
		sc.close();
		int ans = 0;
		for(int i = 0; i < n;++i){
			for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			}
		}

		System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {

	public static boolean dis(int x[], int y[], int d){
		long ans = 0;
		for(int i = 0; i < d; ++i){
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		}
		double ansd = Math.sqrt((double)ans);
		return (ansd == Math.floor(ansd));
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt();
		int x[][] = new int[n][d];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < d; ++j)
				x[i][j] = sc.nextInt();
		sc.close();
		int ans = 0;
		for(int i = 0; i < n;++i){
			for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			}
		}

		System.out.println(ans);
	}
} Main public static boolean dis(int x[], int y[], int d){
		long ans = 0;
		for(int i = 0; i < d; ++i){
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		}
		double ansd = Math.sqrt((double)ans);
		return (ansd == Math.floor(ansd));
	} dis {
		long ans = 0;
		for(int i = 0; i < d; ++i){
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		}
		double ansd = Math.sqrt((double)ans);
		return (ansd == Math.floor(ansd));
	} long ans = 0; ans 0 for(int i = 0; i < d; ++i){
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		} int i = 0; int i = 0; i 0 i < d i d ++i ++i i {
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		} {
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		} int tmpx = x[i]; tmpx x[i] x i int tmpy = y[i]; tmpy y[i] y i ans += (tmpx - tmpy) * (tmpx - tmpy) ans (tmpx - tmpy) * (tmpx - tmpy) (tmpx - tmpy) tmpx tmpy (tmpx - tmpy) tmpx tmpy double ansd = Math.sqrt((double)ans); ansd Math.sqrt((double)ans) Math.sqrt Math (double)ans return (ansd == Math.floor(ansd)); (ansd == Math.floor(ansd)) ansd Math.floor(ansd) Math.floor Math ansd int x[] x int y[] y int d d public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt();
		int x[][] = new int[n][d];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < d; ++j)
				x[i][j] = sc.nextInt();
		sc.close();
		int ans = 0;
		for(int i = 0; i < n;++i){
			for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			}
		}

		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt();
		int x[][] = new int[n][d];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < d; ++j)
				x[i][j] = sc.nextInt();
		sc.close();
		int ans = 0;
		for(int i = 0; i < n;++i){
			for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			}
		}

		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc d = sc.nextInt(); d sc.nextInt() sc.nextInt 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] = sc.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] = sc.nextInt(); for (int j = 0; j < d; ++j)
				x[i][j] = sc.nextInt(); int j = 0; int j = 0; j 0 j < d j d ++j ++j j x[i][j] = sc.nextInt(); x[i][j] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt 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){
				if(dis(x[i], x[j], d))++ans;
			}
		} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
			for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			}
		} {
			for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			}
		} for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n ++j ++j j {
				if(dis(x[i], x[j], d))++ans;
			} {
				if(dis(x[i], x[j], d))++ans;
			} if(dis(x[i], x[j], d))++ans; dis(x[i], x[j], d) dis x[i] x i x[j] x j d ++ans ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static boolean dis(int x[], int y[], int d){
		long ans = 0;
		for(int i = 0; i < d; ++i){
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		}
		double ansd = Math.sqrt((double)ans);
		return (ansd == Math.floor(ansd));
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt();
		int x[][] = new int[n][d];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < d; ++j)
				x[i][j] = sc.nextInt();
		sc.close();
		int ans = 0;
		for(int i = 0; i < n;++i){
			for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			}
		}

		System.out.println(ans);
	}
} public class Main {

	public static boolean dis(int x[], int y[], int d){
		long ans = 0;
		for(int i = 0; i < d; ++i){
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		}
		double ansd = Math.sqrt((double)ans);
		return (ansd == Math.floor(ansd));
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt();
		int x[][] = new int[n][d];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < d; ++j)
				x[i][j] = sc.nextInt();
		sc.close();
		int ans = 0;
		for(int i = 0; i < n;++i){
			for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			}
		}

		System.out.println(ans);
	}
} Main
import java.util.*;

public class Main {

	public static boolean dis(int x[], int y[], int d){
		long ans = 0;
		for(int i = 0; i < d; ++i){
			int tmpx = x[i];
			int tmpy = y[i];
			ans += (tmpx - tmpy) * (tmpx - tmpy);
		}
		double ansd = Math.sqrt((double)ans);
		return (ansd == Math.floor(ansd));
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt();
		int x[][] = new int[n][d];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < d; ++j)
				x[i][j] = sc.nextInt();
		sc.close();
		int ans = 0;
		for(int i = 0; i < n;++i){
			for(int j = i + 1; j < n; ++j){
				if(dis(x[i], x[j], d))++ans;
			}
		}

		System.out.println(ans);
	}
}
