void fft( num *a, num *res ) {
  forn(i, maxn)
    res[rev[i]] = a[i];
  for (int k = 1, log = maxlog - 1; k < maxn; k *= 2, log--) {
    num x(1, 0), root(2 * M_PI / (maxn >> log));
    forn(i, maxn)
      a[i] = res[i & ~k] + res[i | k] * x, x = x * root;
    copy(a, a + maxn, res);
  }
}