prithivMLmods/Coder-Stat huggingface dataset:
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

// a[1001] = a[1001] + a[1000] + a[0001] + a[0000];

pair<int, int> marge(pair<int, int> a, pair<int, int> b) {
  int v[4] = {a.first, b.first, a.second, b.second};
  sort(v, v + 4);
  return {v[3], v[2]};
}

void FZT(int n, pair<int, int> *a) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (1 << n); j++)
      if (j & (1 << i))
        a[j] = marge(a[j], a[j ^ (1 << i)]); // 総和
}

int main() {
  int n, a[SIZE];
  pair<int, int> b[SIZE];

  scanf("%d", &n);
  for (int i = 0; i < (1 << n); i++) {
    scanf("%d", a + i);
    b[i] = {a[i], -1};
  }

  FZT(n, b);
  /*
  for(int i=0;i<(1<<n);i++)
    debug(b[i].first);
  */

  int ans = 0;

  for (int i = 1; i < (1 << n); i++) {
    ans = max(ans, b[i].first + b[i].second);
    printf("%d\n", ans);
  }

  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

// a[1001] = a[1001] + a[1000] + a[0001] + a[0000];

pair<int, int> marge(pair<int, int> a, pair<int, int> b) {
  int v[4] = {a.first, b.first, a.second, b.second};
  sort(v, v + 4);
  return {v[3], v[2]};
}

void FZT(int n, pair<int, int> *a) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (1 << n); j++)
      if (j & (1 << i))
        a[j] = marge(a[j], a[j ^ (1 << i)]); // 総和
}

