import java.util.*;

public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      int ans = 0;
      double sum = 0;
      
      double[][] ary = new double[n][d];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      }
      
      for (int i = 0; i < n -1; i++) {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      }
      System.out.print(ans);
    }
}
 import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      int ans = 0;
      double sum = 0;
      
      double[][] ary = new double[n][d];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      }
      
      for (int i = 0; i < n -1; i++) {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      }
      System.out.print(ans);
    }
} Main public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      int ans = 0;
      double sum = 0;
      
      double[][] ary = new double[n][d];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      }
      
      for (int i = 0; i < n -1; i++) {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      }
      System.out.print(ans);
    } main {
      
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      int ans = 0;
      double sum = 0;
      
      double[][] ary = new double[n][d];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      }
      
      for (int i = 0; i < n -1; i++) {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      }
      System.out.print(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int ans = 0; ans 0 double sum = 0; sum 0 double[][] ary = new double[n][d]; ary new double[n][d] n d for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      } {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      } for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
          ary[i][j] = Double.parseDouble(sc.next());
        } {
          ary[i][j] = Double.parseDouble(sc.next());
        } ary[i][j] = Double.parseDouble(sc.next()) ary[i][j] ary[i] ary i j Double.parseDouble(sc.next()) Double.parseDouble Double sc.next() sc.next sc for (int i = 0; i < n -1; i++) {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      } int i = 0; int i = 0; i 0 i < n -1 i n -1 n 1 i++ i++ i {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      } {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      } for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        } int k = 1; int k = 1; k 1 k < n-i k n-i n i k++ k++ k {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        } {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        } sum = 0 sum 0 for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          } {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          } sum += Math.pow((ary[i][j]-ary[i+k][j]),2) sum Math.pow((ary[i][j]-ary[i+k][j]),2) Math.pow Math (ary[i][j]-ary[i+k][j]) ary[i][j] ary[i] ary i j ary[i+k][j] ary[i+k] ary i+k i k j 2 if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          } Math.sqrt(sum) % 1 == 0 Math.sqrt(sum) % 1 Math.sqrt(sum) Math.sqrt Math sum 1 0 {
            ans += 1;
          } ans += 1 ans 1 System.out.print(ans) System.out.print System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      int ans = 0;
      double sum = 0;
      
      double[][] ary = new double[n][d];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      }
      
      for (int i = 0; i < n -1; i++) {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      }
      System.out.print(ans);
    }
} public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      int ans = 0;
      double sum = 0;
      
      double[][] ary = new double[n][d];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      }
      
      for (int i = 0; i < n -1; i++) {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      }
      System.out.print(ans);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      int ans = 0;
      double sum = 0;
      
      double[][] ary = new double[n][d];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
          ary[i][j] = Double.parseDouble(sc.next());
        }
      }
      
      for (int i = 0; i < n -1; i++) {
        for (int k = 1;k < n-i;k++) {
          sum = 0;
          for (int j = 0; j < d; j++) {
            sum += Math.pow((ary[i][j]-ary[i+k][j]),2);
          }
          if (Math.sqrt(sum) % 1 == 0) {
            ans += 1;
          }
        }
      }
      System.out.print(ans);
    }
}

