import java.util.Scanner;

public class Main {
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		d = sc.nextInt();
		point[] points = new point[n];
		for(int i = 0; i < n; i++){
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}
class point{
	static int d;
	static{
		d = Main.d;
	}
	int[] x;
	point(int... x){
		this.x = x;
	}
	boolean checkGD(point p){
		double dist = 0;
		for(int i = 0; i < d; i++){
			dist += (int)Math.pow(this.x[i] - p.x[i], 2);
		}
		dist = Math.sqrt(dist);
		int idist = (int)dist;
		return (int)(dist * dist * dist * dist) == idist * idist * idist * idist;
//		return dist == dist % 1;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		d = sc.nextInt();
		point[] points = new point[n];
		for(int i = 0; i < n; i++){
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		}
		System.out.println(count);
	}
} Main static int d; d public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		d = sc.nextInt();
		point[] points = new point[n];
		for(int i = 0; i < n; i++){
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		d = sc.nextInt();
		point[] points = new point[n];
		for(int i = 0; i < n; i++){
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		}
		System.out.println(count);
	} 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 point[] points = new point[n]; points new point[n] n for(int i = 0; i < n; i++){
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		} {
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		} int[] x = new int[d]; x new int[d] d for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			} int i2 = 0; int i2 = 0; i2 0 i2 < d i2 d i2++ i2++ i2 {
				x[i2] = sc.nextInt();
			} {
				x[i2] = sc.nextInt();
			} x[i2] = sc.nextInt() x[i2] x i2 sc.nextInt() sc.nextInt sc points[i] = new point(x) points[i] points i new point(x) int count = 0; count 0 for(int i = 0; i < n; i++){
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		} {
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		} for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			} int i2 = i + 1 ; int i2 = i + 1 ; i2 i + 1 i 1 i2 < n i2 n i2++ i2++ i2 {
				if(points[i].checkGD(points[i2])){
					count++;
				}
			} {
				if(points[i].checkGD(points[i2])){
					count++;
				}
			} if(points[i].checkGD(points[i2])){
					count++;
				} points[i].checkGD(points[i2]) points[i].checkGD points[i] points i points[i2] points i2 {
					count++;
				} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args class point{
	static int d;
	static{
		d = Main.d;
	}
	int[] x;
	point(int... x){
		this.x = x;
	}
	boolean checkGD(point p){
		double dist = 0;
		for(int i = 0; i < d; i++){
			dist += (int)Math.pow(this.x[i] - p.x[i], 2);
		}
		dist = Math.sqrt(dist);
		int idist = (int)dist;
		return (int)(dist * dist * dist * dist) == idist * idist * idist * idist;
//		return dist == dist % 1;
	}
} point static int d; d int[] x; x point(int... x){
		this.x = x;
	} point {
		this.x = x;
	} this.x = x this.x this this.x x int... x x boolean checkGD(point p){
		double dist = 0;
		for(int i = 0; i < d; i++){
			dist += (int)Math.pow(this.x[i] - p.x[i], 2);
		}
		dist = Math.sqrt(dist);
		int idist = (int)dist;
		return (int)(dist * dist * dist * dist) == idist * idist * idist * idist;
//		return dist == dist % 1;
	} checkGD {
		double dist = 0;
		for(int i = 0; i < d; i++){
			dist += (int)Math.pow(this.x[i] - p.x[i], 2);
		}
		dist = Math.sqrt(dist);
		int idist = (int)dist;
		return (int)(dist * dist * dist * dist) == idist * idist * idist * idist;
//		return dist == dist % 1;
	} double dist = 0; dist 0 for(int i = 0; i < d; i++){
			dist += (int)Math.pow(this.x[i] - p.x[i], 2);
		} int i = 0; int i = 0; i 0 i < d i d i++ i++ i {
			dist += (int)Math.pow(this.x[i] - p.x[i], 2);
		} {
			dist += (int)Math.pow(this.x[i] - p.x[i], 2);
		} dist += (int)Math.pow(this.x[i] - p.x[i], 2) dist (int)Math.pow(this.x[i] - p.x[i], 2) Math.pow Math this.x[i] - p.x[i] this.x[i] this.x this this.x i p.x[i] p.x p p.x i 2 dist = Math.sqrt(dist) dist Math.sqrt(dist) Math.sqrt Math dist int idist = (int)dist; idist (int)dist return (int)(dist * dist * dist * dist) == idist * idist * idist * idist; (int)(dist * dist * dist * dist) == idist * idist * idist * idist (int)(dist * dist * dist * dist) dist dist * dist * dist * dist dist dist dist dist idist * idist * idist * idist idist idist * idist * idist * idist idist idist idist idist point p p public class Main {
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		d = sc.nextInt();
		point[] points = new point[n];
		for(int i = 0; i < n; i++){
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		}
		System.out.println(count);
	}
} public class Main {
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		d = sc.nextInt();
		point[] points = new point[n];
		for(int i = 0; i < n; i++){
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		}
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main {
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		d = sc.nextInt();
		point[] points = new point[n];
		for(int i = 0; i < n; i++){
			int[] x = new int[d];
			for(int i2 = 0; i2 < d; i2++){
				x[i2] = sc.nextInt();
			}
			points[i] = new point(x);
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int i2 = i + 1 ; i2 < n; i2++){
				if(points[i].checkGD(points[i2])){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}
class point{
	static int d;
	static{
		d = Main.d;
	}
	int[] x;
	point(int... x){
		this.x = x;
	}
	boolean checkGD(point p){
		double dist = 0;
		for(int i = 0; i < d; i++){
			dist += (int)Math.pow(this.x[i] - p.x[i], 2);
		}
		dist = Math.sqrt(dist);
		int idist = (int)dist;
		return (int)(dist * dist * dist * dist) == idist * idist * idist * idist;
//		return dist == dist % 1;
	}
}
