import java.util.Scanner;

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

    int count = 0;
    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++;
    System.out.println(count);
  }

  private static boolean isInteger(int[] array1, int[] array2, int d) {
    int sum = 0;
    for (int i = 0; i < d; i++) {
      sum += Math.pow(array1[i] - array2[i], 2);
    }
    int squareRoot = (int) Math.sqrt(sum);
    return squareRoot * squareRoot == sum;
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int[][] array = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      }
    }

    int count = 0;
    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++;
    System.out.println(count);
  }

  private static boolean isInteger(int[] array1, int[] array2, int d) {
    int sum = 0;
    for (int i = 0; i < d; i++) {
      sum += Math.pow(array1[i] - array2[i], 2);
    }
    int squareRoot = (int) Math.sqrt(sum);
    return squareRoot * squareRoot == sum;
  }
} Main public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int[][] array = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      }
    }

    int count = 0;
    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++;
    System.out.println(count);
  } main {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int[][] array = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      }
    }

    int count = 0;
    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++;
    System.out.println(count);
  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int D = scan.nextInt(); D scan.nextInt() scan.nextInt scan int[][] array = new int[N][D]; array new int[N][D] N D for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      }
    } {
      for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      }
    } for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
        array[i][j] = scan.nextInt();
      } {
        array[i][j] = scan.nextInt();
      } array[i][j] = scan.nextInt() array[i][j] array[i] array i j scan.nextInt() scan.nextInt scan int count = 0; count 0 for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++; 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++)
        if (isInteger(array[i], array[j], D))
          count++; for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++; int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j if (isInteger(array[i], array[j], D))
          count++; if (isInteger(array[i], array[j], D))
          count++; isInteger(array[i], array[j], D) isInteger array[i] array i array[j] array j D count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args private static boolean isInteger(int[] array1, int[] array2, int d) {
    int sum = 0;
    for (int i = 0; i < d; i++) {
      sum += Math.pow(array1[i] - array2[i], 2);
    }
    int squareRoot = (int) Math.sqrt(sum);
    return squareRoot * squareRoot == sum;
  } isInteger {
    int sum = 0;
    for (int i = 0; i < d; i++) {
      sum += Math.pow(array1[i] - array2[i], 2);
    }
    int squareRoot = (int) Math.sqrt(sum);
    return squareRoot * squareRoot == sum;
  } int sum = 0; sum 0 for (int i = 0; i < d; i++) {
      sum += Math.pow(array1[i] - array2[i], 2);
    } int i = 0; int i = 0; i 0 i < d i d i++ i++ i {
      sum += Math.pow(array1[i] - array2[i], 2);
    } {
      sum += Math.pow(array1[i] - array2[i], 2);
    } sum += Math.pow(array1[i] - array2[i], 2) sum Math.pow(array1[i] - array2[i], 2) Math.pow Math array1[i] - array2[i] array1[i] array1 i array2[i] array2 i 2 int squareRoot = (int) Math.sqrt(sum); squareRoot (int) Math.sqrt(sum) Math.sqrt Math sum return squareRoot * squareRoot == sum; squareRoot * squareRoot == sum squareRoot * squareRoot squareRoot squareRoot sum int[] array1 array1 int[] array2 array2 int d d public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int[][] array = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      }
    }

    int count = 0;
    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++;
    System.out.println(count);
  }

  private static boolean isInteger(int[] array1, int[] array2, int d) {
    int sum = 0;
    for (int i = 0; i < d; i++) {
      sum += Math.pow(array1[i] - array2[i], 2);
    }
    int squareRoot = (int) Math.sqrt(sum);
    return squareRoot * squareRoot == sum;
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int[][] array = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      }
    }

    int count = 0;
    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++;
    System.out.println(count);
  }

  private static boolean isInteger(int[] array1, int[] array2, int d) {
    int sum = 0;
    for (int i = 0; i < d; i++) {
      sum += Math.pow(array1[i] - array2[i], 2);
    }
    int squareRoot = (int) Math.sqrt(sum);
    return squareRoot * squareRoot == sum;
  }
} Main
import java.util.Scanner;

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

    int count = 0;
    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++;
    System.out.println(count);
  }

  private static boolean isInteger(int[] array1, int[] array2, int d) {
    int sum = 0;
    for (int i = 0; i < d; i++) {
      sum += Math.pow(array1[i] - array2[i], 2);
    }
    int squareRoot = (int) Math.sqrt(sum);
    return squareRoot * squareRoot == sum;
  }
}
