import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam056 */ public class Samples { public static void main(String[] args) { Scanner s = new Scanner(System.in); while(s.hasNextInt()) { int n = s.nextInt(); Sample[] pole = new Sample[n]; for (int i = 0; i < n; i++) { Sample a = new Sample(s.nextInt(), s.nextInt()); pole [i] = a; } int c = s.nextInt(); String[] R = new String[c]; String[] F = new String[c]; int[] L = new int[c]; s.nextLine(); for (int i = 0; i < c; i++) { String str = s.nextLine(); String[] strr= str.split(" "); R[i] = strr[0]; F[i] = strr[1]; L[i] = Integer.parseInt(strr[2]); } for (int i = 0; i < c; i++) { int last = 0; int count = 0; for (int j = 0; j < n; j++) { while (pole[j].getTime() - L[i] > pole[last].getTime()) { last++; } if (last == j) continue; double valuetotest = 0; switch (F[i]) { case "min": valuetotest = Integer.MAX_VALUE; for (int k = last; k < j; k++) { if (pole[k].getValue() < valuetotest) valuetotest = pole[k].getValue(); } break; case "max": valuetotest = Integer.MIN_VALUE; for (int k = last; k < j; k++) { if (pole[k].getValue() > valuetotest) valuetotest = pole[k].getValue(); } break; case "avg": int cnt = 0; int val = 0; for (int k = last; k < j; k++) { cnt++; val+=pole[k].getValue(); } valuetotest = val/cnt; break; } switch(R[i]) { case "gt": if(pole[j].getValue() > valuetotest) { count++; } break; case "lt": if(pole[j].getValue() < valuetotest) { count++; } break; } } System.out.println(count); } } } static class Sample { int time; int value; public Sample(int time, int value) { this.time = time; this.value = value; } public int getTime() { return time; } public int getValue() { return value; } } } /* 10 60 30 120 28 180 35 240 34 300 40 360 31 420 28 480 2 540 42 600 30 2 gt avg 7200 lt min 300 */