
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer d = Integer.parseInt(scanner.next());
        Integer[][] x = new Integer[n][d];

        for(int i = 0; i < n; i++) {
            for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            }
        }

        int count = 0;
        ArrayList<Integer> intList = new ArrayList<Integer>();
        for(int i =0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        }

        count = 0;
        for (int i = 0; i < intList.size(); i++) {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        }

        System.out.println(count);
    }
} import java.util.*; util.* java import java.lang.*; lang.* java import java.util.stream.*; stream.* java.util public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer d = Integer.parseInt(scanner.next());
        Integer[][] x = new Integer[n][d];

        for(int i = 0; i < n; i++) {
            for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            }
        }

        int count = 0;
        ArrayList<Integer> intList = new ArrayList<Integer>();
        for(int i =0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        }

        count = 0;
        for (int i = 0; i < intList.size(); i++) {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        }

        System.out.println(count);
    }
} Main public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer d = Integer.parseInt(scanner.next());
        Integer[][] x = new Integer[n][d];

        for(int i = 0; i < n; i++) {
            for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            }
        }

        int count = 0;
        ArrayList<Integer> intList = new ArrayList<Integer>();
        for(int i =0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        }

        count = 0;
        for (int i = 0; i < intList.size(); i++) {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        }

        System.out.println(count);
    } main {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer d = Integer.parseInt(scanner.next());
        Integer[][] x = new Integer[n][d];

        for(int i = 0; i < n; i++) {
            for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            }
        }

        int count = 0;
        ArrayList<Integer> intList = new ArrayList<Integer>();
        for(int i =0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        }

        count = 0;
        for (int i = 0; i < intList.size(); i++) {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        }

        System.out.println(count);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Integer n = Integer.parseInt(scanner.next()); n Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner Integer d = Integer.parseInt(scanner.next()); d Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner Integer[][] x = new Integer[n][d]; x new Integer[n][d] n d for(int i = 0; i < n; i++) {
            for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            }
        } 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] = Integer.parseInt(scanner.next());
            }
        } {
            for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            }
        } for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            } int j = 0; int j = 0; j 0 j <d j d j++ j++ j {
                x[i][j] = Integer.parseInt(scanner.next());
            } {
                x[i][j] = Integer.parseInt(scanner.next());
            } x[i][j] = Integer.parseInt(scanner.next()) x[i][j] x[i] x i j Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int count = 0; count 0 ArrayList<Integer> intList = new ArrayList<Integer>(); intList new ArrayList<Integer>() for(int i =0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        } int i =0; int i =0; i 0 i < n i n i++ i++ i {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        } {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        } for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            } int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            } {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            } int total = 0; total 0 for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                } {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                } total += (int) Math.pow(x[i][k] - x[j][k], 2) total (int) Math.pow(x[i][k] - x[j][k], 2) Math.pow Math x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k 2 intList.add(total) intList.add intList total count = 0 count 0 for (int i = 0; i < intList.size(); i++) {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        } int i = 0; int i = 0; i 0 i < intList.size() i intList.size() intList.size intList i++ i++ i {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        } {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        } if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            } (Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i))) (Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i)))) Math.sqrt(intList.get(i)) Math.sqrt Math intList.get(i) intList.get intList i Math.floor(Math.sqrt(intList.get(i))) Math.floor Math Math.sqrt(intList.get(i)) Math.sqrt Math intList.get(i) intList.get intList i !Double.isInfinite(Math.sqrt(intList.get(i))) Double.isInfinite(Math.sqrt(intList.get(i))) Double.isInfinite Double Math.sqrt(intList.get(i)) Math.sqrt Math intList.get(i) intList.get intList i {
                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 scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer d = Integer.parseInt(scanner.next());
        Integer[][] x = new Integer[n][d];

        for(int i = 0; i < n; i++) {
            for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            }
        }

        int count = 0;
        ArrayList<Integer> intList = new ArrayList<Integer>();
        for(int i =0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        }

        count = 0;
        for (int i = 0; i < intList.size(); i++) {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        }

        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer d = Integer.parseInt(scanner.next());
        Integer[][] x = new Integer[n][d];

        for(int i = 0; i < n; i++) {
            for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            }
        }

        int count = 0;
        ArrayList<Integer> intList = new ArrayList<Integer>();
        for(int i =0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        }

        count = 0;
        for (int i = 0; i < intList.size(); i++) {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        }

        System.out.println(count);
    }
} Main

import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer d = Integer.parseInt(scanner.next());
        Integer[][] x = new Integer[n][d];

        for(int i = 0; i < n; i++) {
            for(int j = 0; j <d; j++ ) {
                x[i][j] = Integer.parseInt(scanner.next());
            }
        }

        int count = 0;
        ArrayList<Integer> intList = new ArrayList<Integer>();
        for(int i =0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int total = 0;
                for(int k = 0; k < d; k++) {
                    total += (int) Math.pow(x[i][k] - x[j][k], 2);
                }
                intList.add(total);
            }
        }

        count = 0;
        for (int i = 0; i < intList.size(); i++) {
            if ((Math.sqrt(intList.get(i)) == Math.floor(Math.sqrt(intList.get(i))))
                    && !Double.isInfinite(Math.sqrt(intList.get(i)))) {
                count++;
            }
        }

        System.out.println(count);
    }
}