description: Three little pigs from all over the world are meeting for a convention! Every minute, a triple of 3 new pigs arrives on the convention floor. After the n-th minute, the convention ends.
  
  The big bad wolf has learned about this convention, and he has an attack plan. At some minute in the convention, he will arrive and eat exactly x pigs. Then he will get away.
  
  The wolf wants Gregor to help him figure out the number of possible attack plans that involve eating exactly x pigs for various values of x (1 ≤ x ≤ 3n). Two attack plans are considered different, if they occur at different times or if the sets of little pigs to eat are different.
  
  Note that all queries are independent, that is, the wolf does not eat the little pigs, he only makes plans!
  
  Input
  
  The first line of input contains two integers n and q (1 ≤ n ≤ 10^6, 1 ≤ q ≤ 2⋅ 10^5), the number of minutes the convention lasts and the number of queries the wolf asks.
  
  Each of the next q lines contains a single integer x_i (1 ≤ x_i ≤ 3n), the number of pigs the wolf will eat in the i-th query.
  
  Output
  
  You should print q lines, with line i representing the number of attack plans if the wolf wants to eat x_i pigs. Since each query answer can be large, output each answer modulo 10^9+7.
  
  Examples
  
  Input
  
  
  2 3
  1
  5
  6
  
  
  Output
  
  
  9
  6
  1
  
  
  Input
  
  
  5 4
  2
  4
  6
  8
  
  
  Output
  
  
  225
  2001
  6014
  6939
  
  Note
  
  In the example test, n=2. Thus, there are 3 pigs at minute 1, and 6 pigs at minute 2. There are three queries: x=1, x=5, and x=6.
  
  If the wolf wants to eat 1 pig, he can do so in 3+6=9 possible attack plans, depending on whether he arrives at minute 1 or 2.
  
  If the wolf wants to eat 5 pigs, the wolf cannot arrive at minute 1, since there aren't enough pigs at that time. Therefore, the wolf has to arrive at minute 2, and there are 6 possible attack plans.
  
  If the wolf wants to eat 6 pigs, his only plan is to arrive at the end of the convention and devour everybody.
  
  Remember to output your answers modulo 10^9+7!
solution: #include <bits/stdc++.h>
  using namespace std;
  const int kMod = 1e9 + 7;
  int Add(int x, int y) {
    x += y;
    if (x >= kMod) x -= kMod;
    if (x < 0) x += kMod;
    return x;
  }
  int fpow(int a, int n) {
    int res = 1;
    while (n) {
      if (n & 1) res = 1LL * res * a % kMod;
      n >>= 1, a = 1LL * a * a % kMod;
    }
    return res;
  }
  int Inv(int x) { return fpow(x, kMod - 2); }
  int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<vector<int>> dp(3, vector<int>(3 * n + 1));
    vector<int> fac(3 * n + 5), inv(3 * n + 5);
    fac[0] = 1;
    for (int i = 1; i <= 3 * n + 4; i++) fac[i] = 1LL * i * fac[i - 1] % kMod;
    inv[3 * n + 4] = Inv(fac[3 * n + 4]);
    for (int i = 3 * n + 3; i >= 0; i--)
      inv[i] = 1LL * (i + 1) * inv[i + 1] % kMod;
    auto C = [&](int n, int m) -> int {
      if (n < m) return 0;
      return int(1LL * fac[n] * inv[n - m] % kMod * inv[m] % kMod);
    };
    dp[0][0] = dp[1][0] = dp[2][0] = n;
    for (int i = 1; i <= 3 * n; i++) {
      dp[1][i] = 1LL *
                 Add(Add(C(3 * n + 1, i + 1), -dp[2][i - 1]),
                     -2LL * dp[1][i - 1] % kMod) *
                 Inv(3) % kMod;
      dp[2][i] = Add(dp[1][i], dp[1][i - 1]);
      dp[0][i] = Add(dp[2][i], dp[2][i - 1]);
    }
    while (q--) {
      int x;
      cin >> x;
      cout << dp[0][x] << '\n';
    }
    return 0;
  }
  