import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Set; import java.math.*; /* * 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 cteam071 */ public class Samples { public static BufferedReader in; private static int min(int first, int last, int[][] pole){ int daco = pole[first][1]; for (int i=first; i < last; i++){ if (pole[i][1]daco){ daco = pole[i][1]; } } return daco; } private static int avg(int first, int last, int[][] pole){ int sum = 0; for (int i=first; i < last; i++){ sum += pole[i][1]; } if (last==first) return 0; return sum/(last-first); } public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); String line; int samples; int conditions; while((line = in.readLine()) != null){ samples = Integer.parseInt(line); int[][] pole = new int[samples][2]; String[] sample; for (int i=0; i< samples; i++){ sample = in.readLine().split(" "); pole[i][0] = Integer.parseInt(sample[0]); pole[i][1] = Integer.parseInt(sample[1]); } conditions = Integer.parseInt(in.readLine()); String[][] pole2 = new String[conditions][3]; for (int i=0; i< conditions; i++){ sample = in.readLine().split(" "); pole2[i][0] = sample[0]; pole2[i][1] = sample[1]; pole2[i][2] = sample[2]; } for (int k = 0; k < conditions; k++) { int count = 0; int time = Integer.parseInt(pole2[k][2]); for (int i = 0; i < samples; i++) { for (int j = i - 1; j >= 0; j--) { int firstindex = 0; if (pole[i][0] - pole[j][0] > time) { firstindex = j+1; } else if (j == 0){ firstindex = 0; } else continue; int porovnavam = 0; if (pole2[k][1].equals("avg")){ porovnavam = avg(firstindex,i,pole); } else if (pole2[k][1].equals("min")){ porovnavam = min(firstindex,i,pole); } else if (pole2[k][1].equals("max")){ porovnavam = max(firstindex,i,pole); } else if (pole2[k][1].equals("max")){ porovnavam = max(firstindex,i,pole); } if (pole2[k][0].equals("gt") && pole[i][1] > porovnavam){ count++; } else if (pole2[k][0].equals("lt") && pole[i][1] < porovnavam){ count++; } break; } } System.out.println(count); } } } }