human
Recently, Petya learned about a new game "Slay the Dragon". As the name suggests, the player will have to fight with dragons. To defeat a dragon, you have to kill it and defend your castle. To do this, the player has a squad of n heroes, the strength of the i-th hero is equal to a_i.

According to the rules of the game, exactly one hero should go kill the dragon, all the others will defend the castle. If the dragon's defense is equal to x, then you have to send a hero with a strength of at least x to kill it. If the dragon's attack power is y, then the total strength of the heroes defending the castle should be at least y.

The player can increase the strength of any hero by 1 for one gold coin. This operation can be done any number of times.

There are m dragons in the game, the i-th of them has defense equal to x_i and attack power equal to y_i. Petya was wondering what is the minimum number of coins he needs to spend to defeat the i-th dragon.

Note that the task is solved independently for each dragon (improvements are not saved).

Input

The first line contains a single integer n (2 ≤ n ≤ 2 ⋅ 10^5) — number of heroes.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^{12}), where a_i is the strength of the i-th hero.

The third line contains a single integer m (1 ≤ m ≤ 2 ⋅ 10^5) — the number of dragons.

The next m lines contain two integers each, x_i and y_i (1 ≤ x_i ≤ 10^{12}.
1 ≤ y_i ≤ 10^{18}) — defense and attack power of the i-th dragon.

Output

Print m lines, i-th of which contains a single integer — the minimum number of coins that should be spent to defeat the i-th dragon.

Example

Input

4
3 6 2 3
5
3 12
7 9
4 14
1 10
8 7

Output

1
2
4
0
2

Note

To defeat the first dragon, you can increase the strength of the third hero by 1, then the strength of the heroes will be equal to [3, 6, 3, 3]. To kill the dragon, you can choose the first hero.

To defeat the second dragon, you can increase the forces of the second and third heroes by 1, then the strength of the heroes will...
assistant
#Here is Python code to print m lines, i-th of which contains a single integer — the minimum number of coins that should be spent to defeat the i-th dragon.

import sys
import os
from math import ceil, floor, sqrt, gcd, factorial, log, log2
from io import BytesIO, IOBase
from collections import Counter
from itertools import permutations, combinations
from bisect import bisect
from functools import reduce

inf=int(10e9)
BUFSIZE = 8192

inp = lambda: int(input())
mp = lambda: map(int, input().split())
lst = lambda: list(map(int, input().split()))

def main():
    n=inp()
    a=lst()
    a.sort()
    s=sum(a)
    m=inp()
    l=[]
    for i in range(m):
        x,y=mp()
        c=0
        c1=0
        if x>=a[-1]:
            c+=(x-a[-1])
            if s-a[-1]<y:
                c+=y-(s-a[-1])
            print(c)
        else:
            j=bisect(a, x)
            if (s-a[j-1])<y:
                c+=y-(s-a[j-1])
            if a[j-1]<x:
                c+=x-a[j-1]
            if (s-a[j])<y:
                c1+=y-(s-a[j])

            print(min(c,c1))
                    


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
           ...