int main() {
  int n, a[1 << 18];
  pair<int, int> b[1 << 18];

  scanf("%d", &n);
  for (int i = 0; i < (1 << n); i++) {
    scanf("%d", a + i);
    b[i] = {a[i], -1};
  }

  FZT(n, b);
  /*
  for(int i=0;i<(1<<n);i++)
    debug(b[i].first);
  */

  int ans = 0;

  for (int i = 1; i < (1 << n); i++) {
    ans = max(ans, b[i].first + b[i].second);
    printf("%d\n", ans);
  }

  return 0;
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define sqr(x) ((x) * (x))
typedef long long ll;
ll read() {
  ll x = 0;
  char f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void write(ll x) {
  if (x < 0)
    x = -x, putchar('-');
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(ll x) {
  write(x);
  puts("");
}
const int N = 201000;
using namespace std;
int n, s;
ll ans, a[N], b[N][4], c[5];
bool cmp(int x, int y) { return a[x] > a[y]; }
int main() {
  n = read();
  s = 1 << n;
  for (int i = 0; i < s; ++i)
    a[i] = read();
  a[s] = -1e11;
  b[0][0] = 0, b[0][1] = s;
  for (int i = 1; i < s; ++i) {
    b[i][0] = i, b[i][1] = s;
    for (int j = 0; j < n; ++j)
      if (i & 1 << j) {
        int k = i ^ (1 << j);
        c[0] = b[i][0], c[1] = b[i][1], c[2] = b[k][0], c[3] = b[k][1];
        sort(c, c + 4, cmp);
        b[i][0] = c[0];
        b[i][1] = c[0] == c[1] ? c[2] : c[1];
      }
  }
  for (int i = 1; i < s; ++i) {
    ans = max(ans, a[b[i][0]] + a[b[i][1]]);
    writeln(ans);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define sqr(x) ((x) * (x))
typedef long long ll;
ll read() {
  ll x = 0;
  char f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void write(ll x) {
  if (x < 0)
    x = -x, putchar('-');
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(ll x) {
  write(x);
  puts("");
}
const int N = 444444;
using namespace std;
int n, s;
ll ans, a[N], b[N][4], c[5];
bool cmp(int x, int y) { return a[x] > a[y]; }
int main() {
  n = read();
  s = 1 << n;
  for (int i = 0; i < s; ++i)
    a[i] = read();
  a[s] = -1e11;
  b[0][0] = 0, b[0][1] = s;
  for (int i = 1; i < s; ++i) {
    b[i][0] = i, b[i][1] = s;
    for (int j = 0; j < n; ++j)
      if (i & 1 << j) {
        int k = i ^ (1 << j);
        c[0] = b[i][0], c[1] = b[i][1], c[2] = b[k][0], c[3] = b[k][1];
        sort(c, c + 4, cmp);
        b[i][0] = c[0];
        b[i][1] = c[0] == c[1] ? c[2] : c[1];
      }
  }
  for (int i = 1; i < s; ++i) {
    ans = max(ans, a[b[i][0]] + a[b[i][1]]);
    writeln(ans);
  }
  return 0;
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const int maxn = 2e5 + 233;
int a[maxn], f[maxn], g[maxn];
void work(int k, int j) {
  //	if(k==3)cout<<"!"<<k<<" "<<j<<endl;
  if (g[j] > f[k]) {
    g[k] = f[k];
    f[k] = g[j];
  } else if (g[j] > g[k])
    g[k] = g[j];
  if (f[j] > f[k]) {
    g[k] = f[k];
    f[k] = f[j];
  } else if (f[j] > g[k])
    g[k] = f[j];
  return;
}
int main() {
  int n;
  cin >> n;
  int m = 1 << n;
  for (int i = 0; i < m; i++)
    scanf("%d", &a[i]);
  memset(f, 0, sizeof(f));
  memset(g, 0, sizeof(g));
  for (int i = 0; i < m; i++) {
    f[i] = a[i];
    g[i] = 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if ((j & (1 << i)) == 0) {
        int nj = j | (1 << i);
        work(nj, j);
      }
  for (int k = 1; k < m; k++) {
    ans = max(ans, f[k] + g[k]);
    printf("%d\n", ans);
  }
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const int maxn = 1 << 20;
int a[maxn], f[maxn], g[maxn];
void work(int k, int j) {
  //	if(k==3)cout<<"!"<<k<<" "<<j<<endl;
  if (g[j] > f[k]) {
    g[k] = f[k];
    f[k] = g[j];
  } else if (g[j] > g[k])
    g[k] = g[j];
  if (f[j] > f[k]) {
    g[k] = f[k];
    f[k] = f[j];
  } else if (f[j] > g[k])
    g[k] = f[j];
  return;
}
int main() {
  int n;
  cin >> n;
  int m = 1 << n;
  for (int i = 0; i < m; i++)
    scanf("%d", &a[i]);
  memset(f, 0, sizeof(f));
  memset(g, 0, sizeof(g));
  for (int i = 0; i < m; i++) {
    f[i] = a[i];
    g[i] = 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if ((j & (1 << i)) == 0) {
        int nj = j | (1 << i);
        work(nj, j);
      }
  for (int k = 1; k < m; k++) {
    ans = max(ans, f[k] + g[k]);
    printf("%d\n", ans);
  }
  return 0;
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define INF 0x3f3f3f3f3f
// #define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 20;

int n;
pii a[N];

pii merge(pii A, pii B) {
  if (A.fi < B.fi)
    swap(A, B);
  pii ans = A;
  if (B.fi > ans.se)
    ans.se = B.fi;
  return ans;
}

void run() {
  for (int i = 0; i < 1 << n; i++) {
    int x;
    cin >> x;
    a[i] = MP(x, -INF);
  }
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < 1 << n; i++) {
      if (i >> j & 1)
        a[i] = merge(a[i], a[i ^ (1 << j)]);
    }
  }
  int ans = 0;
  for (int i = 1; i < 1 << n; i++) {
    ans = max(ans, a[i].fi + a[i].se);
    cout << ans << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
#ifdef Local
  freopen("../input.in", "r", stdin);
  freopen("../output.out", "w", stdout);
#endif
  while (cin >> n)
    run();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define INF 0x3f3f3f3f3f
// #define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 20;

int n;
pii a[1 << N];

pii merge(pii A, pii B) {
  if (A.fi < B.fi)
    swap(A, B);
  pii ans = A;
  if (B.fi > ans.se)
    ans.se = B.fi;
  return ans;
}

void run() {
  for (int i = 0; i < 1 << n; i++) {
    int x;
    cin >> x;
    a[i] = MP(x, -INF);
  }
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < 1 << n; i++) {
      if (i >> j & 1)
        a[i] = merge(a[i], a[i ^ (1 << j)]);
    }
  }
  int ans = 0;
  for (int i = 1; i < 1 << n; i++) {
    ans = max(ans, a[i].fi + a[i].se);
    cout << ans << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
#ifdef Local
  freopen("../input.in", "r", stdin);
  freopen("../output.out", "w", stdout);
#endif
  while (cin >> n)
    run();
  return 0;
}
Problem p03313 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

struct pp {
  int a1, a2;
} mx1[300001], mx2[300001], c[4];

int a[300001], lastans = 0, n;

bool cmp(pp o, pp p) { return o.a1 < p.a1; }

void dfs(int o) {
  mx1[o].a1 = a[o];
  mx1[o].a2 = o;
  mx2[o].a1 = -1;
  mx2[o].a2 = -1;
  for (int i = 1; i <= n; i++)
    if (o & (1 << (i - 1))) {
      int yu = o ^ (1 << (i - 1));
      dfs(yu);
      c[0] = mx1[o];
      c[1] = mx2[o];
      c[2] = mx1[yu];
      c[3] = mx2[yu];
      sort(c, c + 4, cmp);
      mx1[o] = c[3];
      int j = 2;
      while ((j >= 0) && (c[j].a2 == c[3].a2))
        j--;
      mx2[o] = c[j];
    }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < 1 << n; i++)
    scanf("%d", &a[i]);
  dfs((1 << n) - 1);
  for (int i = 1; i < 1 << n; i++) {
    lastans = max(lastans, mx1[i].a1 + mx2[i].a1);
    printf("%d\n", lastans);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

struct pp {
  int a1, a2;
} mx1[300001], mx2[300001], c[4];

int a[300001], lastans = 0, n;

bool cmp(pp o, pp p) { return o.a1 < p.a1; }

void dfs(int o) {
  if (mx1[o].a1)
    return;
  mx1[o].a1 = a[o];
  mx1[o].a2 = o;
  mx2[o].a1 = -1;
  mx2[o].a2 = -1;
  for (int i = 1; i <= n; i++)
    if (o & (1 << (i - 1))) {
      int yu = o ^ (1 << (i - 1));
      dfs(yu);
      c[0] = mx1[o];
      c[1] = mx2[o];
      c[2] = mx1[yu];
      c[3] = mx2[yu];
      sort(c, c + 4, cmp);
      mx1[o] = c[3];
      int j = 2;
      while ((j >= 0) && (c[j].a2 == c[3].a2))
        j--;
      mx2[o] = c[j];
    }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < 1 << n; i++)
    scanf("%d", &a[i]);
  dfs((1 << n) - 1);
  for (int i = 1; i < 1 << n; i++) {
    lastans = max(lastans, mx1[i].a1 + mx2[i].a1);
    printf("%d\n", lastans);
  }
  return 0;
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

int const L = 18, N = L + 2, MASK = (1 << L) + 20, inf = 1e9 + 20;
int n, a[N];
int mx1[N][MASK], mx2[N][MASK];
int dp[N][MASK];

inline void add(int bit, int cur, int val) {
  mx2[bit][cur] = max(mx2[bit][cur], val);
  if (mx2[bit][cur] > mx1[bit][cur])
    swap(mx1[bit][cur], mx2[bit][cur]);
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  for (int i = 0; i < N; i++) {
    fill(mx1[i], mx1[i] + MASK, -inf);
    fill(mx2[i], mx2[i] + MASK, -inf);
  }

  cin >> n;

  for (int i = 0; i < (1 << n); i++) {
    cin >> a[i];
    int cur = 0;

    for (int bit = n - 1; bit >= 0; bit--) {
      cur += (i & (1 << bit));

      add(bit, cur, a[i]);
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j >= i; j--) {
      for (int mask = 0; mask < (1 << n); mask++) {
        if (mask & (1 << j)) {
          add(i, mask, mx1[i][mask ^ (1 << j)]);
          add(i, mask, mx2[i][mask ^ (1 << j)]);
        }
      }
    }
  }

  for (int k = 1; k < (1 << n); k++) {
    int cur = 0, ans = 0;

    for (int bit = n - 1; bit >= 0; bit--) {
      if (k & (1 << bit)) {
        ans = max(ans, mx1[bit][cur] + mx2[bit][cur]);
        cur += (1 << bit);
      }
    }

    ans = max(ans, mx1[0][cur] + mx2[0][cur]);

    cout << ans << '\n';
  }
}

Fixed submission:
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

int const L = 18, N = L + 2, MASK = (1 << L) + 20, inf = 1e9 + 20;
int n, a[MASK];
int mx1[N][MASK], mx2[N][MASK];
int dp[N][MASK];

inline void add(int bit, int cur, int val) {
  mx2[bit][cur] = max(mx2[bit][cur], val);
  if (mx2[bit][cur] > mx1[bit][cur])
    swap(mx1[bit][cur], mx2[bit][cur]);
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  for (int i = 0; i < N; i++) {
    fill(mx1[i], mx1[i] + MASK, -inf);
    fill(mx2[i], mx2[i] + MASK, -inf);
  }

  cin >> n;

  for (int i = 0; i < (1 << n); i++) {
    cin >> a[i];
    int cur = 0;

    for (int bit = n - 1; bit >= 0; bit--) {
      cur += (i & (1 << bit));

      add(bit, cur, a[i]);
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j >= i; j--) {
      for (int mask = 0; mask < (1 << n); mask++) {
        if (mask & (1 << j)) {
          add(i, mask, mx1[i][mask ^ (1 << j)]);
          add(i, mask, mx2[i][mask ^ (1 << j)]);
        }
      }
    }
  }

  for (int k = 1; k < (1 << n); k++) {
    int cur = 0, ans = 0;

    for (int bit = n - 1; bit >= 0; bit--) {
      if (k & (1 << bit)) {
        ans = max(ans, mx1[bit][cur] + mx2[bit][cur]);
        cur += (1 << bit);
      }
    }

    ans = max(ans, mx1[0][cur] + mx2[0][cur]);

    cout << ans << '\n';
  }
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define _ int v, int tl, int tr, int l, int r
#define tm (tl + tr >> 1)
#define sol v + v, tl, tm, l, r
#define sag v + v + 1, tm + 1, tr, l, r
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair<int, int> pp;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

pp mx[N], mx2[N];

signed main() {
  int n;
  cin >> n;
  for (int i = 0; i < (1 << n); i++) {
    scanf("%d", &mx[i].st);
    mx[i].nd = i;
  }

  for (int i = 0; i < (1 << n); i++)
    for (int j = 0; j < n; j++) {
      if ((i & (1 << j)) == 0) {
        int t = i | (1 << j);
        if (mx[i].nd != mx[t].nd) {
          if (mx[t].st < mx[i].st) {
            mx2[t] = mx[t];
            mx[t] = mx[i];
          } else
            mx2[t] = max(mx2[t], mx[i]);
        }
        mx2[t] = max(mx2[t], mx2[i]);
      }
    }

  int ans = 0;
  for (int i = 1; i < (1 << n); i++) {
    ans = max(ans, mx[i].st + mx2[i].st);
    printf("%d\n", ans);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define _ int v, int tl, int tr, int l, int r
#define tm (tl + tr >> 1)
#define sol v + v, tl, tm, l, r
#define sag v + v + 1, tm + 1, tr, l, r
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair<int, int> pp;
const int mod = 1e9 + 7;
const int N = 1 << 18;

pp mx[N], mx2[N];

signed main() {
  int n;
  cin >> n;
  for (int i = 0; i < (1 << n); i++) {
    scanf("%d", &mx[i].st);
    mx[i].nd = i;
  }

  for (int i = 0; i < (1 << n); i++)
    for (int j = 0; j < n; j++) {
      if ((i & (1 << j)) == 0) {
        int t = i | (1 << j);
        if (mx[i].nd != mx[t].nd) {
          if (mx[t].st < mx[i].st) {
            mx2[t] = mx[t];
            mx[t] = mx[i];
          } else
            mx2[t] = max(mx2[t], mx[i]);
        }
        mx2[t] = max(mx2[t], mx2[i]);
      }
    }

  int ans = 0;
  for (int i = 1; i < (1 << n); i++) {
    ans = max(ans, mx[i].st + mx2[i].st);
    printf("%d\n", ans);
  }
  return 0;
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 20;
int n, a[1 << maxn];

void merge(multiset<int> &a, multiset<int> b) {
  for (auto i : b)
    a.insert(i);
  while (a.size() > 2)
    a.erase(a.begin());
}

int sum(multiset<int> &a) {
  int res = 0;
  for (int i : a)
    res += i;
  return res;
}

multiset<int> f[1 << maxn];
int ans[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < (1 << n); i++) {
    cin >> a[i];
    f[i].insert(a[i]);
  }
  for (int k = 0; k < n; k++) {
    for (int mask = 0; mask < (1 << n); mask++) {
      if (mask & (1 << k))
        continue;
      merge(f[mask | 1 << k], f[mask]);
    }
  }
  for (int k = 1; k < (1 << n); k++) {
    ans[k] = sum(f[k]);
    ans[k] = max(ans[k], ans[k - 1]);
    cout << ans[k] << '\n';
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 20;
int n, a[1 << maxn];

void merge(multiset<int> &a, multiset<int> b) {
  for (auto i : b)
    a.insert(i);
  while (a.size() > 2)
    a.erase(a.begin());
}

int sum(multiset<int> &a) {
  int res = 0;
  for (int i : a)
    res += i;
  return res;
}

multiset<int> f[1 << maxn];
int ans[1 << maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < (1 << n); i++) {
    cin >> a[i];
    f[i].insert(a[i]);
  }
  for (int k = 0; k < n; k++) {
    for (int mask = 0; mask < (1 << n); mask++) {
      if (mask & (1 << k))
        continue;
      merge(f[mask | 1 << k], f[mask]);
    }
  }
  for (int k = 1; k < (1 << n); k++) {
    ans[k] = sum(f[k]);
    ans[k] = max(ans[k], ans[k - 1]);
    cout << ans[k] << '\n';
  }
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
const int MAXN = 2e5 + 5;
int arr[MAXN];
int dp[MAXN];
struct mx {
  int x = 0, y = 0;
  void update(int r) {
    if (r > x)
      swap(r, x);
    if (r > y)
      swap(r, y);
  }
};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  int n;
  cin >> n;
  for (int i = 0; i < (1 << n); i++)
    cin >> arr[i];
  for (int i = 1; i < (1 << n); i++) {
    dp[i] = dp[i - 1];
    mx temp;
    for (int sm = i; sm > 0; sm = i & (sm - 1))
      temp.update(arr[sm]);
    temp.update(arr[0]);
    dp[i] = max(dp[i], temp.x + temp.y);
    cout << dp[i] << '\n';
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
const int MAXN = 3e5 + 5;
int arr[MAXN];
int dp[MAXN];
struct mx {
  int x = 0, y = 0;
  void update(int r) {
    if (r > x)
      swap(r, x);
    if (r > y)
      swap(r, y);
  }
};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  int n;
  cin >> n;
  for (int i = 0; i < (1 << n); i++)
    cin >> arr[i];
  for (int i = 1; i < (1 << n); i++) {
    dp[i] = dp[i - 1];
    mx temp;
    for (int sm = i; sm > 0; sm = i & (sm - 1))
      temp.update(arr[sm]);
    temp.update(arr[0]);
    dp[i] = max(dp[i], temp.x + temp.y);
    cout << dp[i] << '\n';
  }
  return 0;
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
// const int MOD=998244353;
const long long LINF = 1e18;
#define int long long
// template
template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}
/*
各bitがKより小さいi,jでA_i,A_jが一番大きいものをdp[K][0],dp[K][1]とする(i,jが入ってる)
答えは当然dp[K][0]+dp[K][1]
dp[K][0]とdp[K][1]の求め方は、Kの立ってるbitを1つ外した数字Lに対してのdp[L][0]とdp[L][1]、A[K]を見ればいいので
40個くらい見ればいいはず
*/
int dp[1234567][3];
// main
signed main() {
  int N;
  cin >> N;
  std::vector<int> v(N);
  for (int i = 0; i < pow(2, N); i++)
    cin >> v[i];
  typedef pair<int, int> P;
  set<int> s;
  priority_queue<P> que;
  int mx = 0;
  dp[0][0] = 0;
  for (int i = 1; i < pow(2, N); i++) {
    s.clear();
    for (int j = 0; j < N; j++) {
      if ((i >> j) & 1) {
        s.insert(dp[i ^ (1 << j)][0]);
        if ((i ^ (1 << j)))
          s.insert(dp[i ^ (1 << j)][1]);
      }
    }
    // cout<<i<<" "<<s.size()<<endl;
    while (que.size())
      que.pop(); // que.clear();
    for (int p : s)
      que.push(P(v[p], p));
    que.push(P(v[i], i));
    dp[i][0] = que.top().second;
    que.pop();
    dp[i][1] = que.top().second;
    que.pop();
    // cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<"
    // "<<v[dp[i][0]]+v[dp[i][1]]<<endl;
    mx = max(mx, v[dp[i][0]] + v[dp[i][1]]);
    cout << mx << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
// const int MOD=998244353;
const long long LINF = 1e18;
#define int long long
// template
template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}
/*
各bitがKより小さいi,jでA_i,A_jが一番大きいものをdp[K][0],dp[K][1]とする(i,jが入ってる)
答えは当然dp[K][0]+dp[K][1]
dp[K][0]とdp[K][1]の求め方は、Kの立ってるbitを1つ外した数字Lに対してのdp[L][0]とdp[L][1]、A[K]を見ればいいので
40個くらい見ればいいはず
*/
int dp[1234567][3];
// main
signed main() {
  int N;
  cin >> N;
  std::vector<int> v(1234567);
  for (int i = 0; i < pow(2, N); i++)
    cin >> v[i];
  typedef pair<int, int> P;
  set<int> s;
  priority_queue<P> que;
  int mx = 0;
  dp[0][0] = 0;
  for (int i = 1; i < pow(2, N); i++) {
    s.clear();
    for (int j = 0; j < N; j++) {
      if ((i >> j) & 1) {
        s.insert(dp[i ^ (1 << j)][0]);
        if ((i ^ (1 << j)))
          s.insert(dp[i ^ (1 << j)][1]);
      }
    }
    // cout<<i<<" "<<s.size()<<endl;
    while (que.size())
      que.pop(); // que.clear();
    for (int p : s)
      que.push(P(v[p], p));
    que.push(P(v[i], i));
    dp[i][0] = que.top().second;
    que.pop();
    dp[i][1] = que.top().second;
    que.pop();
    // cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<"
    // "<<v[dp[i][0]]+v[dp[i][1]]<<endl;
    mx = max(mx, v[dp[i][0]] + v[dp[i][1]]);
    cout << mx << endl;
  }
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define ll long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N = 1e6 + 69, mod = 1e9 + 9;

ll n, m, x, y, a, b, c, d, t, k, ans = 1e18, cur, l, r;

ll A[N], dp[N], mx[N], mx1[N];

int main() {

  cin >> n;

  for (int i = 0; i < (1 << n); i++)
    cin >> A[i];

  if (A[0] < A[1]) {
    mx[1] = 1;
    mx1[1] = 0;
  } else {
    mx[1] = 0;
    mx1[1] = 1;
  }
  dp[1] = A[0] + A[1];
  mx[0] = A[0];

  for (int i = 2; i < (1 << n); i++) {

    mx[i] = i;

    for (int j = 0; j < n; j++)
      if ((i >> j) & 1) {
        // cout<< (i^(1<<j)) <<endl;
        if (A[mx[i]] <= A[mx[i ^ (1 << j)]] && mx[i] != mx[i ^ (1 << j)]) {
          mx1[i] = mx[i];
          mx[i] = mx[i ^ (1 << j)];
        } else if (A[mx1[i]] < A[mx[i ^ (1 << j)]] &&
                   mx1[i] != mx[i ^ (1 << j)] && mx[i] != mx[i ^ (1 << j)]) {
          mx1[i] = mx[i ^ (1 << j)];
        }
      }

    dp[i] = max(A[mx[i]] + A[mx1[i]], dp[i - 1]);
    // cout<<mx[i]<<" "<<mx1[i]<<" "<<i<<endl;
  }

  for (int i = 1; i < (1 << n); i++)
    cout << dp[i] << " ";
}


Fixed submission:
#include <bits/stdc++.h>

#define ll long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N = 1e6 + 69, mod = 1e9 + 9;

ll n, m, x, y, a, b, c, d, t, k, ans = 1e18, cur, l, r;

ll A[N], dp[N], mx[N], mx1[N];

int main() {

  cin >> n;

  for (int i = 0; i < (1 << n); i++)
    cin >> A[i];

  if (A[0] < A[1]) {
    mx[1] = 1;
    mx1[1] = 0;
  } else {
    mx[1] = 0;
    mx1[1] = 1;
  }
  dp[1] = A[0] + A[1];
  mx[0] = 0;

  for (int i = 2; i < (1 << n); i++) {

    mx[i] = i;

    for (int j = 0; j < n; j++)
      if ((i >> j) & 1) {
        // cout<< (i^(1<<j)) <<endl;
        if (A[mx[i]] <= A[mx[i ^ (1 << j)]] && mx[i] != mx[i ^ (1 << j)]) {
          mx1[i] = mx[i];
          mx[i] = mx[i ^ (1 << j)];
        } else if (A[mx1[i]] < A[mx[i ^ (1 << j)]] &&
                   mx1[i] != mx[i ^ (1 << j)] && mx[i] != mx[i ^ (1 << j)]) {
          mx1[i] = mx[i ^ (1 << j)];
        }
      }

    dp[i] = max(A[mx[i]] + A[mx1[i]], dp[i - 1]);
    // cout<<mx[i]<<" "<<mx1[i]<<" "<<i<<endl;
  }

  for (int i = 1; i < (1 << n); i++)
    cout << dp[i] << " ";
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <set>
#include <stdio.h>
#include <vector>
using namespace std;

#define MAXN 200007

int st;
int n;
int a[MAXN];

set<pair<int, int>> s[MAXN];

void input() {
  scanf("%d", &st);
  n = (1 << st);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
}

void solve() {
  int i, j, t;
  for (i = 0; i < n; i++) {
    s[i].insert(make_pair(a[i], i));
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < st; j++) {
      if ((i & (1 << j)) != 0) {
        continue;
      }
      for (auto it = s[i].begin(); it != s[i].end(); it++) {
        s[(i | (1 << j))].insert((*it));
      }
      while (s[(i | (1 << j))].size() > 2) {
        s[(i | (1 << j))].erase(s[(i | (1 << j))].begin());
      }
    }
  }
  int ans = 0;
  for (i = 1; i < n; i++) {
    int cur = 0;
    if (s[i].size() >= 2) {
      auto it = s[i].begin();
      cur = (*it).first;
      it++;
      cur += (*it).first;
    }
    if (ans < cur) {
      ans = cur;
    }
    printf("%d\n", ans);
  }
}

int main() {
  input();
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <stdio.h>
#include <vector>
using namespace std;

#define MAXN 500007

int st;
int n;
int a[MAXN];

set<pair<int, int>> s[MAXN];

void input() {
  scanf("%d", &st);
  n = (1 << st);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
}

void solve() {
  int i, j, t;
  for (i = 0; i < n; i++) {
    s[i].insert(make_pair(a[i], i));
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < st; j++) {
      if ((i & (1 << j)) != 0) {
        continue;
      }
      for (auto it = s[i].begin(); it != s[i].end(); it++) {
        s[(i | (1 << j))].insert((*it));
      }
      while (s[(i | (1 << j))].size() > 2) {
        s[(i | (1 << j))].erase(s[(i | (1 << j))].begin());
      }
    }
  }
  int ans = 0;
  for (i = 1; i < n; i++) {
    int cur = 0;
    if (s[i].size() >= 2) {
      auto it = s[i].begin();
      cur = (*it).first;
      it++;
      cur += (*it).first;
    }
    if (ans < cur) {
      ans = cur;
    }
    printf("%d\n", ans);
  }
}

int main() {
  input();
  solve();
  return 0;
}
Problem p03313 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int maxn = 2e5 + 5;
multiset<int, greater<int>> s[maxn];
int n, a[maxn];

int main() {
  if (fopen(taskname ".INP", "r")) {
    freopen(taskname ".INP", "r", stdin);
    freopen(taskname ".OUT", "w", stdout);
  }
  cin >> n;
  for (int i = 0; i < (1 << n); ++i) {
    cin >> a[i];
    s[i].insert(a[i]);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < (1 << n); ++j) {
      if ((j >> i) & 1) {
        for (int c : s[j ^ (1 << i)]) {
          s[j].insert(c);
        }
        while (s[j].size() > 2)
          s[j].erase(s[j].find(*s[j].rbegin()));
      }
    }
  }
  int res = 0;
  for (int i = 1; i < (1 << n); ++i) {
    res = max(res, *s[i].begin() + (*++s[i].begin()));
    cout << res << '\n';
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int maxn = 5e5 + 5;
multiset<int, greater<int>> s[maxn];
int n, a[maxn];

int main() {
  if (fopen(taskname ".INP", "r")) {
    freopen(taskname ".INP", "r", stdin);
    freopen(taskname ".OUT", "w", stdout);
  }
  cin >> n;
  for (int i = 0; i < (1 << n); ++i) {
    cin >> a[i];
    s[i].insert(a[i]);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < (1 << n); ++j) {
      if ((j >> i) & 1) {
        for (int c : s[j ^ (1 << i)]) {
          s[j].insert(c);
        }
        while (s[j].size() > 2)
          s[j].erase(s[j].find(*s[j].rbegin()));
      }
    }
  }
  int res = 0;
  for (int i = 1; i < (1 << n); ++i) {
    res = max(res, *s[i].begin() + (*++s[i].begin()));
    cout << res << '\n';
  }
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n = 0;
  string s;
  cin >> s;
  for (int i = 0; i < (int)s.size(); ++i) {
    if (s[i] == '+') {
      n += 1;
    } else {
      n -= 1;
    }
  }
  return n;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n = 0;
  string s;
  cin >> s;
  for (int i = 0; i < (int)s.size(); ++i) {
    if (s[i] == '+') {
      n += 1;
    } else {
      n -= 1;
    }
  }
  cout << n << endl;
  return 0;
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int count = 0;
  for (int i = 0; i < 4; i++) {
    if (s.at(i) == '+')
      count++;
    else
      count--;
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < 4; i++) {
    if (s.at(i) == '+')
      count++;
    else
      count--;
  }
  cout << count << endl;
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios::sync_with_stdio(0);
  cin.tie(0);

  string s;
  cin >> s;
  int num = 0;
  rep(i, 0, s.size()) {
    if (s[i] == '+')
      num++;
    else
      num--;
  }
  cout << num << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);

  string s;
  cin >> s;
  int num = 0;
  rep(i, 0, s.size()) {
    if (s[i] == '+')
      num++;
    else
      num--;
  }
  cout << num << endl;
  return 0;
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  string str;
  cin >> str;
  int cnt = 0;
  if (str[0] == '+')
    cnt++;
  if (str[1] == '-')
    cnt--;
  return cnt;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  string str;
  cin >> str;
  int cnt = 0;
  for (int i = 0; i < 4; i++) {
    if (str[i] == '+')
      cnt++;
    if (str[i] == '-')
      cnt--;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  int k = 0;
  for (int i = 0; i < 4; i++) {
    if (S.at(i) == '+') {
      k++;
    } else {
      k--;
    }
  }
  cout << k << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  cin >> S;
  int k = 0;
  for (int i = 0; i < 4; i++) {
    if (S.at(i) == '+') {
      k++;
    } else {
      k--;
    }
  }
  cout << k << endl;
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; s.size(); i++) {
    if (s[i] == '+') {
      cnt++;
    } else {
      cnt--;
    }
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+') {
      cnt++;
    } else {
      cnt--;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int x = 0;
  for (int i = 0; i < 4; i++) {
    if (s.at(i) == '+') {
      x++;
    } else {
      x--;
    }
  }
  cout << x << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int x = 0;
  for (int i = 0; i < 4; i++) {
    if (s.at(i) == '+') {
      x++;
    } else {
      x--;
    }
  }
  cout << x << endl;
}
Problem p03315 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x, y) memset(x, y, sizeof(x))
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
// ll fmod(ll x,ll y){ll
// res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;} ll gcd(ll
// x,ll y){return y==0?x:gcd(y,x%y);}
char s[maxn];
int main() {
  while (scanf("%s", s)) {
    int n = strlen(s);
    int da = 0;
    for (int i = 0; i < n; ++i)
      if (s[i] == '+')
        da++;
      else
        da--;
    cout << da << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x, y) memset(x, y, sizeof(x))
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
// ll fmod(ll x,ll y){ll
// res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;} ll gcd(ll
// x,ll y){return y==0?x:gcd(y,x%y);}
char s[maxn];
int main() {
  while (~scanf("%s", s)) {
    int n = strlen(s);
    int da = 0;
    for (int i = 0; i < n; ++i)
      if (s[i] == '+')
        da++;
      else
        da--;
    cout << da << endl;
  }
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    if (s.at(i) == '+')
      ans += 1;
    else
      ans -= 1;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    if (s.at(i) == '+')
      ans += 1;
    else
      ans -= 1;
  }
  cout << ans << endl;
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string a;
  ll b = 0;
  ll c = 0;
  for (ll i = 0; i < 4; i++) {
    if (a.at(i) == '+') {
      b += 1;
    } else {
      c += 1;
    }
  }
  cout << b - c << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string a;
  cin >> a;
  ll b = 0;
  ll c = 0;
  for (ll i = 0; i < 4; i++) {
    if (a.at(i) == '+') {
      b += 1;
    } else {
      c += 1;
    }
  }
  cout << b - c << endl;

  return 0;
}
Problem p03315 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int n = 1;
  while (true) {
    char tmp;
    cin >> tmp;
    n = (tmp == '+') ? n + 1 : n - 1;
  }
  cout << n << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  char tmp;
  int n = 0;
  while (cin >> tmp) {
    n = (tmp == '+') ? n + 1 : n - 1;
  }
  cout << n << endl;
}
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int res = 0;
  for (char c : s) {

    if (c == '+')
      res++;
    if (c == '-')
      res--;
  }
  return res;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int res = 0;
  for (char c : s) {

    if (c == '+')
      res++;
    if (c == '-')
      res--;
  }
  cout << res << endl;
  return 0;
}
Problem p03315 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <stdio.h>
#include <string.h>

using namespace std;

int N;

int main(void) {
  char c;

  while (scanf("%c", &c))
    c == '+' ? N++ : N--;

  printf("%d\n", N);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <string.h>

using namespace std;

int N;

int main(void) {
  char c;

  while (~scanf("%c ", &c))
    c == '+' ? N++ : N--;

  printf("%d\n", N);

  return 0;
}
Problem p03315 (Python)

Buggy submission (status: Runtime Error):
S = input()
S = sorted(S)
for i in range(len(S)):
    if S[i] == "-":
        ans = 2 * i - 4
        break
print(ans)


Fixed submission:
S = input()
S = sorted(S)
for i in range(len(S)):
    if S[i] == "-":
        ans = 2 * i - 4
        break
else:
    ans = 4
print(ans)
Problem p03315 (Python)

Buggy submission (status: Runtime Error):
S = list(input())
a = list.count("+")
b = list.count("-")
print(int(a) - int(b))


Fixed submission:
S = list(input())
a = S.count("+")
b = S.count("-")
print(int(a) - int(b))
Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>

int main() {
  char row[4];
  int number = 0;
  fgets(row, 5, stdin);
  for (int i = 0; i < 5; i++) {
    if (row[i] == '+') {
      number++;
    } else if (row[i] == '-') {
      number--;
    }
  }
  printf("%d\n", number);
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>

int main() {
  char row[4];
  int number = 0;
  scanf("%s", row);
  for (int i = 0; i < 5; i++) {
    if (row[i] == '+') {
      number++;
    } else if (row[i] == '-') {
      number--;
    }
  }
  printf("%d\n", number);
  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
// https://atcoder.jp/contests/abc101/tasks/abc101_b

#include <cmath>
#include <iostream>

bool solve(int n) {
  int sum = 0;
  for (int i = 1; i <= 9; i++) {
    auto a = n % 10;
    sum += a;
    n /= 10;
  }

  return (n % sum) == 0;
}

int main() {
  using namespace std;

  int n;
  cin >> n;

  cout << (solve(n) ? "Yes" : "No") << std::endl;

  return 0;
}


Fixed submission:
// https://atcoder.jp/contests/abc101/tasks/abc101_b

#include <cmath>
#include <iostream>

bool solve(int n) {
  int sum = 0;
  int a = n;
  while (a > 0) {
    sum += a % 10;
    a /= 10;
  }

  return (n % sum) == 0;
}

int main() {
  using namespace std;

  int n;
  cin >> n;

  cout << (solve(n) ? "Yes" : "No") << std::endl;

  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n;
  cin >> n;
  int n1 = n;
  int sn = 0;
  while (true) {
    if (n / 10 == 0) {
      sn += n;
      break;
    } else {
      sn += n % 10;
      sn /= 10;
    }
  }
  if (n1 % sn == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n;
  cin >> n;
  int n1 = n;
  int sn = 0;
  while (true) {
    if (n / 10 == 0) {
      sn += n;
      break;
    } else {
      sn += n % 10;
      n /= 10;
    }
  }
  if (n1 % sn == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int N, n;
  int S = 0, k = 0;

  cin >> N;
  n = N;
  while (n / 10 > 0) {
    n = n / 10;
    k++;
  }

  for (int i = k; 1 <= i; i--) {
    S = S + N % (int(pow(10, k)));
  }

  if (N % S == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int N, n;
  int S = 0, k = 0;

  cin >> N;
  n = N;
  while (n / 10 > 0) {
    n = n / 10;
    k++;
  }

  n = N;
  for (int i = k; 0 <= i; i--) {
    S = S + (n / int(pow(10, i)) % 10);
    n = n % (int(pow(10, i)));
  }

  if (N % S == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
/*Infor {{{
 ******************************************************
 * > File Name: b.cpp
 * > Author: samcompu
 * > Mail: admin@samcompu.com
 * > Created Time: 2018年06月23日 星期六 20时05分58秒
 ******************************************************
}}}*/

#include <bits/stdc++.h>

using namespace std;

/*Abbreviation {{{ */
#define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define ROF(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define cini(a) scanf("%d", &(a))
#define cinc(a) scanf("%c", &(a))
#define cinl(a) scanf("%lld", &(a))
#define cins(a) scanf("%s", (a))
#define cind(a) scanf("%lf", &(a))
#define coui(a) printf("%d", (a))
#define couc(a) printf("%c", (a))
#define coul(a) printf("%lld", (a))
#define cous(a) printf("%s", (a))
#define coud(a) printf("%f", (a))
#define SPA printf(" ")
#define LIN printf("\n")
#define ull unsigned long long int
/*}}}*/

/*Constant {{{*/
/*}}}*/

/*Class {{{*/
/*}}}*/

/*Variable {{{*/
/*}}}*/

/*Declare {{{*/
/*}}}*/

/*Main {{{*/
int main() {
  freopen("b.in", "r", stdin);
  freopen("b.out", "w", stdout);
  int N;
  cini(N);
  int t = N;
  int ans = 0;
  while (t) {
    ans += t % 10;
    t /= 10;
  }
  if (N % ans)
    cous("No"), LIN;
  else
    cous("Yes"), LIN;
  return 0;
}
/*}}}*/

/*Define {{{*/
/*}}}*/


Fixed submission:
/*Infor {{{
 ******************************************************
 * > File Name: b.cpp
 * > Author: samcompu
 * > Mail: admin@samcompu.com
 * > Created Time: 2018年06月23日 星期六 20时05分58秒
 ******************************************************
}}}*/

#include <bits/stdc++.h>

using namespace std;

/*Abbreviation {{{ */
#define FOR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define ROF(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define cini(a) scanf("%d", &(a))
#define cinc(a) scanf("%c", &(a))
#define cinl(a) scanf("%lld", &(a))
#define cins(a) scanf("%s", (a))
#define cind(a) scanf("%lf", &(a))
#define coui(a) printf("%d", (a))
#define couc(a) printf("%c", (a))
#define coul(a) printf("%lld", (a))
#define cous(a) printf("%s", (a))
#define coud(a) printf("%f", (a))
#define SPA printf(" ")
#define LIN printf("\n")
#define ull unsigned long long int
/*}}}*/

/*Constant {{{*/
/*}}}*/

/*Class {{{*/
/*}}}*/

/*Variable {{{*/
/*}}}*/

/*Declare {{{*/
/*}}}*/

/*Main {{{*/
int main() {
  int N;
  cini(N);
  int t = N;
  int ans = 0;
  while (t) {
    ans += t % 10;
    t /= 10;
  }
  if (N % ans)
    cous("No"), LIN;
  else
    cous("Yes"), LIN;
  return 0;
}
/*}}}*/

/*Define {{{*/
/*}}}*/
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(void) {
  long long n = 0, u;
  cin >> n;
  int sum = 0;
  u = n;
  for (int i = 0; i < 9; i++) {
    sum += u % 10;
    u /= 10;
  }
  if (n % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main(void) {
  long long n = 0, u;
  cin >> n;
  int sum = 0;
  u = n;
  for (int i = 0; i < 10; i++) {
    sum += u % 10;
    u /= 10;
  }
  if (n % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;

  int SN = 0, N_copy = N;
  while (N > 0) {
    SN += N_copy % 10;
    N_copy /= 10;
  }

  if (N % SN == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;

  int SN = 0, N_copy = N;
  while (N_copy > 0) {
    SN += N_copy % 10;
    N_copy /= 10;
  }

  if (N % SN == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int n;

int main() {
  int N = n, t = 0;
  while (N) {
    t += N % 10;
    N /= 10;
  }
  if (n % t == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int n;

int main() {
  cin >> n;
  int N = n, t = 0;
  while (N) {
    t += N % 10;
    N /= 10;
  }
  if (n % t == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  int sum = 0;
  int A = N;
  while (A > 0) {
    sum += A % 10;
    A /= 10;
  }
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  int sum = 0;
  int A = N;
  while (A > 0) {
    sum += A % 10;
    A /= 10;
  }
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int neko(int N) {
  int sum = 0;
  while (N == 0) {
    sum += N % 10;
    N /= 10;
  }
  return sum;
}

int main() {
  int x;
  cin >> x;
  if (x % neko(x) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int neko(int N) {
  int sum = 0;
  while (N != 0) {
    sum += N % 10;
    N /= 10;
  }
  return sum;
}

int main() {
  int x;
  cin >> x;
  if (x % neko(x) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}