import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    double s = 0;
    double ss = 0;
    String[] array1 ;
    String[][] array2 = new String[n][d];
    int count =0;

    for(int i=0; i<n; i++){
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    }

    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    }
    System.out.println(count/2);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    double s = 0;
    double ss = 0;
    String[] array1 ;
    String[][] array2 = new String[n][d];
    int count =0;

    for(int i=0; i<n; i++){
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    }

    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    }
    System.out.println(count/2);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    double s = 0;
    double ss = 0;
    String[] array1 ;
    String[][] array2 = new String[n][d];
    int count =0;

    for(int i=0; i<n; i++){
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    }

    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    }
    System.out.println(count/2);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    double s = 0;
    double ss = 0;
    String[] array1 ;
    String[][] array2 = new String[n][d];
    int count =0;

    for(int i=0; i<n; i++){
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    }

    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    }
    System.out.println(count/2);
  } 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 double s = 0; s 0 double ss = 0; ss 0 String[] array1 ; array1 String[][] array2 = new String[n][d]; array2 new String[n][d] n d int count =0; count 0 for(int i=0; i<n; i++){
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    } {
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    } for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      } int j=0; int j=0; j 0 j<d j d j++ j++ j {
        array2[i][j] = sc.next();
      } {
        array2[i][j] = sc.next();
      } array2[i][j] = sc.next() array2[i][j] array2[i] array2 i j sc.next() sc.next sc for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    } {
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    } for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      } int j=0; int j=0; j 0 j<n j n j++ j++ j {
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      } {
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      } for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        } int k=0; int k=0; k 0 k<d k d k++ k++ k {
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        } {
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        } s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) s Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) Math.pow Math (Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])) Integer.valueOf(array2[i][k]) Integer.valueOf Integer array2[i][k] array2[i] array2 i k Integer.valueOf(array2[j][k]) Integer.valueOf Integer array2[j][k] array2[j] array2 j k 2 ss = Math.sqrt(s) ss Math.sqrt(s) Math.sqrt Math s if(ss == (int)ss && ss != 0){
          count += 1;
        } ss == (int)ss && ss != 0 ss == (int)ss ss (int)ss ss != 0 ss 0 {
          count += 1;
        } count += 1 count 1 s= 0 s 0 System.out.println(count/2) System.out.println System.out System System.out count/2 count 2 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();
    double s = 0;
    double ss = 0;
    String[] array1 ;
    String[][] array2 = new String[n][d];
    int count =0;

    for(int i=0; i<n; i++){
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    }

    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    }
    System.out.println(count/2);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    double s = 0;
    double ss = 0;
    String[] array1 ;
    String[][] array2 = new String[n][d];
    int count =0;

    for(int i=0; i<n; i++){
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    }

    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    }
    System.out.println(count/2);
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    double s = 0;
    double ss = 0;
    String[] array1 ;
    String[][] array2 = new String[n][d];
    int count =0;

    for(int i=0; i<n; i++){
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    }

    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    }
    System.out.println(count/2);
  }
}