import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int D = in.nextInt();
        double[][] arr = new double[N][D];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        }

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        }

        System.out.println(ans);
    }

    private static boolean integerDistance(double[] a, double[] b) {
        // a & b guaranteed to have same length
        double dist = 0;
        for (int i = 0; i < a.length && i < b.length; ++i) {
            dist += sq(a[i] - b[i]);
        }
        return isInteger(dist);
    }

    private static boolean isInteger(double d) {
        double sqrt = Math.floor(Math.sqrt(d));
        return sqrt * sqrt == d;
    }

    private static double sq(double a) {
        return a * a;
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int D = in.nextInt();
        double[][] arr = new double[N][D];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        }

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        }

        System.out.println(ans);
    }

    private static boolean integerDistance(double[] a, double[] b) {
        // a & b guaranteed to have same length
        double dist = 0;
        for (int i = 0; i < a.length && i < b.length; ++i) {
            dist += sq(a[i] - b[i]);
        }
        return isInteger(dist);
    }

    private static boolean isInteger(double d) {
        double sqrt = Math.floor(Math.sqrt(d));
        return sqrt * sqrt == d;
    }

    private static double sq(double a) {
        return a * a;
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int D = in.nextInt();
        double[][] arr = new double[N][D];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        }

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        }

        System.out.println(ans);
    } main {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int D = in.nextInt();
        double[][] arr = new double[N][D];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        }

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        }

        System.out.println(ans);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in int D = in.nextInt(); D in.nextInt() in.nextInt in double[][] arr = new double[N][D]; arr new double[N][D] N D for (int i = 0; i < N; ++i) {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        } int i = 0; int i = 0; i 0 i < N i N ++i ++i i {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        } {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        } for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            } int j = 0; int j = 0; j 0 j < D j D ++j ++j j {
                arr[i][j] = in.nextDouble();
            } {
                arr[i][j] = in.nextDouble();
            } arr[i][j] = in.nextDouble() arr[i][j] arr[i] arr i j in.nextDouble() in.nextDouble in int ans = 0; ans 0 for (int i = 0; i < N; ++i) {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        } int i = 0; int i = 0; i 0 i < N i N ++i ++i i {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        } {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        } for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            } int j = 0; int j = 0; j 0 j < i j i ++j ++j j {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            } {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            } if (integerDistance(arr[i], arr[j])) 
                    ++ans; integerDistance(arr[i], arr[j]) integerDistance arr[i] arr i arr[j] arr j ++ans ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args private static boolean integerDistance(double[] a, double[] b) {
        // a & b guaranteed to have same length
        double dist = 0;
        for (int i = 0; i < a.length && i < b.length; ++i) {
            dist += sq(a[i] - b[i]);
        }
        return isInteger(dist);
    } integerDistance {
        // a & b guaranteed to have same length
        double dist = 0;
        for (int i = 0; i < a.length && i < b.length; ++i) {
            dist += sq(a[i] - b[i]);
        }
        return isInteger(dist);
    } double dist = 0; dist 0 for (int i = 0; i < a.length && i < b.length; ++i) {
            dist += sq(a[i] - b[i]);
        } int i = 0; int i = 0; i 0 i < a.length && i < b.length i < a.length i a.length a a.length i < b.length i b.length b b.length ++i ++i i {
            dist += sq(a[i] - b[i]);
        } {
            dist += sq(a[i] - b[i]);
        } dist += sq(a[i] - b[i]) dist sq(a[i] - b[i]) sq a[i] - b[i] a[i] a i b[i] b i return isInteger(dist); isInteger(dist) isInteger dist double[] a a double[] b b private static boolean isInteger(double d) {
        double sqrt = Math.floor(Math.sqrt(d));
        return sqrt * sqrt == d;
    } isInteger {
        double sqrt = Math.floor(Math.sqrt(d));
        return sqrt * sqrt == d;
    } double sqrt = Math.floor(Math.sqrt(d)); sqrt Math.floor(Math.sqrt(d)) Math.floor Math Math.sqrt(d) Math.sqrt Math d return sqrt * sqrt == d; sqrt * sqrt == d sqrt * sqrt sqrt sqrt d double d d private static double sq(double a) {
        return a * a;
    } sq {
        return a * a;
    } return a * a; a * a a a double a a public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int D = in.nextInt();
        double[][] arr = new double[N][D];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        }

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        }

        System.out.println(ans);
    }

    private static boolean integerDistance(double[] a, double[] b) {
        // a & b guaranteed to have same length
        double dist = 0;
        for (int i = 0; i < a.length && i < b.length; ++i) {
            dist += sq(a[i] - b[i]);
        }
        return isInteger(dist);
    }

    private static boolean isInteger(double d) {
        double sqrt = Math.floor(Math.sqrt(d));
        return sqrt * sqrt == d;
    }

    private static double sq(double a) {
        return a * a;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int D = in.nextInt();
        double[][] arr = new double[N][D];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        }

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        }

        System.out.println(ans);
    }

    private static boolean integerDistance(double[] a, double[] b) {
        // a & b guaranteed to have same length
        double dist = 0;
        for (int i = 0; i < a.length && i < b.length; ++i) {
            dist += sq(a[i] - b[i]);
        }
        return isInteger(dist);
    }

    private static boolean isInteger(double d) {
        double sqrt = Math.floor(Math.sqrt(d));
        return sqrt * sqrt == d;
    }

    private static double sq(double a) {
        return a * a;
    }
} Main
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int D = in.nextInt();
        double[][] arr = new double[N][D];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < D; ++j) {
                arr[i][j] = in.nextDouble();
            }
        }

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < i; ++j) {
                if (integerDistance(arr[i], arr[j])) 
                    ++ans;
            }
        }

        System.out.println(ans);
    }

    private static boolean integerDistance(double[] a, double[] b) {
        // a & b guaranteed to have same length
        double dist = 0;
        for (int i = 0; i < a.length && i < b.length; ++i) {
            dist += sq(a[i] - b[i]);
        }
        return isInteger(dist);
    }

    private static boolean isInteger(double d) {
        double sqrt = Math.floor(Math.sqrt(d));
        return sqrt * sqrt == d;
    }

    private static double sq(double a) {
        return a * a;
    }
}