import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        Integer d = scanner.nextInt();
        
        int result = 0;
        List<List<Integer>> points = new ArrayList<List<Integer>>();
        
        for(int k = 0 ; k < n ; k++) {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        }
        
        
        for(int f = 0; f < n-1 ; f++) {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        }
        System.out.println(result);
    }
    
    static boolean hasIntDist(List<Integer> p1, List<Integer>p2) {
      int sum = 0;
      for(int a = 0 ; a < p1.size();a++) {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      }
      
      return isSquare(sum);
    }
    static boolean isSquare(int num) {
      double root = Math.sqrt(num);
      
      int castedRoot = (int) (root / 1.0);
      return (castedRoot *castedRoot) == (num) ;
    }
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        Integer d = scanner.nextInt();
        
        int result = 0;
        List<List<Integer>> points = new ArrayList<List<Integer>>();
        
        for(int k = 0 ; k < n ; k++) {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        }
        
        
        for(int f = 0; f < n-1 ; f++) {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        }
        System.out.println(result);
    }
    
    static boolean hasIntDist(List<Integer> p1, List<Integer>p2) {
      int sum = 0;
      for(int a = 0 ; a < p1.size();a++) {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      }
      
      return isSquare(sum);
    }
    static boolean isSquare(int num) {
      double root = Math.sqrt(num);
      
      int castedRoot = (int) (root / 1.0);
      return (castedRoot *castedRoot) == (num) ;
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        Integer d = scanner.nextInt();
        
        int result = 0;
        List<List<Integer>> points = new ArrayList<List<Integer>>();
        
        for(int k = 0 ; k < n ; k++) {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        }
        
        
        for(int f = 0; f < n-1 ; f++) {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        }
        System.out.println(result);
    } main {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        Integer d = scanner.nextInt();
        
        int result = 0;
        List<List<Integer>> points = new ArrayList<List<Integer>>();
        
        for(int k = 0 ; k < n ; k++) {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        }
        
        
        for(int f = 0; f < n-1 ; f++) {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        }
        System.out.println(result);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Integer n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner Integer d = scanner.nextInt(); d scanner.nextInt() scanner.nextInt scanner int result = 0; result 0 List<List<Integer>> points = new ArrayList<List<Integer>>(); points new ArrayList<List<Integer>>() for(int k = 0 ; k < n ; k++) {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        } int k = 0 ; int k = 0 ; k 0 k < n k n k++ k++ k {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        } {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        } List<Integer> point = new ArrayList<Integer>(); point new ArrayList<Integer>() for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          } int j = 0 ; int j = 0 ; j 0 j < d j d j++ j++ j {
            point.add(scanner.nextInt());
          } {
            point.add(scanner.nextInt());
          } point.add(scanner.nextInt()) point.add point scanner.nextInt() scanner.nextInt scanner points.add(point) points.add points point for(int f = 0; f < n-1 ; f++) {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        } int f = 0; int f = 0; f 0 f < n-1 f n-1 n 1 f++ f++ f {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        } {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        } for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          } int s = f + 1; int s = f + 1; s f + 1 f 1 s< n s n s++ s++ s {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          } {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          } if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            } hasIntDist(points.get(f),points.get(s)) hasIntDist points.get(f) points.get points f points.get(s) points.get points s {
               result++;
            } result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args static boolean hasIntDist(List<Integer> p1, List<Integer>p2) {
      int sum = 0;
      for(int a = 0 ; a < p1.size();a++) {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      }
      
      return isSquare(sum);
    } hasIntDist {
      int sum = 0;
      for(int a = 0 ; a < p1.size();a++) {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      }
      
      return isSquare(sum);
    } int sum = 0; sum 0 for(int a = 0 ; a < p1.size();a++) {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      } int a = 0 ; int a = 0 ; a 0 a < p1.size() a p1.size() p1.size p1 a++ a++ a {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      } {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      } sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a)) sum (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a)) (p1.get(a) - p2.get(a)) p1.get(a) p1.get p1 a p2.get(a) p2.get p2 a (p1.get(a) - p2.get(a)) p1.get(a) p1.get p1 a p2.get(a) p2.get p2 a return isSquare(sum); isSquare(sum) isSquare sum List<Integer> p1 p1 List<Integer>p2 p2 static boolean isSquare(int num) {
      double root = Math.sqrt(num);
      
      int castedRoot = (int) (root / 1.0);
      return (castedRoot *castedRoot) == (num) ;
    } isSquare {
      double root = Math.sqrt(num);
      
      int castedRoot = (int) (root / 1.0);
      return (castedRoot *castedRoot) == (num) ;
    } double root = Math.sqrt(num); root Math.sqrt(num) Math.sqrt Math num int castedRoot = (int) (root / 1.0); castedRoot (int) (root / 1.0) root 1.0 return (castedRoot *castedRoot) == (num) ; (castedRoot *castedRoot) == (num) (castedRoot *castedRoot) castedRoot castedRoot (num) int num num public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        Integer d = scanner.nextInt();
        
        int result = 0;
        List<List<Integer>> points = new ArrayList<List<Integer>>();
        
        for(int k = 0 ; k < n ; k++) {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        }
        
        
        for(int f = 0; f < n-1 ; f++) {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        }
        System.out.println(result);
    }
    
    static boolean hasIntDist(List<Integer> p1, List<Integer>p2) {
      int sum = 0;
      for(int a = 0 ; a < p1.size();a++) {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      }
      
      return isSquare(sum);
    }
    static boolean isSquare(int num) {
      double root = Math.sqrt(num);
      
      int castedRoot = (int) (root / 1.0);
      return (castedRoot *castedRoot) == (num) ;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        Integer d = scanner.nextInt();
        
        int result = 0;
        List<List<Integer>> points = new ArrayList<List<Integer>>();
        
        for(int k = 0 ; k < n ; k++) {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        }
        
        
        for(int f = 0; f < n-1 ; f++) {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        }
        System.out.println(result);
    }
    
    static boolean hasIntDist(List<Integer> p1, List<Integer>p2) {
      int sum = 0;
      for(int a = 0 ; a < p1.size();a++) {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      }
      
      return isSquare(sum);
    }
    static boolean isSquare(int num) {
      double root = Math.sqrt(num);
      
      int castedRoot = (int) (root / 1.0);
      return (castedRoot *castedRoot) == (num) ;
    }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        Integer d = scanner.nextInt();
        
        int result = 0;
        List<List<Integer>> points = new ArrayList<List<Integer>>();
        
        for(int k = 0 ; k < n ; k++) {
          List<Integer> point = new ArrayList<Integer>();
          for(int j = 0 ; j < d; j++) {
            point.add(scanner.nextInt());
          }
          points.add(point);
        }
        
        
        for(int f = 0; f < n-1 ; f++) {
          for(int s = f + 1; s< n ;s++) {
            if(hasIntDist(points.get(f),points.get(s))) {
               result++;
            }
          }
        }
        System.out.println(result);
    }
    
    static boolean hasIntDist(List<Integer> p1, List<Integer>p2) {
      int sum = 0;
      for(int a = 0 ; a < p1.size();a++) {
        sum += (p1.get(a) - p2.get(a)) * (p1.get(a) - p2.get(a));
      }
      
      return isSquare(sum);
    }
    static boolean isSquare(int num) {
      double root = Math.sqrt(num);
      
      int castedRoot = (int) (root / 1.0);
      return (castedRoot *castedRoot) == (num) ;
    }
}