import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoodDistance solver = new BGoodDistance();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoodDistance {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int x[][] = new int[n][d];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                }
            }
            int nb = 0;
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                }
            out.println(nb);
        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoodDistance solver = new BGoodDistance();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoodDistance {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int x[][] = new int[n][d];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                }
            }
            int nb = 0;
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                }
            out.println(nb);
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoodDistance solver = new BGoodDistance();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoodDistance solver = new BGoodDistance();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) BGoodDistance solver = new BGoodDistance(); solver new BGoodDistance() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class BGoodDistance {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int x[][] = new int[n][d];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                }
            }
            int nb = 0;
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                }
            out.println(nb);
        }

    } BGoodDistance public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int x[][] = new int[n][d];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                }
            }
            int nb = 0;
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                }
            out.println(nb);
        } solve {
            int n = in.nextInt();
            int d = in.nextInt();
            int x[][] = new int[n][d];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                }
            }
            int nb = 0;
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                }
            out.println(nb);
        } int n = in.nextInt(); n in.nextInt() in.nextInt in int d = in.nextInt(); d in.nextInt() in.nextInt in 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] = in.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] = in.nextInt();
                }
            } {
                for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                }
            } for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                    x[i][j] = in.nextInt();
                } {
                    x[i][j] = in.nextInt();
                } x[i][j] = in.nextInt() x[i][j] x[i] x i j in.nextInt() in.nextInt in int nb = 0; nb 0 for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                } int i = 0; int i = 0; i 0 i < n i n i++ i++ i for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                } for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                } {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                } long res = 0; res 0 for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    } {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    } res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) res (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k double result = Math.sqrt(res); result Math.sqrt(res) Math.sqrt Math res int res1 = (int) result; res1 (int) result if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++; Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001 Math.abs(result - res1) <= 0.000001 Math.abs(result - res1) Math.abs Math result - res1 result res1 0.000001 Math.abs(result - res1 - 1) <= 0.000001 Math.abs(result - res1 - 1) Math.abs Math result - res1 - 1 result - res1 - 1 result res1 1 0.000001 nb++ nb out.println(nb) out.println out nb int testNumber testNumber Scanner in in PrintWriter out out public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoodDistance solver = new BGoodDistance();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoodDistance {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int x[][] = new int[n][d];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                }
            }
            int nb = 0;
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                }
            out.println(nb);
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoodDistance solver = new BGoodDistance();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoodDistance {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int x[][] = new int[n][d];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                }
            }
            int nb = 0;
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                }
            out.println(nb);
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoodDistance solver = new BGoodDistance();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoodDistance {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int x[][] = new int[n][d];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < d; j++) {
                    x[i][j] = in.nextInt();
                }
            }
            int nb = 0;
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++) {
                    long res = 0;
                    for (int k = 0; k < d; k++) {
                        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                    }
                    double result = Math.sqrt(res);
                    int res1 = (int) result;
                    if (Math.abs(result - res1) <= 0.000001 || Math.abs(result - res1 - 1) <= 0.000001)
                        nb++;
                }
            out.println(nb);
        }

    }
}

