import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    int D = scanner.nextInt();
	    int X[][] = new int[N][D];
	    for(int i=0;i<N;i++){
	      for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      }
	    }

	    int resultNumber = 0;
	    int temp = 0;
	    for(int i=0;i<N-1;i++){
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    }
	    System.out.println(resultNumber);
	    scanner.close();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    int D = scanner.nextInt();
	    int X[][] = new int[N][D];
	    for(int i=0;i<N;i++){
	      for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      }
	    }

	    int resultNumber = 0;
	    int temp = 0;
	    for(int i=0;i<N-1;i++){
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    }
	    System.out.println(resultNumber);
	    scanner.close();
	}

} Main public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    int D = scanner.nextInt();
	    int X[][] = new int[N][D];
	    for(int i=0;i<N;i++){
	      for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      }
	    }

	    int resultNumber = 0;
	    int temp = 0;
	    for(int i=0;i<N-1;i++){
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    }
	    System.out.println(resultNumber);
	    scanner.close();
	} main {
	    Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    int D = scanner.nextInt();
	    int X[][] = new int[N][D];
	    for(int i=0;i<N;i++){
	      for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      }
	    }

	    int resultNumber = 0;
	    int temp = 0;
	    for(int i=0;i<N-1;i++){
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    }
	    System.out.println(resultNumber);
	    scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int D = scanner.nextInt(); D scanner.nextInt() scanner.nextInt scanner 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] = scanner.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] = scanner.nextInt();
	      }
	    } {
	      for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      }
	    } for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      } int j=0; int j=0; j 0 j<D j D j++ j++ j {
	        X[i][j] = scanner.nextInt();
	      } {
	        X[i][j] = scanner.nextInt();
	      } X[i][j] = scanner.nextInt() X[i][j] X[i] X i j scanner.nextInt() scanner.nextInt scanner int resultNumber = 0; resultNumber 0 int temp = 0; temp 0 for(int i=0;i<N-1;i++){
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    } 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++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    } {
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    } for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      } int j=i+1; int j=i+1; j i+1 i 1 j<N j N j++ j++ j {
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      } {
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      } for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        } int k=0; int k=0; k 0 k<D k D k++ k++ k {
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        } {
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        } temp += Math.pow((X[i][k] - X[j][k]),2) temp Math.pow((X[i][k] - X[j][k]),2) Math.pow Math (X[i][k] - X[j][k]) X[i][k] X[i] X i k X[j][k] X[j] X j k 2 if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          } k==D-1 k D-1 D 1 {
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          } if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            } Math.sqrt(temp) == (int)Math.sqrt(temp) Math.sqrt(temp) Math.sqrt Math temp (int)Math.sqrt(temp) Math.sqrt Math temp {
	              resultNumber++;
	            } resultNumber++ resultNumber temp = 0 temp 0 System.out.println(resultNumber) System.out.println System.out System System.out resultNumber scanner.close() scanner.close scanner String[] args args public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    int D = scanner.nextInt();
	    int X[][] = new int[N][D];
	    for(int i=0;i<N;i++){
	      for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      }
	    }

	    int resultNumber = 0;
	    int temp = 0;
	    for(int i=0;i<N-1;i++){
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    }
	    System.out.println(resultNumber);
	    scanner.close();
	}

} public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    int D = scanner.nextInt();
	    int X[][] = new int[N][D];
	    for(int i=0;i<N;i++){
	      for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      }
	    }

	    int resultNumber = 0;
	    int temp = 0;
	    for(int i=0;i<N-1;i++){
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    }
	    System.out.println(resultNumber);
	    scanner.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    int D = scanner.nextInt();
	    int X[][] = new int[N][D];
	    for(int i=0;i<N;i++){
	      for(int j=0;j<D;j++){
	        X[i][j] = scanner.nextInt();
	      }
	    }

	    int resultNumber = 0;
	    int temp = 0;
	    for(int i=0;i<N-1;i++){
	      for(int j=i+1;j<N;j++){
	        for(int k=0;k<D;k++){
	          temp += Math.pow((X[i][k] - X[j][k]),2);
	          if(k==D-1){
	            if(Math.sqrt(temp) == (int)Math.sqrt(temp)){
	              resultNumber++;
	            }
	            temp = 0;
	          }
	        }
	      }
	    }
	    System.out.println(resultNumber);
	    scanner.close();
	}

}
