Emma and sum of products
Difficulty: Hard

Emma is really fond of integers and loves playing with them. Her friends were jealous, and to test her, one of them gave her a problem.  
Emma is given a list $A$ of $N$ integers and is asked a set of $Q$ queries. Each query is denoted by an integer $K$, for which you have to return the sum of product of all possible sublists having exactly $K$ elements.  
Emma has got stuck in this problem and you being her best friend have decided to help her write a code to solve it. Since the answers can be very large, print the answers modulo $100003$.

**Input Format**  
First line has an integer $N$, denoting the number of integers in list $A$. Next line contains $N$ space separated integers. The third line contains integer $Q$, and next $Q$ lines have a single integer $K$.

**Output Format**  
For each of the queries, print the corresponding answer in a new line.  

**NOTE** Sublist here refers to selecting $K$ elements from a list of $N$ elements. There will be $N \choose K$ ways to do that, it doesn't matter if two elements are same.

**Constraints**  
$1 \le N \le 3\times10^4$  
$1 \le A_i \le 10^5$  
$1 \le Q \le N$  
$1 \le K \le N$  

**Sample Input #00**  

    3
    1 2 3
    2
    1
    2

**Sample Output #00**  

    6
    11

**Sample Input #01**  

    3
    1 2 2
    1
    2

**Sample Output #01**  

    8

**Explanation**  

Sample #00:  
For $K=1$ possible sublists are $\{1\},\{2\},\{3\}$ so answer is $1+2+3 = 6$.  
For $K=2$ possible sublists are $\{1,2\},\{2,3\},\{3,1\}$ so answer is $(1\times2) + (2\times3) + (3\times1) = 2+6+3 = 11$.

Sample #01:  
For $K=2$ possible sublists are $\{1,2\},\{2,2\},\{2,1\}$ so answer is $(1\times 2) + (2\times2) + (2\times 1) = 2+4+2 = 8$.

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:
#
# Complete the 'solve' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
#  1. INTEGER_ARRAY A
#  2. INTEGER_ARRAY queries
#

def solve(A, queries):
    # Write your code here




Reference solution (C++):
###C++  
```cpp  
#include<iostream>
#include<vector>
#include<cmath>
#include<complex>
using namespace std;
#define PB push_back
const double PI = 4*atan(1);
typedef complex<double> base;
vector<base> omega;
long long FFT_N,mod=100003;
void init_fft(long long n)
{
  FFT_N  = n;
  omega.resize(n);
  double angle = 2 * PI / n;
  for(int i = 0; i < n; i++)
    omega[i] = base( cos(i * angle), sin(i * angle));
}
void fft (vector<base> & a)
{
  long long n = (long long) a.size();
  if (n == 1)  return;
  long long half = n >> 1;
  vector<base> even (half),  odd (half);
  for (int i=0, j=0; i<n; i+=2, ++j)
    {
      even[j] = a[i];
      odd[j] = a[i+1];
    }
  fft (even), fft (odd);
  for (int i=0, fact = FFT_N/n; i < half; ++i)
    {
      base twiddle =  odd[i] * omega[i * fact] ;
      a[i] =  even[i] + twiddle;
      a[i+half] = even[i] - twiddle;
    }
}
void multiply (const vector<long long> & a, const vector<long long> & b, vector<long long> & res)
{
  vector<base> fa (a.begin(), a.end()),  fb (b.begin(), b.end());
  long long n = 1;
  while (n < 2*max (a.size(), b.size()))  n <<= 1;
  fa.resize (n),  fb.resize (n);

  init_fft(n);
  fft (fa),  fft (fb);
  for (size_t i=0; i<n; ++i)
    fa[i] = conj( fa[i] * fb[i]);
  fft (fa);
  res.resize (n);
  for (size_t i=0; i<n; ++i)
    {
      res[i] = (long long) (fa[i].real() / n + 0.5);
      res[i]%=mod;
    }
}
int main()
{
  int t,n,i,p,l,k,q;
  long long x;
  vector<long long> inp,res;
  vector<vector<long long> > calc[20];
  cin>>n;
  p=0;l=n;
  for(i=0;i<n;i++)
    {
      inp.clear();
      cin>>x;
      inp.PB(1);
      inp.PB(x);
      calc[0].PB(inp);
    }
  while(l>1)
    {
      p++;
      for(i=0;i<l/2;i++)
        {
          calc[p].PB(res);
          multiply(calc[p-1][2*i],calc[p-1][2*i+1],calc[p][i]);
        }
      if(l%2)
        calc[p].PB(calc[p-1][l-1]);
      l=calc[p].size();
    }
  cin>>q;
  while(q--)
    {
      cin>>k;
      cout<<calc[p][0][k]<<endl;
    }
  return 0;
}
```