/* * 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. */ import java.util.*; /** * * @author tym17 */ public class samples { public static void main(String[] args) { long[] casy = new long[100000]; long[] hodn = new long[100000]; Scanner sc = new Scanner(System.in); String a, b; int n, i, j, k, c, sec; int pocet, prumer, p; double prumer2; long suma; while(sc.hasNextInt()) { n = sc.nextInt(); for(i=0; i < n; i++) { casy[i] = sc.nextLong(); hodn[i] = sc.nextLong(); } c = sc.nextInt(); for(i = 0; i < c; i++) { a = sc.next(); b = sc.next(); sec = sc.nextInt(); pocet = 0; if(b.equals("min")){ p = 0; prumer = Integer.MAX_VALUE; for(j = 0; j < n; j++) { for(k = j - 1; k >=0; k--) { if(casy[j]-casy[k]<=sec) { if(prumer > hodn[k]) { prumer = (int)hodn[k]; p++; } } else { break; } } if(a.equals("gt") && hodn[j] > prumer && p != 0) { pocet++; } else if(a.equals("lt") && hodn[j] < prumer && p != 0) { pocet++; } } } else if(b.equals("max")){ p = 0; prumer = Integer.MIN_VALUE; for(j = 0; j < n; j++) { for(k = j - 1; k >=0; k--) { if(casy[j]-casy[k]<=sec) { if(prumer < hodn[k]) { prumer = (int)hodn[k]; p++; } } else { break; } } if(a.equals("gt") && hodn[j] > prumer && p != 0) { pocet++; } else if(a.equals("lt") && hodn[j] < prumer && p != 0) { pocet++; } } } else { suma = 0; p = 0; for(j = 0; j < n; j++) { for(k = j - 1; k >=0; k--) { if(casy[j]-casy[k]<=sec) { suma += hodn[k]; p++; } else { break; } } if(p != 0) { prumer2 = suma/(double)p; if(a.equals("gt") && hodn[j] > prumer2) { pocet++; } else if(a.equals("lt") && hodn[j] < prumer2) { pocet++; } } } } System.out.println(pocet); } } } }