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

// Задача "Голова на плечах"
// 10-ая Интернет-олимпиада сезона 2006-2007, базовый уровень
// Автор задачи: Максим Буздалов, buzdalov@rain.ifmo.ru
// Автор решения: Максим Буздалов, buzdalov@rain.ifmo.ru

public class headand_mb {
    static class Hair {
        double start, finish;

        Hair(String line) {
            StringTokenizer st = new StringTokenizer(line);
            double xs = Double.parseDouble(st.nextToken());
            double ys = Double.parseDouble(st.nextToken());
            
            double xe = finish = Double.parseDouble(st.nextToken());

            start = Math.atan2(ys, xs);
            if (start > Math.PI / 2) {
                start -= Math.PI * 2;
            }
        }
    }

    static class StartComparator implements Comparator<Hair> {
        public int compare(Hair a, Hair b) {
            if (a.start < b.start) return -1;
            if (a.start > b.start) return 1;
            return 0; //не бывает
        }
    }

    static class FinishComparator implements Comparator<Hair> {
        public int compare(Hair a, Hair b) {
            if (a.finish < b.finish) return -1;
            if (a.finish > b.finish) return 1;
            return 0; //не бывает
        }
    }

    static long count;

    static Hair[] hair, temp;

    static Comparator<Hair> c = new FinishComparator();

    static void mergeSort(int s, int e) {  
        if (s >= e) return;
        int m = (s + e) / 2;

        mergeSort(s, m);
        mergeSort(m + 1, e);

        int i = s, j = m + 1, k = s;
        while (k <= e) {
            if (i > m) {
                count += Math.abs(j - k);
                temp[k++] = hair[j++];
            } else if (j > e) {
                count += Math.abs(i - k);
                temp[k++] = hair[i++];
            } else if (c.compare(hair[i], hair[j]) < 0) {
                count += Math.abs(i - k);
                temp[k++] = hair[i++];
            } else {
                count += Math.abs(j - k);
                temp[k++] = hair[j++];
            }
        }

        for (i = s; i <= e; i++) {
            hair[i] = temp[i];
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader("headand.in"));
        PrintWriter out = new PrintWriter("headand.out");

        in.readLine();
        int N = Integer.parseInt(in.readLine());

        hair = new Hair[N];
        temp = new Hair[N];
        for (int i = 0; i < N; i++) {
            hair[i] = new Hair(in.readLine());
        }

        Arrays.sort(hair, new StartComparator());
        count = 0;
        mergeSort(0, N - 1);

        out.println(count / 2);
        out.close();
        in.close();
    }
}