Language: C++

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
vvvvvvvvvvvvvvvvvvvvvvv#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;

int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];

int dp[S][N];
pair<int, int> val[22];
int sw[S2 + 5], sv[S2 + 5];

void calc(int u) {
  if (dp[u][0] != -1) return;
  int len = 0;
  int ver = u;
  while (ver) {
    val[len++] = {v[ver], w[ver]};
    ver /= 2;
  }
  int nmask = 1 << len;
  dp[u][0] = 0;
  sw[0] = sv[0] = 0;
  for (int mask = 1; mask < nmask; ++mask) {
    int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
    int ww = sw[bef] + val[p].second;
    int vv = sv[bef] + val[p].first;
    sw[mask] = ww;
    sv[mask] = vv;
    if (ww < N)
      dp[u][ww] = max(dp[u][ww], vv);
  }
  int now = 0;
  for (int i = 0; i < N; ++i) {
    now = max(dp[u][i], now);
    dp[u][i] = now;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  memset(dp, -1, sizeof dp);
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      calc(u);
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      calc(u);
      ans = dp[u][l];
      for (int mask = 1; mask < nmask; ++mask) {
        int p = __builtin_ctz(mask), bef = mask ^ (1 << p);
        int ww = sw[bef] + val[p].second;
        int vv = sv[bef] + val[p].first;
        sw[mask] = ww;
        sv[mask] = vv;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l-ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Compiler output:
a.cc:77:24: error: stray '#' in program
   77 | vvvvvvvvvvvvvvvvvvvvvvv#include <bits/stdc++.h>
      |                        ^
a.cc:77:1: error: 'vvvvvvvvvvvvvvvvvvvvvvv' does not name a type
   77 | vvvvvvvvvvvvvvvvvvvvvvv#include <bits/stdc++.h>
      | ^~~~~~~~~~~~~~~~~~~~~~~
a.cc:81:11: error: redefinition of 'const int N'
   81 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |           ^
a.cc:5:11: note: 'const int N' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |           ^
a.cc:81:24: error: redefinition of 'const int S'
   81 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                        ^
a.cc:5:24: note: 'const int S' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                        ^
a.cc:81:36: error: redefinition of 'const int S2'
   81 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                                    ^~
a.cc:5:36: note: 'const int S2' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                                    ^~
a.cc:83:5: error: redefinition of 'int n'
   83 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |     ^
a.cc:7:5: note: 'int n' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |     ^
a.cc:83:8: error: redefinition of 'int q'
   83 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |        ^
a.cc:7:8: note: 'int q' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |        ^
a.cc:83:11: error: redefinition of 'int v [262149]'
   83 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |           ^
a.cc:7:11: note: 'int v [262149]' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |           ^
a.cc:83:29: error: redefinition of 'int w [262149]'
   83 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |                             ^
a.cc:7:29: note: 'int w [262149]' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |                             ^
a.cc:85:5: error: redefinition of 'int dp [512][100005]'
   85 | int dp[S][N];
      |     ^~
a.cc:9:5: note: 'int dp [512][100005]' previously declared here
    9 | int dp[S][N];
      |     ^~
a.cc:86:16: error: redefinition of 'std::pair<int, int> val [22]'
   86 | pair<int, int> val[22];
      |                ^~~
a.cc:10:16: note: 'std::pair<int, int> val [22]' previously defined here
   10 | pair<int, int> val[22];
      |                ^~~
a.cc:87:5: error: redefinition of 'int sw [517]'
   87 | int sw[S2 + 5], sv[S2 + 5];
      |     ^~
a.cc:11:5: note: 'int sw [517]' previously declared here
   11 | int sw[S2 + 5], sv[S2 + 5];
      |     ^~
a.cc:87:17: error: redefinition of 'int sv [517]'
   87 | int sw[S2 + 5], sv[S2 + 5];
      |                 ^~
a.cc:11:17: note: 'int sv [517]' previously declared here
   11 | int sw[S2 + 5], sv[S2 + 5];
      |                 ^~
a.cc:89:6: error: redefinition of 'void calc(int)'
   89 | void calc(int u) {
      |      ^~~~
a.cc:13:6: note: 'void calc(int)' previously defined here
   13 | void calc(int u) {
      |      ^~~~
a.cc:116:5: error: redefinition of 'int main()'
  116 | int main() {
      |     ^~~~
a.cc:40:5: note: 'int main()' previously defined here
   40 | int main() {
      |     ^~~~
a.cc:157:11: error: redefinition of 'const int N'
  157 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |           ^
a.cc:5:11: note: 'const int N' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |           ^
a.cc:157:24: error: redefinition of 'const int S'
  157 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                        ^
a.cc:5:24: note: 'const int S' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                        ^
a.cc:157:36: error: redefinition of 'const int S2'
  157 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                                    ^~
a.cc:5:36: note: 'const int S2' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                                    ^~
a.cc:159:5: error: redefinition of 'int n'
  159 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |     ^
a.cc:7:5: note: 'int n' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |     ^
a.cc:159:8: error: redefinition of 'int q'
  159 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |        ^
a.cc:7:8: note: 'int q' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |        ^
a.cc:159:11: error: redefinition of 'int v [262149]'
  159 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |           ^
a.cc:7:11: note: 'int v [262149]' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |           ^
a.cc:159:29: error: redefinition of 'int w [262149]'
  159 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |                             ^
a.cc:7:29: note: 'int w [262149]' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |                             ^
a.cc:161:5: error: redefinition of 'int dp [512][100005]'
  161 | int dp[S][N];
      |     ^~
a.cc:9:5: note: 'int dp [512][100005]' previously declared here
    9 | int dp[S][N];
      |     ^~
a.cc:162:16: error: redefinition of 'std::pair<int, int> val [22]'
  162 | pair<int, int> val[22];
      |                ^~~
a.cc:10:16: note: 'std::pair<int, int> val [22]' previously defined here
   10 | pair<int, int> val[22];
      |                ^~~
a.cc:163:5: error: redefinition of 'int sw [517]'
  163 | int sw[S2 + 5], sv[S2 + 5];
      |     ^~
a.cc:11:5: note: 'int sw [517]' previously declared here
   11 | int sw[S2 + 5], sv[S2 + 5];
      |     ^~
a.cc:163:17: error: redefinition of 'int sv [517]'
  163 | int sw[S2 + 5], sv[S2 + 5];
      |                 ^~
a.cc:11:17: note: 'int sv [517]' previously declared here
   11 | int sw[S2 + 5], sv[S2 + 5];
      |                 ^~
a.cc:165:6: error: redefinition of 'void calc(int)'
  165 | void calc(int u) {
      |      ^~~~
a.cc:13:6: note: 'void calc(int)' previously defined here
   13 | void calc(int u) {
      |      ^~~~
a.cc:192:5: error: redefinition of 'int main()'
  192 | int main() {
      |     ^~~~
a.cc:40:5: note: 'int main()' previously defined here
   40 | int main() {
      |     ^~~~
a.cc:233:11: error: redefinition of 'const int N'
  233 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |           ^
a.cc:5:11: note: 'const int N' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |           ^
a.cc:233:24: error: redefinition of 'const int S'
  233 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                        ^
a.cc:5:24: note: 'const int S' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                        ^
a.cc:233:36: error: redefinition of 'const int S2'
  233 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                                    ^~
a.cc:5:36: note: 'const int S2' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |                                    ^~
a.cc:235:5: error: redefinition of 'int n'
  235 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |     ^
a.cc:7:5: note: 'int n' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |     ^
a.cc:235:8: error: redefinition of 'int q'
  235 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |        ^
a.cc:7:8: note: 'int q' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |        ^
a.cc:235:11: error: redefinition of 'int v [262149]'
  235 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |           ^
a.cc:7:11: note: 'int v [262149]' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |           ^
a.cc:235:29: error: redefinition of 'int w [262149]'
  235 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |                             ^
a.cc:7:29: note: 'int w [262149]' previously declared here
    7 | int n, q, v[(1 << 18) + 5], w[(1 << 18) + 5];
      |                             ^
a.cc:237:5: error: redefinition of 'int dp [512][100005]'
  237 | int dp[S][N];
      |     ^~
a.cc:9:5: note: 'int dp [512][100005]' previously declared here
    9 | int dp[S][N];
      |     ^~
a.cc:238:16: error: redefinition of 'std::pair<int, int> val [22]'
  238 | pair<int, int> val[22];
      |                ^~~
a.cc:10:16: note: 'std::pair<int, int> val [22]' previously defined here
   10 | pair<int, int> val[22];
      |                ^~~
a.cc:239:5: error: redefinition of 'int sw [517]'
  239 | int sw[S2 + 5], sv[S2 + 5];
      |     ^~
a.cc:11:5: note: 'int sw [517]' previously declared here
   11 | int sw[S2 + 5], sv[S2 + 5];
      |     ^~
a.cc:239:17: error: redefinition of 'int sv [517]'
  239 | int sw[S2 + 5], sv[S2 + 5];
      |                 ^~
a.cc:11:17: note: 'int sv [517]' previously declared here
   11 | int sw[S2 + 5], sv[S2 + 5];
      |                 ^~
a.cc:241:6: error: redefinition of 'void calc(int)'
  241 | void calc(int u) {
      |      ^~~~
a.cc:13:6: note: 'void calc(int)' previously defined here
   13 | void calc(int u) {
      |      ^~~~
a.cc:268:5: error: redefinition of 'int main()'
  268 | int main() {
      |     ^~~~
a.cc:40:5: note: 'int main()' previously defined here
   40 | int main() {
      |     ^~~~
a.cc:309:11: error: redefinition of 'const int N'
  309 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |           ^
a.cc:5:11: note: 'const int N' previously defined here
    5 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |           ^
a.cc:309:24: error: redefinition of 'const int S'
  309 | const int N = 1e5 + 5, S = 1 << 9, S2 = (1 << 18) / S;
      |