import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] p = new int[n][d];
    for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    }
    int count = 0;
    for(int i=0; i<n; ++i) {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    }
    System.out.println(count);
  }
  
  private static boolean f(int[] p,int[] p2,int n) {
    int sum = 0;
    for(int i=0; i<n; ++i) 
      sum += (p[i]-p2[i]) * (p[i]-p2[i]);
    return Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum)<0.001;
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] p = new int[n][d];
    for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    }
    int count = 0;
    for(int i=0; i<n; ++i) {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    }
    System.out.println(count);
  }
  
  private static boolean f(int[] p,int[] p2,int n) {
    int sum = 0;
    for(int i=0; i<n; ++i) 
      sum += (p[i]-p2[i]) * (p[i]-p2[i]);
    return Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum)<0.001;
  }
} Main public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] p = new int[n][d];
    for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    }
    int count = 0;
    for(int i=0; i<n; ++i) {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    }
    System.out.println(count);
  } main {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] p = new int[n][d];
    for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    }
    int count = 0;
    for(int i=0; i<n; ++i) {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    }
    System.out.println(count);
  } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) String[] str = in.readLine().split(" "); str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int n = Integer.parseInt(str[0]); n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int d = Integer.parseInt(str[1]); d Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 int[][] p = new int[n][d]; p new int[n][d] n d for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    } {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    } str = in.readLine().split(" ") str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      } int j=0; int j=0; j 0 j<d j d j++ j++ j {
        p[i][j] = Integer.parseInt(str[j]);
      } {
        p[i][j] = Integer.parseInt(str[j]);
      } p[i][j] = Integer.parseInt(str[j]) p[i][j] p[i] p i j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j int count = 0; count 0 for(int i=0; i<n; ++i) {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    } int i=0; int i=0; i 0 i<n i n ++i ++i i {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    } {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    } for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      } int j=i+1; int j=i+1; j i+1 i 1 j<n j n ++j ++j j {
        if(f(p[i],p[j],d))
          ++count;
      } {
        if(f(p[i],p[j],d))
          ++count;
      } if(f(p[i],p[j],d))
          ++count; f(p[i],p[j],d) f p[i] p i p[j] p j d ++count count System.out.println(count) System.out.println System.out System System.out count String[] args args private static boolean f(int[] p,int[] p2,int n) {
    int sum = 0;
    for(int i=0; i<n; ++i) 
      sum += (p[i]-p2[i]) * (p[i]-p2[i]);
    return Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum)<0.001;
  } f {
    int sum = 0;
    for(int i=0; i<n; ++i) 
      sum += (p[i]-p2[i]) * (p[i]-p2[i]);
    return Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum)<0.001;
  } int sum = 0; sum 0 for(int i=0; i<n; ++i) 
      sum += (p[i]-p2[i]) * (p[i]-p2[i]); int i=0; int i=0; i 0 i<n i n ++i ++i i sum += (p[i]-p2[i]) * (p[i]-p2[i]); sum += (p[i]-p2[i]) * (p[i]-p2[i]) sum (p[i]-p2[i]) * (p[i]-p2[i]) (p[i]-p2[i]) p[i] p i p2[i] p2 i (p[i]-p2[i]) p[i] p i p2[i] p2 i return Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum)<0.001; Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum)<0.001 Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum) Math.abs Math Math.pow((int)Math.sqrt(sum),2)-sum Math.pow((int)Math.sqrt(sum),2) Math.pow Math (int)Math.sqrt(sum) Math.sqrt Math sum 2 sum 0.001 int[] p p int[] p2 p2 int n n public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] p = new int[n][d];
    for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    }
    int count = 0;
    for(int i=0; i<n; ++i) {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    }
    System.out.println(count);
  }
  
  private static boolean f(int[] p,int[] p2,int n) {
    int sum = 0;
    for(int i=0; i<n; ++i) 
      sum += (p[i]-p2[i]) * (p[i]-p2[i]);
    return Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum)<0.001;
  }
} public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] p = new int[n][d];
    for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    }
    int count = 0;
    for(int i=0; i<n; ++i) {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    }
    System.out.println(count);
  }
  
  private static boolean f(int[] p,int[] p2,int n) {
    int sum = 0;
    for(int i=0; i<n; ++i) 
      sum += (p[i]-p2[i]) * (p[i]-p2[i]);
    return Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum)<0.001;
  }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[][] p = new int[n][d];
    for(int i=0; i<n; i++) {
      str = in.readLine().split(" ");
      for(int j=0; j<d; j++) {
        p[i][j] = Integer.parseInt(str[j]);
      }
    }
    int count = 0;
    for(int i=0; i<n; ++i) {
      for(int j=i+1; j<n; ++j) {
        if(f(p[i],p[j],d))
          ++count;
      }
    }
    System.out.println(count);
  }
  
  private static boolean f(int[] p,int[] p2,int n) {
    int sum = 0;
    for(int i=0; i<n; ++i) 
      sum += (p[i]-p2[i]) * (p[i]-p2[i]);
    return Math.abs(Math.pow((int)Math.sqrt(sum),2)-sum)<0.001;
  }
}