import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();

    int[][] points = new int[n][d];
    int count = 0;

    for (int i = 0; i < n; ++i) {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      }
    }

    System.out.println(count);
  }
} import java.util.Scanner; Scanner 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[][] points = new int[n][d];
    int count = 0;

    for (int i = 0; i < n; ++i) {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++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[][] points = new int[n][d];
    int count = 0;

    for (int i = 0; i < n; ++i) {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      }
    }

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

    int[][] points = new int[n][d];
    int count = 0;

    for (int i = 0; i < n; ++i) {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++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[][] points = new int[n][d]; points new int[n][d] n d int count = 0; count 0 for (int i = 0; i < n; ++i) {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      }
    } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      }
    } {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      }
    } for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt(); int j = 0; int j = 0; j 0 j < d j d ++j ++j j points[i][j] = sc.nextInt(); points[i][j] = sc.nextInt() points[i][j] points[i] points i j sc.nextInt() sc.nextInt sc for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      } int j = 0; int j = 0; j 0 j < i j i ++j ++j j {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      } {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      } double dist = 0; dist 0 for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2); int k = 0; int k = 0; k 0 k < d k d ++k ++k k dist += Math.pow(points[i][k] - points[j][k], 2); dist += Math.pow(points[i][k] - points[j][k], 2) dist Math.pow(points[i][k] - points[j][k], 2) Math.pow Math points[i][k] - points[j][k] points[i][k] points[i] points i k points[j][k] points[j] points j k 2 dist = Math.sqrt(dist) dist Math.sqrt(dist) Math.sqrt Math dist if (Math.round(dist) == dist)
          ++count; Math.round(dist) == dist Math.round(dist) Math.round Math dist dist ++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[][] points = new int[n][d];
    int count = 0;

    for (int i = 0; i < n; ++i) {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++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[][] points = new int[n][d];
    int count = 0;

    for (int i = 0; i < n; ++i) {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      }
    }

    System.out.println(count);
  }
} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();

    int[][] points = new int[n][d];
    int count = 0;

    for (int i = 0; i < n; ++i) {

      for (int j = 0; j < d; ++j)
        points[i][j] = sc.nextInt();

      for (int j = 0; j < i; ++j) {
        double dist = 0;

        for (int k = 0; k < d; ++k)
          dist += Math.pow(points[i][k] - points[j][k], 2);

        dist = Math.sqrt(dist);
        if (Math.round(dist) == dist)
          ++count;
      }
    }

    System.out.println(count);
  }
}