# Alien Chef

A new programming Problem…..

//http://www.codechef.com/problems/DOWNLOAD

/*

The aliens living in outer space are very advanced in technology, intelligence and everything, except one, and that is Cooking. Each year they spend millions of dollars in research, to crack famous recipes prepared by humans.

Recently they came to know about Khana-Academy, a non-profit organization streaming free cooking lesson videos on earth. There are N recipes, numbered 1 to N, and the video of the ith recipe is live in the time interval [Si, Ei]. An alien can visit earth but can not survive for more than just a small moment (earth is so advanced in pollution). An alien visits the earth at an integer time t and instantly downloads the complete video of all the lessons that are live at that moment of time t and leaves earth immediately. You are given the visiting times of a small group of K aliens. Find the number of different recipes aliens can learn by watching the downloaded videos. Not just one group of aliens, there are Q such groups, so you have to find the answer for each of these Q groups.

Input

The first line has an integer N. Each of the following N lines has two integers Si Ei. The next line has an integer Q, the number of groups. Each of the following Q lines has information of a group of aliens. The first integer is K, the number of aliens in that group, followed by K integers in the same line, the integer visiting times t of the aliens.

1 ≤ N ≤ 100000 (105)

1 ≤ Q ≤ 5000 (5 103)

1 ≤ K ≤ 20

1 ≤ Si, Ei, t ≤ 1000000000 (109)

Si < Ei

Output

For each of the Q groups, output the number of different recipes that group of aliens can learn by watching the downloaded videos.

Example

Input:

4

1 4

3 10

2 6

5 8

3

1 5

2 2 6

3 1 10 9

Output:

3

4

2

Explanation:

Given videos of 4 recipes in the following closed intervals.

1. [ 1 , 4 ]

2. [ 3 , 10 ]

3. [ 2 , 6 ]

4. [ 5 , 8 ]

In the first query, only one alien arrives at t = 5 and can download 3 recipes 2, 3, 4.

In the second query, two aliens arrive at t = 2 and 6. They can learn all the 4 recipes.

In the third query, three aliens arrive at t = 1, 10 and 9. They can learn only two recipes, 1 and 2.

*/**import java.util.*;****import java.lang.*;****/*public class Array****{**** int num[] = new int[20];**** **** **

}***/****public class AlienChefs****{**** static int aaa[] = new int[100000];**** static int end ;**** //leng = 1;**** static int start ;**** public static void main(String [] args)**** {**** **** Scanner sc = new Scanner(System.in);**** int n = sc.nextInt();**** if((0**

**{****int a[] = new int[2*n];****int add = 10;****for(int i = 0 ; i<(2*n) ; ++i)****{****//System.out.println(“Inside”);****a[i] = sc.nextInt();****if( (0**

**{****if((i%2) == 1 )****{****//System.out.println(“Inside”);****if((a[i-1] > a[i]))****System.exit(0);****}****}****else****System.exit(0);****}****int groups = sc.nextInt();****//System.out.println(“********************”);****//int address[] = new int[groups];****for(int i = 0 ; i< groups; ++i)****{****int count = 0 ;****int alen = 0 ;****int times = sc.nextInt();****for(int j =0 ;j**

**{****alen = sc.nextInt();****if((0**

**{****//System.out.println(alen);****count = count+ cc(a , alen);**

}}

**}****start = end – start;****start = start +end + add ;****end = start;****aaa[start] = 1000;****System.out.println(count);****}****}****}****static int cc(int a [] , int val)****{****int count = 0 ;****for(int i = 0 ; i< a.length; i++)****{ //static int a;****int abc =0;****if((a[i] <= val)&& (val <= a[i+1] ))****{****//System.out.println(“***************************************”);****abc = check(aaa , i);****if( abc == 0)****{****++count;****}****}****++i;****}****//System.out.println(“Count Returned :”+count);****return count;****}****static int check(int qw [], int i)****{****//System.out.println(“Check Function is called “);****//System.out.println(start+”:”+end);****//System.out.println(“i = “+i);****for(int j = start ; j<=end ; j++)****{****if(qw[j] == i)****return 1;****}****qw[end] = i;****//System.out.println(qw[end]+” :::::::Value Added”);****++end;****return 0;****}****}**