import java.io.*;

/**
 * Created by Ayushi on 07/07/2019.
 */

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int d = Integer.parseInt(temp[1]);
        int[][] p = new int[n][d];
        for (int i = 0; i < n; i++) {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        }
        r.close();

        double x, y, z;
        int ans = 0;
        for (int k = 0; k < n; k++) {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        }

        System.out.println(ans);
    }
} import java.io.*; io.* java public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int d = Integer.parseInt(temp[1]);
        int[][] p = new int[n][d];
        for (int i = 0; i < n; i++) {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        }
        r.close();

        double x, y, z;
        int ans = 0;
        for (int k = 0; k < n; k++) {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        }

        System.out.println(ans);
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int d = Integer.parseInt(temp[1]);
        int[][] p = new int[n][d];
        for (int i = 0; i < n; i++) {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        }
        r.close();

        double x, y, z;
        int ans = 0;
        for (int k = 0; k < n; k++) {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        }

        System.out.println(ans);
    } main {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int d = Integer.parseInt(temp[1]);
        int[][] p = new int[n][d];
        for (int i = 0; i < n; i++) {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        }
        r.close();

        double x, y, z;
        int ans = 0;
        for (int k = 0; k < n; k++) {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        }

        System.out.println(ans);
    } BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); r new BufferedReader(new InputStreamReader(System.in)) String[] temp = r.readLine().split(" "); temp r.readLine().split(" ") r.readLine().split r.readLine() r.readLine r " " int n = Integer.parseInt(temp[0]); n Integer.parseInt(temp[0]) Integer.parseInt Integer temp[0] temp 0 int d = Integer.parseInt(temp[1]); d Integer.parseInt(temp[1]) Integer.parseInt Integer temp[1] temp 1 int[][] p = new int[n][d]; p new int[n][d] n d for (int i = 0; i < n; i++) {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        } {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        } temp = r.readLine().split(" ") temp r.readLine().split(" ") r.readLine().split r.readLine() r.readLine r " " for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                p[i][j] = Integer.parseInt(temp[j]);
            } {
                p[i][j] = Integer.parseInt(temp[j]);
            } p[i][j] = Integer.parseInt(temp[j]) p[i][j] p[i] p i j Integer.parseInt(temp[j]) Integer.parseInt Integer temp[j] temp j r.close() r.close r double x x y y z; z int ans = 0; ans 0 for (int k = 0; k < n; k++) {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        } int k = 0; int k = 0; k 0 k < n k n k++ k++ k {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        } {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        } for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            } int l = k+1; int l = k+1; l k+1 k 1 l < n l n l++ l++ l {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            } {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            } y = 0 y 0 for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                } int m = 0; int m = 0; m 0 m < d m d m++ m++ m {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                } {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                } x = p[k][m] - p[l][m] x p[k][m] - p[l][m] p[k][m] p[k] p k m p[l][m] p[l] p l m y += x*x y x*x x x z = Math.sqrt(y) z Math.sqrt(y) Math.sqrt Math y if (z % 1 == 0) ans++; z % 1 == 0 z % 1 z 1 0 ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int d = Integer.parseInt(temp[1]);
        int[][] p = new int[n][d];
        for (int i = 0; i < n; i++) {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        }
        r.close();

        double x, y, z;
        int ans = 0;
        for (int k = 0; k < n; k++) {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        }

        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int d = Integer.parseInt(temp[1]);
        int[][] p = new int[n][d];
        for (int i = 0; i < n; i++) {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        }
        r.close();

        double x, y, z;
        int ans = 0;
        for (int k = 0; k < n; k++) {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        }

        System.out.println(ans);
    }
} Main
import java.io.*;

/**
 * Created by Ayushi on 07/07/2019.
 */

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        int d = Integer.parseInt(temp[1]);
        int[][] p = new int[n][d];
        for (int i = 0; i < n; i++) {
            temp = r.readLine().split(" ");
            for (int j = 0; j < d; j++) {
                p[i][j] = Integer.parseInt(temp[j]);
            }
        }
        r.close();

        double x, y, z;
        int ans = 0;
        for (int k = 0; k < n; k++) {
            for (int l = k+1; l < n; l++) {
                y = 0;
                for (int m = 0; m < d; m++) {
                    x = p[k][m] - p[l][m];
                    y += x*x;
                }
                z = Math.sqrt(y);
                if (z % 1 == 0) ans++;
            }
        }

        System.out.println(ans);
    }
}
