import java.io.*;
import 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[][] X = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = scan.nextInt();
            }
        }
        double distance = 0.0;
        int count=0;
        for (int i = 0; i < N; i++) {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            }
        }
        System.out.println(count);
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] X = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = scan.nextInt();
            }
        }
        double distance = 0.0;
        int count=0;
        for (int i = 0; i < N; i++) {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] X = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = scan.nextInt();
            }
        }
        double distance = 0.0;
        int count=0;
        for (int i = 0; i < N; i++) {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            }
        }
        System.out.println(count);
    } main {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] X = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = scan.nextInt();
            }
        }
        double distance = 0.0;
        int count=0;
        for (int i = 0; i < N; i++) {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		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[][] X = new int[N][D]; X new int[N][D] N D for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[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++) {
                X[i][j] = scan.nextInt();
            }
        } {
            for (int j = 0; j < D; j++) {
                X[i][j] = scan.nextInt();
            }
        } for (int j = 0; j < D; j++) {
                X[i][j] = scan.nextInt();
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                X[i][j] = scan.nextInt();
            } {
                X[i][j] = scan.nextInt();
            } X[i][j] = scan.nextInt() X[i][j] X[i] X i j scan.nextInt() scan.nextInt scan double distance = 0.0; distance 0.0 int count=0; count 0 for (int i = 0; i < N; i++) {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            }
        } {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            }
        } for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            } int k = i+1; int k = i+1; k i+1 i 1 k < N k N k++ k++ k {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            } {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            } distance = 0.0 distance 0.0 for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                } {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                } distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0) distance Math.pow(Math.abs(X[i][j] - X[k][j]),2.0) Math.pow Math Math.abs(X[i][j] - X[k][j]) Math.abs Math X[i][j] - X[k][j] X[i][j] X[i] X i j X[k][j] X[k] X k j 2.0 int distanceT= (int)Math.sqrt(distance); distanceT (int)Math.sqrt(distance) Math.sqrt Math distance if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	} distance==Math.pow(distanceT,2.0) distance Math.pow(distanceT,2.0) Math.pow Math distanceT 2.0 {
               		count++;
            	} 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 scan = new Scanner(System.in);
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] X = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = scan.nextInt();
            }
        }
        double distance = 0.0;
        int count=0;
        for (int i = 0; i < N; i++) {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            }
        }
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int D = scan.nextInt();
        int[][] X = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = scan.nextInt();
            }
        }
        double distance = 0.0;
        int count=0;
        for (int i = 0; i < N; i++) {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            }
        }
        System.out.println(count);
    }
} Main
import java.io.*;
import 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[][] X = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = scan.nextInt();
            }
        }
        double distance = 0.0;
        int count=0;
        for (int i = 0; i < N; i++) {
          for (int k = i+1; k < N; k++) {
            distance = 0.0;
            for (int j = 0; j < D; j++) {
                    distance += Math.pow(Math.abs(X[i][j] - X[k][j]),2.0);
                }            
            	int distanceT= (int)Math.sqrt(distance);
            	if (distance==Math.pow(distanceT,2.0)) {
               		count++;
            	}
            }
        }
        System.out.println(count);
    }
}