import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int 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();
		    }
		}
		
		// 計算
		int result = 0;
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		}

		// 出力
		System.out.println(result);
	}
} import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; import java.math.BigInteger; BigInteger java.math public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int 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();
		    }
		}
		
		// 計算
		int result = 0;
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		}

		// 出力
		System.out.println(result);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int 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();
		    }
		}
		
		// 計算
		int result = 0;
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		}

		// 出力
		System.out.println(result);
	} main {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int 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();
		    }
		}
		
		// 計算
		int result = 0;
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		}

		// 出力
		System.out.println(result);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int 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();
		    }
		} 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] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt sc int result = 0; result 0 for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		} {
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		} for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    } int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    } {
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    } long dist = 0; dist 0 for(int k = 0; k < d; k++){
		            dist += (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 {
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        } {
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        } dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]) dist (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 boolean flg = false; flg false for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        } int k = 0; int k = 0; k 0 k <= sqrt(dist) k sqrt(dist) sqrt dist k++ k++ k {
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        } {
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        } if(dist == k*k){
		                flg = true;
		                break;
		            } dist == k*k dist k*k k k {
		                flg = true;
		                break;
		            } flg = true flg true break; if(flg) result++; flg result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int 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();
		    }
		}
		
		// 計算
		int result = 0;
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		}

		// 出力
		System.out.println(result);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int 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();
		    }
		}
		
		// 計算
		int result = 0;
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		}

		// 出力
		System.out.println(result);
	}
} Main
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int 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();
		    }
		}
		
		// 計算
		int result = 0;
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        long dist = 0;
		        for(int k = 0; k < d; k++){
		            dist += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
		        }
		        boolean flg = false;
		        for(int k = 0; k <= sqrt(dist); k++){
		            if(dist == k*k){
		                flg = true;
		                break;
		            } 
		        }
		        if(flg) result++;
		    }
		}

		// 出力
		System.out.println(result);
	}
}
