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();

      int[][] x = new int[n+1][d+1];
      int z = 10;
      int s = 0;
      int count = 0;

      for (int j = 1; j<=n; j++) {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    }

      for (int j = 1;j<n ;j++ ) {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    }


      System.out.println(count);
}
} 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();

      int[][] x = new int[n+1][d+1];
      int z = 10;
      int s = 0;
      int count = 0;

      for (int j = 1; j<=n; j++) {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    }

      for (int j = 1;j<n ;j++ ) {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    }


      System.out.println(count);
}
} 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+1][d+1];
      int z = 10;
      int s = 0;
      int count = 0;

      for (int j = 1; j<=n; j++) {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    }

      for (int j = 1;j<n ;j++ ) {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    }


      System.out.println(count);
} main {
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      int d = sc.nextInt();

      int[][] x = new int[n+1][d+1];
      int z = 10;
      int s = 0;
      int count = 0;

      for (int j = 1; j<=n; j++) {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    }

      for (int j = 1;j<n ;j++ ) {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          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 int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int[][] x = new int[n+1][d+1]; x new int[n+1][d+1] n+1 n 1 d+1 d 1 int z = 10; z 10 int s = 0; s 0 int count = 0; count 0 for (int j = 1; j<=n; j++) {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    } int j = 1; int j = 1; j 1 j<=n j n j++ j++ j {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    } {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    } for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      } int i = 1; int i = 1; i 1 i<=d i d i++ i++ i {
        x[j][i] = sc.nextInt();
      } {
        x[j][i] = sc.nextInt();
      } x[j][i] = sc.nextInt() x[j][i] x[j] x j i sc.nextInt() sc.nextInt sc for (int j = 1;j<n ;j++ ) {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    } int j = 1; int j = 1; j 1 j<n j n j++ j++ j {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    } {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    } for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      } int k = 0; int k = 0; k 0 k+j<n k+j k j n k++ k++ k {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      } {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      } s = 0 s 0 for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        } int i = 1; int i = 1; i 1 i<=d i d i++ i++ i {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        } {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        } s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]) s s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]) s Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]) Math.abs(x[j][i]-x[j+1+k][i]) Math.abs Math x[j][i]-x[j+1+k][i] x[j][i] x[j] x j i x[j+1+k][i] x[j+1+k] x j+1+k j+1+k j 1 k i Math.abs(x[j][i]-x[j+1+k][i]) Math.abs Math x[j][i]-x[j+1+k][i] x[j][i] x[j] x j i x[j+1+k][i] x[j+1+k] x j+1+k j+1+k j 1 k i double a = Math.sqrt(s); a Math.sqrt(s) Math.sqrt Math s if(a==(int)a){
          count++;
        } a==(int)a a (int)a {
          count++;
        } count++ count System.out.println(count) System.out.println System.out System System.out count 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+1][d+1];
      int z = 10;
      int s = 0;
      int count = 0;

      for (int j = 1; j<=n; j++) {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    }

      for (int j = 1;j<n ;j++ ) {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    }


      System.out.println(count);
}
} 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+1][d+1];
      int z = 10;
      int s = 0;
      int count = 0;

      for (int j = 1; j<=n; j++) {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    }

      for (int j = 1;j<n ;j++ ) {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    }


      System.out.println(count);
}
} 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();

      int[][] x = new int[n+1][d+1];
      int z = 10;
      int s = 0;
      int count = 0;

      for (int j = 1; j<=n; j++) {
      for (int i = 1; i<=d; i++) {
        x[j][i] = sc.nextInt();
      }
    }

      for (int j = 1;j<n ;j++ ) {
        for (int k = 0;k+j<n ;k++) {
         s = 0;
        for (int i = 1;i<=d ;i++ ) {
             s = s + Math.abs(x[j][i]-x[j+1+k][i])*Math.abs(x[j][i]-x[j+1+k][i]);
        }
        double a = Math.sqrt(s);

        if(a==(int)a){
          count++;
        }
      }
    }


      System.out.println(count);
}
}
