## Favorite Numbers

View as PDF

Points: 5
Time limit: 0.6s
Java 1.0s
Python 2 3.0s
Python 3 3.0s
Turing 3.0s
Memory limit: 256M

Author:
Problem type

When asked what his Favorite Number is, Joey cannot respond! He likes a lot of numbers! In particular, he has a list of numbers that are his Favorite Numbers. Numbers might appear more than once on his list of Favorite Numbers, but that's okay, since it means that he really, really likes that number.

Joey is given numbers, but these numbers might not be one of his Favorite Numbers. For each number that he is given, he would like the smallest Favorite Number that is at least as large as the number he is given. He would also like to know how many times that Favorite Number appears in his list of Favorite Numbers.

#### Input Specification

The first line will contain : the size of Joey's list of Favorite Numbers.

The next line will contain space-separated integers: the numbers that are in Joey's list of Favorite Numbers, in no particular order.

The next line will contain : the amount of numbers Joey is given.

lines of input will follow. Each line will contain one integer: one number that Joey is given.

The absolute value of any integer will not exceed . It is guaranteed that no number given to Joey will exceed the largest number in his list.

#### Output Specification

On separate lines, for each number that Joey is given, output two space-separated integers: the smallest Favorite Number that is at least as large as the number given, and how many times it appears in Joey's list of Favorite Numbers.

#### Sample Input

10
-2 8 -100 19 -2 -2 8 -100 8 8
5
6
8
17
-1000
-10

#### Sample Output

8 4
8 4
19 1
-100 2
-2 3