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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;

struct edge {
  int to;
  ll cost;
};
vector<vector<edge>> tree(100010);
vector<ll> depth(10010);

void dfs(int v, int p,
         ll d) { // vからの最短経路、現在地のいっこまえ、はじめからの距離
  depth[v] = d;
  for (auto &e : tree[v]) {
    if (e.to == p)
      continue;
    dfs(e.to, v, d + e.cost);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    tree[a].push_back({b, c});
    tree[b].push_back({a, c});
  }

  int q, k;
  cin >> q >> k;
  k--;

  dfs(k, -1, 0);
  rep(i, q) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << depth[x] + depth[y] << endl;
  }
}


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

struct edge {
  int to;
  ll cost;
};
vector<vector<edge>> tree(100010);
vector<ll> depth(100010);

void dfs(int v, int p,
         ll d) { // vからの最短経路、現在地のいっこまえ、はじめからの距離
  depth[v] = d;
  for (auto &e : tree[v]) {
    if (e.to == p)
      continue;
    dfs(e.to, v, d + e.cost);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    tree[a].push_back({b, c});
    tree[b].push_back({a, c});
  }

  int q, k;
  cin >> q >> k;
  k--;

  dfs(k, -1, 0);
  rep(i, q) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << depth[x] + depth[y] << endl;
  }
}
Problem p03634 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio> //SPFA
#include <cstdlib>
#include <cstring>
using namespace std;

const int MaxN = 10000;
typedef long long LL;
int n, m, all;
int pre[MaxN + 5], last[MaxN + 5], other[MaxN + 5], cost[MaxN + 5];
LL dis[MaxN + 5], seq[MaxN + 5];
bool Inque[MaxN + 5];

void Build(int x, int y, int w) {
  pre[++all] = last[x];
  last[x] = all;
  other[all] = y;
  cost[all] = w;
}

void Bfs(int s) {
  int head = 1, tail = 1, now, ed, dr;
  seq[tail] = s;
  for (int i = 1; i <= n; i++) {
    if (i == s)
      dis[i] = 0;
    else
      dis[i] = 1ll << 60;
  }
  Inque[s] = 1;
  while (head <= tail) {
    now = seq[head];
    ed = last[now];
    while (ed != -1) {
      dr = other[ed];
      if (dis[now] + cost[ed] < dis[dr]) {
        dis[dr] = dis[now] + cost[ed];
        if (!Inque[dr]) {
          Inque[dr] = 1;
          seq[++tail] = dr;
        }
      }
      ed = pre[ed];
    }
    Inque[now] = 0;
    head++;
  }
}

int main() {
  all = -1;
  memset(last, -1, sizeof(last));
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    Build(a, b, w);
    Build(b, a, w);
  }
  memset(seq, 0, sizeof(seq));
  memset(Inque, 0, sizeof(Inque));
  int q, k;
  scanf("%d%d", &q, &k);
  Bfs(k);
  for (int i = 1; i <= q; i++) {
    int h, j;
    scanf("%d %d", &h, &j);
    printf("%lld\n", dis[h] + dis[j]);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio> //SPFA
#include <cstdlib>
#include <cstring>
using namespace std;

const int MaxN = 1000000;
typedef long long LL;
int n, m, all;
int pre[MaxN + 5], last[MaxN + 5], other[MaxN + 5], cost[MaxN + 5];
LL dis[MaxN + 5], seq[MaxN + 5];
bool Inque[MaxN + 5];

void Build(int x, int y, int w) {
  pre[++all] = last[x];
  last[x] = all;
  other[all] = y;
  cost[all] = w;
}

void Bfs(int s) {
  int head = 1, tail = 1, now, ed, dr;
  seq[tail] = s;
  for (int i = 1; i <= n; i++) {
    if (i == s)
      dis[i] = 0;
    else
      dis[i] = 1ll << 60;
  }
  Inque[s] = 1;
  while (head <= tail) {
    now = seq[head];
    ed = last[now];
    while (ed != -1) {
      dr = other[ed];
      if (dis[now] + cost[ed] < dis[dr]) {
        dis[dr] = dis[now] + cost[ed];
        if (!Inque[dr]) {
          Inque[dr] = 1;
          seq[++tail] = dr;
        }
      }
      ed = pre[ed];
    }
    Inque[now] = 0;
    head++;
  }
}

int main() {
  all = -1;
  memset(last, -1, sizeof(last));
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    Build(a, b, w);
    Build(b, a, w);
  }
  memset(seq, 0, sizeof(seq));
  memset(Inque, 0, sizeof(Inque));
  int q, k;
  scanf("%d%d", &q, &k);
  Bfs(k);
  for (int i = 1; i <= q; i++) {
    int h, j;
    scanf("%d %d", &h, &j);
    printf("%lld\n", dis[h] + dis[j]);
  }
}
Problem p03634 (C++)

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

typedef long long ll;
typedef pair<ll, ll> P;

static const int MAX = 10010;
static const ll INF = 1e15;

ll d[MAX];

struct edge {
  int to, cost;
};

vector<edge> g[MAX];

void daijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + MAX, INF);
  que.push(P(0, s));
  d[s] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {

  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back(edge{b, c});
    g[b].push_back(edge{a, c});
  }
  int Q, K;
  cin >> Q >> K;
  K--;
  daijkstra(K);
  while (Q--) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << d[x] + d[y] << endl;
  }
}

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

typedef long long ll;
typedef pair<ll, ll> P;

static const int MAX = 100100;
static const ll INF = 1e15;

ll d[MAX];

struct edge {
  int to, cost;
};

vector<edge> g[MAX];

void daijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + MAX, INF);
  que.push(P(0, s));
  d[s] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {

  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back(edge{b, c});
    g[b].push_back(edge{a, c});
  }
  int Q, K;
  cin >> Q >> K;
  K--;
  daijkstra(K);
  while (Q--) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << d[x] + d[y] << endl;
  }
}
Problem p03634 (C++)

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

const long long INF = 1e15;

struct edge {
  int to, cost;
};

vector<long long> dp(10010, -1);
vector<edge> g[10010];

void solve(int u, int pa = -1) {
  for (auto e : g[u]) {
    int v = e.to;
    int c = e.cost;
    if (v == pa)
      continue;
    if (dp[v] != -1)
      continue;
    dp[v] = dp[u] + c;
    solve(v, u);
  }
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  int Q, K;
  cin >> Q >> K;
  K--;
  dp[K] = 0;
  solve(K);
  /*
  for(int i=0;i<N;i++){
      cout << dp[i] << " ";
  }
  */
  for (int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << dp[x] + dp[y] << endl;
  }
}

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

const long long INF = 1e15;

struct edge {
  int to, cost;
};

vector<long long> dp(100100, -1);
vector<edge> g[100100];

void solve(int u, int pa = -1) {
  for (auto e : g[u]) {
    int v = e.to;
    int c = e.cost;
    if (v == pa)
      continue;
    if (dp[v] != -1)
      continue;
    dp[v] = dp[u] + c;
    solve(v, u);
  }
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  int Q, K;
  cin >> Q >> K;
  K--;
  dp[K] = 0;
  solve(K);
  /*
  for(int i=0;i<N;i++){
      cout << dp[i] << " ";
  }
  */
  for (int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << dp[x] + dp[y] << endl;
  }
}
Problem p03634 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <map>
#include <set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100010
using namespace std;

// 木のデータ構造
vector<vector<int>> tree(10, vector<int>());

// 訪問済み検査配列
vector<bool> visit(MAX, false);

// 頂点Kから頂点iへの最短距離はdist[i]である
long long dist[MAX];

// 頂点間の距離（コスト）
map<set<int>, int> cost;

// 頂点nowからの距離がdである
void dfs(int now, long long d) {
  for (auto next : tree[now - 1]) {
    // 訪問済みなら次の頂点へ
    if (visit[next - 1] == true)
      continue;

    // nextを訪問済みにし，距離を計算
    visit[next - 1] = true;
    dist[next - 1] = d + cost[{now, next}];

    // 再帰的にDFS
    dfs(next, dist[next - 1]);
  }
}

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

  // treeの作成
  int a, b, c;
  rep(i, N - 1) {
    cin >> a >> b >> c;
    tree[a - 1].push_back(b);
    tree[b - 1].push_back(a);
    cost[{a, b}] = c;
  }

  int Q, K;
  cin >> Q >> K;

  // 頂点Kを探索済みにする
  visit[K - 1] = true;

  // 最短経路探索
  dfs(K, 0);

  // クエリ処理
  int x, y;
  rep(i, Q) {
    cin >> x >> y;
    // 頂点x -> K -> yの最短距離を考えればよい
    cout << dist[x - 1] + dist[y - 1] << endl;
  }

  return 0;
}


Fixed submission:
#include <iostream>
#include <map>
#include <set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100010
using namespace std;

// 木のデータ構造
vector<vector<int>> tree(MAX, vector<int>());

// 訪問済み検査配列
vector<bool> visit(MAX, false);

// 頂点Kから頂点iへの最短距離はdist[i]である
long long dist[MAX];

// 頂点間の距離（コスト）
map<set<int>, int> cost;

// 頂点nowからの距離がdである
void dfs(int now, long long d) {
  for (auto next : tree[now - 1]) {
    // 訪問済みなら次の頂点へ
    if (visit[next - 1] == true)
      continue;

    // nextを訪問済みにし，距離を計算
    visit[next - 1] = true;
    dist[next - 1] = d + cost[{now, next}];

    // 再帰的にDFS
    dfs(next, dist[next - 1]);
  }
}

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

  // treeの作成
  int a, b, c;
  rep(i, N - 1) {
    cin >> a >> b >> c;
    tree[a - 1].push_back(b);
    tree[b - 1].push_back(a);
    cost[{a, b}] = c;
  }

  int Q, K;
  cin >> Q >> K;

  // 頂点Kを探索済みにする
  visit[K - 1] = true;

  // 最短経路探索
  dfs(K, 0);

  // クエリ処理
  int x, y;
  rep(i, Q) {
    cin >> x >> y;
    // 頂点x -> K -> yの最短距離を考えればよい
    cout << dist[x - 1] + dist[y - 1] << endl;
  }

  return 0;
}
Problem p03634 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int main() {
  int n;
  cin >> n;
  int q, k;
  vector<vector<pair<int, long long>>> vec(n + 10);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    vec[a].emplace_back(make_pair(b, c));
    vec[b].emplace_back(make_pair(a, c));
  }
  priority_queue<pair<long long, int>> que;
  long long co[100010];
  for (int i = 0; i < 100010; i++) {
    co[i] = 10000000000000007;
  }
  cin >> q >> k;
  que.push(make_pair(0, k));
  while (!que.empty()) {
    long long y = que.top().first;
    int x = que.top().second;
    que.pop();
    for (int i = 0; i < vec[x].size(); i++) {
      if (y + vec[x][i].second < co[vec[x][i].first]) {
        co[vec[x][i].first] = y + vec[x][i].second;
        que.push(make_pair(y + vec[x][i].second, vec[x][i].first));
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << co[l] + co[r] << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int main() {
  int n;
  cin >> n;
  int q, k;
  vector<vector<pair<int, long long>>> vec(n + 10);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    vec[a].emplace_back(make_pair(b, c));
    vec[b].emplace_back(make_pair(a, c));
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      que;
  long long co[100010];
  for (int i = 0; i < 100010; i++) {
    co[i] = 10000000000000007;
  }
  cin >> q >> k;
  que.push(make_pair(0, k));
  while (!que.empty()) {
    long long y = que.top().first;
    int x = que.top().second;
    que.pop();
    for (int i = 0; i < vec[x].size(); i++) {
      if (y + vec[x][i].second < co[vec[x][i].first]) {
        co[vec[x][i].first] = y + vec[x][i].second;
        que.push(make_pair(y + vec[x][i].second, vec[x][i].first));
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << co[l] + co[r] << endl;
  }
  return 0;
}
Problem p03634 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)


def dfs(v, parent, d):
    depth[v] = d
    for to, cost in tree[v]:
        if to == parent:
            continue
        dfs(to, v, d + cost)


depth = defaultdict(int)
tree = defaultdict(list)
n = int(input())
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(depth[x] + depth[y])


Fixed submission:
import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)


def input():
    return sys.stdin.readline()[:-1]


def dfs(v, parent, d):
    depth[v] = d
    for to, cost in tree[v]:
        if to == parent:
            continue
        dfs(to, v, d + cost)


depth = defaultdict(int)
tree = defaultdict(list)
n = int(input())
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(depth[x] + depth[y])
Problem p03634 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
D = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append((b, c))
    D[b].append((a, c))
Q, K = map(int, input().split())
DS = [-1] * (N + 2)


def dfs(c, p, d):
    DS[c] = d
    for r in D[c]:
        if r[0] == p:
            continue
        dfs(r[0], c, d + r[1])


def main():
    dfs(K - 1, -1, 0)
    for _ in range(Q):
        x, y = map(int, input().split())
        print(DS[x - 1] + DS[y - 1])


main()


Fixed submission:
import sys

sys.setrecursionlimit(1000001)

N = int(input())
D = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append((b, c))
    D[b].append((a, c))
Q, K = map(int, input().split())
DS = [-1] * (N + 2)


def dfs(c, p, d):
    DS[c] = d
    for r in D[c]:
        if r[0] == p:
            continue
        dfs(r[0], c, d + r[1])


def main():
    dfs(K - 1, -1, 0)
    for _ in range(Q):
        x, y = map(int, input().split())
        print(DS[x - 1] + DS[y - 1])


main()
Problem p03635 (C++)

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

int main() {
  string S;
  cin >> S;
  S.at(3) = '8';
  cout << S << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
}
Problem p03635 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;
int main() {

  int a, b;

  cin >> a >> b;

  return (a - 1) * (b - 1);
}

Fixed submission:
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;
int main() {

  int a, b;

  cin >> a >> b;

  cout << (a - 1) * (b - 1);

  return 0;
}
Problem p03635 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans;

  while (n >= 2 && m <= 100) {
    ans = (n - 1) * (m - 1);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans;

  ans = (n - 1) * (m - 1);
  cout << ans;

  return 0;
}
Problem p03635 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input())
print((n - 1) * (m - 1))


Fixed submission:
n, m = map(int, input().split())
print((n - 1) * (m - 1))
Problem p03636 (C++)

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

int main() {
  string s;
  cin >> s;
  cout << s.at(0) << int(s.size()) - 2 << s.at(s.size()) << endl;
}


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

int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
}
Problem p03636 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, i;
  char s[i];
  cin >> s;
  a = strlen(s);
  cout << s[0] << a - 2 << s[a - 1];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  char s[100000];
  cin >> s;
  a = strlen(s);
  cout << s[0] << a - 2 << s[a - 1];
}
Problem p03636 (C++)

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

int main() {
  string s;
  cin >> s;
  if (s.size() > 2) {
    cout << s.at(1) << s.size() - 2 << s.at(s.size()) << endl;
  } else
    cout << s << endl;
}

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

int main() {
  string s;
  cin >> s;
  if (s.size() > 2) {
    cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
  } else
    cout << s << endl;
}
Problem p03636 (C++)

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

int main() {
  string s;
  cin >> s;
  int N = s.size();
  cout << s.at(0) << N - 2 << s.at(N) << endl;
}


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

int main() {
  string s;
  cin >> s;
  int N = s.size();
  cout << s.at(0) << N - 2 << s.at(N - 1) << endl;
}
Problem p03636 (C++)

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

int main() {
  string s;
  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1);
}

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

int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
}
Problem p03636 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[50];
  cin >> s;
  int len = strlen(s);

  cout << s[0] << len - 2 << s[len - 1] << endl;
}


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[100];
  cin >> s;
  int len = strlen(s);

  cout << s[0] << len - 2 << s[len - 1] << endl;
}
Problem p03636 (C++)

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

int main() {
  string s;
  int num = 0;
  for (int i = 1; i < s.size() - 1; i++) {
    num++;
  }

  cout << s.at(0) << num << s.at(s.size() - 1) << endl;
}

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

int main() {
  string s;
  cin >> s;
  int num = 0;
  for (int i = 1; i < s.size() - 1; i++) {
    num++;
  }

  cout << s.at(0) << num << s.at(s.size() - 1) << endl;
}
Problem p03636 (C++)

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

int main() {
  string s;
  cout << s.at(0) << s.length() - 2 << s.at(s.length() - 1) << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.length() - 2 << s.at(s.length() - 1) << endl;
  return 0;
}
Problem p03636 (C++)

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

int main() {
  string s;
  cin >> s;

  cout << s.at(0) << s.size() << s.at(s.size()) << endl;
}

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

int main() {
  string s;
  cin >> s;

  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
}
Problem p03636 (C++)

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

int main() {
  string s;
  int K;
  K = s.size() - 2;
  cout << s.at(0) << K << s.at(s.size() - 1);
}

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

int main() {
  string s;
  cin >> s;
  int K, L, D;
  K = s.size();
  D = K - 2;
  L = K - 1;
  cout << s.at(0) << D << s.at(L);
}
Problem p03636 (C++)

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

  cout << s.at(1) << s.size() - 2 << s.at(s.size()) << endl;
}


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

  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
}
Problem p03636 (C++)

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

int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.size() - 2 << s.at(s.size()) << endl;
}


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

int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
}
Problem p03636 (C++)

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

int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.length() - 2 << s.at(s.length()) << endl;
}


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

int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
}
Problem p03636 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  string s;
  cin >> s;
  a = s.size();
  cout << s.at(0) << a - 2 << s.at(a) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  string s;
  cin >> s;
  a = s.size();
  cout << s[0] << a - 2 << s[a - 1] << endl;
}
Problem p03636 (Python)

Buggy submission (status: Runtime Error):
# AtCoder
s = input()
mid = str(len(s) - 2)
print(f"{s[0]}{mid}{s[-1]}")


Fixed submission:
# AtCoder
s = input()
mid = str(len(s) - 2)
print(s[0] + mid + s[-1])
Problem p03636 (Python)

Buggy submission (status: Runtime Error):
s = input()
print(f"{s[0]}{s.len()-2}{s[-1]}")


Fixed submission:
s = input()
print(s[0], end="")
print(len(s) - 2, end="")
print(s[-1])
Problem p03636 (Python)

Buggy submission (status: Runtime Error):
s = input()
# 頭とお尻の文字数を引く
n = len(s) - 2
# 頭とお尻をくっつくて出力
print(f"{s[0]}{n}{s[-1]}")


Fixed submission:
s = input()
# 頭とお尻の文字数を引く
n = len(s) - 2
# 頭とお尻をくっつくて出力
print(s[0] + str(n) + s[-1])
Problem p03636 (Python)

Buggy submission (status: Runtime Error):
s = input()

print(s[0] + len(s[1:-1]) + s[-1])


Fixed submission:
s = input()

print(s[0] + str(len(s[1:-1])) + s[-1])
Problem p03636 (Python)

Buggy submission (status: Runtime Error):
s = input()
print("".join(s[0], str(len(s) - 2), s[-1]))


Fixed submission:
s = input()
print("{}{}{}".format(s[0], str(len(s) - 2), s[-1]))
Problem p03636 (C++)

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

int main() {
  string s;
  cin >> s;

  cout << s.at(0) << s.size() << s.at(s.size()) << endl;

  return 0;
}


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

int main() {
  string s;
  cin >> s;

  cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;

  return 0;
}
Problem p03636 (C++)

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

int main(void) {
  char s[128];

  scanf("%s", s);
  printf("%d%s%d\n", *s, strlen(s) - 2, s[strlen(s) - 1]);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
using namespace std;

int main(void) {
  char s[128];

  scanf("%s", s);
  printf("%c%d%c\n", *s, strlen(s) - 2, s[strlen(s) - 1]);
  return 0;
}
Problem p03636 (C++)

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

int main() {
  string s;
  int t = s.size();
  cout << s.at(0) << s.size() - 2 << s.at(t - 1) << endl;
}

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

int main() {
  string s;
  cin >> s;
  int t = s.size();
  cout << s.at(0) << s.size() - 2 << s.at(t - 1) << endl;
}
Problem p03637 (C++)

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

int main() {
  int N;
  cin >> N;
  int a[10000];
  for (int i = 0; i < N; i++)
    cin >> a[i];
  // 4の倍数・偶数サーチ
  int four = 0, two = 0, odd = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] % 4 == 0)
      four++;
    else if (a[i] % 2 == 0)
      two++;
    else
      odd++;
  }
  // 許容される奇数の数は？
  if (two != 0) {
    if (odd <= four)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else {
    if ((odd - 1) <= four)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a[100000];
  for (int i = 0; i < N; i++)
    cin >> a[i];
  // 4の倍数・偶数サーチ
  int four = 0, two = 0, odd = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] % 4 == 0)
      four++;
    else if (a[i] % 2 == 0)
      two++;
    else
      odd++;
  }
  // 許容される奇数の数は？
  if (two != 0) {
    if (odd <= four)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else {
    if ((odd - 1) <= four)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}
Problem p03637 (C++)

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

int a[10050];

int main() {
  int n, b2, b4, b24, b, flag = 0;
  b2 = b4 = b24 = b = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] % 4 == 0) {
      b4++;
    } else {
      if (a[i] % 2 == 0) {
        b2++;
        flag = 1;
      } else
        b++;
    }
  }
  if (b4 >= b + b2 - 1)
    cout << "Yes" << endl;
  else {
    if (flag && b4 >= b)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

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

int a[105000];

int main() {
  int n, b2, b4, b24, b, flag = 0;
  b2 = b4 = b24 = b = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] % 4 == 0) {
      b4++;
    } else {
      if (a[i] % 2 == 0) {
        b2++;
        flag = 1;
      } else
        b++;
    }
  }
  if (b4 >= b + b2 - 1)
    cout << "Yes" << endl;
  else {
    if (flag && b4 >= b)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
Problem p03637 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
#define REP(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 102
#define MAXM 100005
#define MAXV 1000000009

ll n, A[MAXN], a, b, c;

int main() {
  cin >> n;
  REP(i, 0, n) {
    cin >> A[i];
    if (A[i] % 4 == 0) {
      a++;
    } else if (A[i] % 2 == 0) {
      b++;
    } else {
      c++;
    }
  }
  if (n % 2 == 0) {
    if (a >= c) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  } else {
    if (a + 1 >= c) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }

  return 0;
}
/*
 */


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
#define REP(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 100005
#define MAXM 100005
#define MAXV 1000000009

ll n, A[MAXN], a, b, c;

int main() {
  cin >> n;
  REP(i, 0, n) {
    cin >> A[i];
    if (A[i] % 4 == 0) {
      a++;
    } else if (A[i] % 2 == 0) {
      b++;
    } else {
      c++;
    }
  }
  if (n % 2 == 0) {
    if (a >= c) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  } else {
    if (a + 1 >= c) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }

  return 0;
}
/*
 */
Problem p03637 (C++)

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define dep(i, a, n) for (int i = a; i >= (n); i--)
#define FOR(i, a, n) for (int i = a; i < (n); i++)
#define mod (ll)(1e9 + 7)
#define int ll
#define INF 100000000

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  ll n, a[10001];
  ll one = 0, two = 0, four = 0;
  string result;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    if (a[i] % 4 == 0)
      four++;
    else if (a[i] % 2 == 0)
      two++;
    else
      one++;
  }
  if (two) {
    if (one <= four)
      result = "Yes";
    else
      result = "No";
  } else {
    if (one <= four + 1)
      result = "Yes";
    else
      result = "No";
  }
  cout << result << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define dep(i, a, n) for (int i = a; i >= (n); i--)
#define FOR(i, a, n) for (int i = a; i < (n); i++)
#define mod (ll)(1e9 + 7)
#define int ll
#define INF 100000000

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  ll n, a[100001];
  ll one = 0, two = 0, four = 0;
  string result;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    if (a[i] % 4 == 0)
      four++;
    else if (a[i] % 2 == 0)
      two++;
    else
      one++;
  }
  if (two) {
    if (one <= four)
      result = "Yes";
    else
      result = "No";
  } else {
    if (one <= four + 1)
      result = "Yes";
    else
      result = "No";
  }
  cout << result << endl;
  return 0;
}
Problem p03637 (C++)

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

#define MAXN 100
/*
bool check1(int *a, int n);
bool check2(int *a, int n);

int main()
{
    int n, i, a[MAXN];
    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
       scanf("%d", &a[i]);
    }
    if(check1(a, n) == false)
        printf("No");
    else
        printf("Yes");
}
bool check1(int * a, int n)
{
   int *p, i;
   if(check2(a, n) == false)
        return false;
    else
    {
        for(i = 0; i < n; i++)
        {
           *p = * (a + n);
           * (a + n) = * (a + i);
           * (a + i) = * p;
           if(check1(a, n-1) == false || a[n-2] * a[n-1] % 4 != 0)
              return false;
           *p = * (a + n);
           * (a + n) = * (a + i);
           * (a + i) = * p;
        }
    }
    return true;
}
bool check2(int * a, int n)
{
    int i;
    for(i = 1; i < n - 1; i++)
    {
        if(a[i] * a[i-1] % 4 != 0 || a[i] * a[i+1] % 4 != 0)
            return false;
    }
    if(a[0] * a[1] % 4 != 0 )
        return false;
    return true;
}
*/
int main() {
  int n, i, a[MAXN], a4 = 0, a2 = 0, a1 = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] % 4 == 0)
      a4++;
    if (a[i] % 2 == 0 && a[i] % 4 != 0)
      a2++;
    if (a[i] % 2 != 0)
      a1++;
  }
  if (a4 >= a1) {
    printf("Yes\n");
  } else {
    if (a4 == a1 - 1 && a2 == 0)
      printf("Yes\n");
    else
      printf("No\n");
  }
}


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

#define MAXN 100000
/*
bool check1(int *a, int n);
bool check2(int *a, int n);

int main()
{
    int n, i, a[MAXN];
    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
       scanf("%d", &a[i]);
    }
    if(check1(a, n) == false)
        printf("No");
    else
        printf("Yes");
}
bool check1(int * a, int n)
{
   int *p, i;
   if(check2(a, n) == false)
        return false;
    else
    {
        for(i = 0; i < n; i++)
        {
           *p = * (a + n);
           * (a + n) = * (a + i);
           * (a + i) = * p;
           if(check1(a, n-1) == false || a[n-2] * a[n-1] % 4 != 0)
              return false;
           *p = * (a + n);
           * (a + n) = * (a + i);
           * (a + i) = * p;
        }
    }
    return true;
}
bool check2(int * a, int n)
{
    int i;
    for(i = 1; i < n - 1; i++)
    {
        if(a[i] * a[i-1] % 4 != 0 || a[i] * a[i+1] % 4 != 0)
            return false;
    }
    if(a[0] * a[1] % 4 != 0 )
        return false;
    return true;
}
*/
int main() {
  int n, i, a[MAXN], a4 = 0, a2 = 0, a1 = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] % 4 == 0)
      a4++;
    if (a[i] % 2 == 0 && a[i] % 4 != 0)
      a2++;
    if (a[i] % 2 != 0)
      a1++;
  }
  if (a4 >= a1) {
    printf("Yes\n");
  } else {
    if (a4 == a1 - 1 && a2 == 0)
      printf("Yes\n");
    else
      printf("No\n");
  }
}
Problem p03637 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[10005];
int main() {
  int n;
  int l = 0;
  int flag = 0;
  int p = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] % 4 == 0)
      l++;
    if (a[i] % 2 == 0)
      p++;
  }
  int w = p - l;
  int y = w / 2;
  if (n % 2 == 0) {
    if (l + y >= n / 2)
      flag = 1;
  } else {
    if (l + y >= (n - 1) / 2)
      flag = 1;
  }

  if (flag)
    printf("Yes\n");
  else
    printf("No\n");
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[100050];
int main() {
  int n;
  int l = 0;
  int flag = 0;
  int p = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] % 4 == 0)
      l++;
    if (a[i] % 2 == 0)
      p++;
  }
  int w = p - l;
  int y = w / 2;
  if (n % 2 == 0) {
    if (l + y >= n / 2)
      flag = 1;
  } else {
    if (l + y >= (n - 1) / 2)
      flag = 1;
  }

  if (flag)
    printf("Yes\n");
  else
    printf("No\n");
}
Problem p03638 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

// 68 11 55 - rank 3
// 69 12 19

int gcd(int a, int b) {
  while (b != 0) {
    auto na = a % b;
    a = b;
    b = na;
  }
  return a;
}

void oneCase() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n);
  for (auto &e : a) {
    cin >> e;
  }
  int color = 0;
  int id = 0;
  vector<vector<int>> b(h, vector<int>(w, 0));
  for (int r = 0; r < h; ++r) {
    for (int c = 0; c < w; ++c) {
      auto column = c;
      if (r % 2 == 1) {
        column = n - c - 1;
      }
      if (color == a[id]) {
        ++id;
        color = 0;
      }
      b[r][column] = id;
      ++color;
    }
  }

  for (auto &row : b) {
    for (auto el : row) {
      cout << el + 1 << " ";
    }
    cout << "\n";
  }
}

int main() {
  int t = 1;
  //    cin >> t;
  while (t--) {
    oneCase();
  }

  return 0;
}

ll fact(ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    res = (res * n) % mod;
    --n;
  }
  return res;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

// 68 11 55 - rank 3
// 69 12 19

int gcd(int a, int b) {
  while (b != 0) {
    auto na = a % b;
    a = b;
    b = na;
  }
  return a;
}

void oneCase() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n);
  for (auto &e : a) {
    cin >> e;
  }
  int color = 0;
  int id = 0;
  vector<vector<int>> b(h, vector<int>(w, 0));
  for (int r = 0; r < h; ++r) {
    for (int c = 0; c < w; ++c) {
      auto column = c;
      if (r % 2 == 1) {
        column = w - c - 1;
      }
      if (color == a[id]) {
        ++id;
        color = 0;
      }
      b[r][column] = id;
      ++color;
    }
  }

  for (auto &row : b) {
    for (auto el : row) {
      cout << el + 1 << " ";
    }
    cout << "\n";
  }
}

int main() {
  int t = 1;
  //    cin >> t;
  while (t--) {
    oneCase();
  }

  return 0;
}

ll fact(ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    res = (res * n) % mod;
    --n;
  }
  return res;
}
Problem p03638 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int MAXN = 100 + 5;
int a[MAXN][MAXN], s[MAXN];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int t, cnt = 0;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++)
      scanf("%d", &s[i]);
    int x = 1, y = 1;
    for (int i = 1; i <= t; i++) {
      for (int j = 1; j <= s[i]; j++) {
        a[x][y++] = i;
        if (y == m + 1) {
          x = x + 1;
          y = 1;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (i % 2 == 1) {
        for (int j = 1; j <= m; j++)
          printf("%d ", a[i][j]);
      }

      else if (i % 2 == 0) {
        for (int j = m; j >= 1; j--)
          printf("%d ", a[i][j]);
      }
      printf("\n");
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int MAXN = 10000 + 15;
int a[200][200], s[MAXN];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int t, cnt = 0;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++)
      scanf("%d", &s[i]);
    int x = 1, y = 1;
    for (int i = 1; i <= t; i++) {
      for (int j = 1; j <= s[i]; j++) {
        a[x][y++] = i;
        if (y == m + 1) {
          x = x + 1;
          y = 1;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (i % 2 == 1) {
        for (int j = 1; j <= m; j++)
          printf("%d ", a[i][j]);
      }

      else if (i % 2 == 0) {
        for (int j = m; j >= 1; j--)
          printf("%d ", a[i][j]);
      }
      printf("\n");
    }
  }
}
Problem p03638 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
  ll H, W;
  cin >> H >> W;
  ll N;
  cin >> N;
  ll a[200] = {0}, c[200][200] = {0};
  // cは出力
  rep(i, N) cin >> a[i];
  ll col = 0, row = 0;
  bool flag = true; // if(true)left to right
  rep(i, N) {
    rep(j, a[i]) {
      if (flag) {
        c[col][row] = i + 1;
        row++;
        if (row == W) {
          flag = false;
          row = 0;
          col++;
        }
      } else {
        c[col][W - 1 - row] = i + 1;
        row++;
        if (row == W) {
          flag = true;
          row = 0;
          col++;
        }
      }
    }
  }
  rep(i, H) {
    rep(j, W) { cout << c[i][j] << " "; }
    cout << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
  ll H, W;
  cin >> H >> W;
  ll N;
  cin >> N;
  ll a[200000] = {0}, c[200][200] = {0};
  // cは出力
  rep(i, N) cin >> a[i];
  ll col = 0, row = 0;
  bool flag = true; // if(true)left to right
  rep(i, N) {
    rep(j, a[i]) {
      if (flag) {
        c[col][row] = i + 1;
        row++;
        if (row == W) {
          flag = false;
          row = 0;
          col++;
        }
      } else {
        c[col][W - 1 - row] = i + 1;
        row++;
        if (row == W) {
          flag = true;
          row = 0;
          col++;
        }
      }
    }
  }
  rep(i, H) {
    rep(j, W) { cout << c[i][j] << " "; }
    cout << endl;
  }
}
Problem p03638 (C++)

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

#define reps(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reps(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main() {
  int H, W, N, a[110];
  int G[60][60];
  cin >> H >> W >> N;
  rep(i, N) { cin >> a[i]; }
  int cnt = 0, col = 0;
  rep(i, H) {
    rep(j, W) {
      if (i % 2 == 0)
        G[i][j] = col + 1;
      else
        G[i][W - 1 - j] = col + 1;

      cnt++;
      if (cnt == a[col]) {
        col++;
        cnt = 0;
      }
    }
  }

  rep(i, H) {
    rep(j, W) { cout << G[i][j] << " "; }
    cout << endl;
  }
}

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

#define reps(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reps(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main() {
  int H, W, N, a[10010];
  int G[110][110];
  cin >> H >> W >> N;
  rep(i, N) { cin >> a[i]; }
  int cnt = 0, col = 0;
  rep(i, H) {
    rep(j, W) {
      if (i % 2 == 0)
        G[i][j] = col + 1;
      else
        G[i][W - 1 - j] = col + 1;

      cnt++;
      if (cnt == a[col]) {
        col++;
        cnt = 0;
      }
    }
  }

  rep(i, H) {
    rep(j, W) { cout << G[i][j] << " "; }
    cout << endl;
  }
}
Problem p03638 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ll h, w, n;
  cin >> h >> w >> n;
  ll grid[h * w];
  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < a[i]; j++) {
      grid[sum] = i + 1;
      sum++;
    }
  }
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (i % 2 == 0) {
        cout << grid[i * w + j] << " ";
      } else {
        if (j == 0)
          reverse(grid + i * w, grid + i * (w + 1));
        cout << grid[(i + 1) * w - j - 1] << " ";
      }
    }
    cout << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ll h, w, n;
  cin >> h >> w >> n;
  ll grid[h * w];
  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < a[i]; j++) {
      grid[sum] = i + 1;
      sum++;
    }
  }
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (i % 2 == 0) {
        cout << grid[i * w + j] << " ";
      } else {
        cout << grid[(i + 1) * w - j - 1] << " ";
      }
    }
    cout << endl;
  }
}
Problem p03638 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
const int maxn = 110;
int tag[maxn];
int tmp[maxn * maxn];
int ans[maxn][maxn];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int times, cnt = 1, change = 1;
    scanf("%d", &times);
    for (int i = 1; i <= times; i++) {
      scanf("%d", &tag[i]);
      for (int j = 1; j <= tag[i]; j++) {
        tmp[cnt] = i;
        cnt++;
      }
    }
    cnt = 1;
    for (int i = 1; i <= n; i++) {
      if (change == 1) {
        for (int j = 1; j <= m; j++) {
          ans[i][j] = tmp[cnt];
          cnt++;
        }
      } else {
        for (int j = m; j >= 1; j--) {
          ans[i][j] = tmp[cnt];
          cnt++;
        }
      }
      change = change * -1;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (j == 1)
          printf("%d ", ans[i][j]);
        else
          printf("%d ", ans[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>
const int maxn = 110;
int tag[maxn * maxn];
int tmp[maxn * maxn];
int ans[maxn][maxn];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int times, cnt = 1, change = 1;
    scanf("%d", &times);
    for (int i = 1; i <= times; i++) {
      scanf("%d", &tag[i]);
      for (int j = 1; j <= tag[i]; j++) {
        tmp[cnt] = i;
        cnt++;
      }
    }
    cnt = 1;
    for (int i = 1; i <= n; i++) {
      if (change == 1) {
        for (int j = 1; j <= m; j++) {
          ans[i][j] = tmp[cnt];
          cnt++;
        }
      } else {
        for (int j = m; j >= 1; j--) {
          ans[i][j] = tmp[cnt];
          cnt++;
        }
      }
      change = change * -1;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (j == 1)
          printf("%d ", ans[i][j]);
        else
          printf("%d ", ans[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}
Problem p03638 (C++)

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

int main() {
  int H, W;
  int mass[110][110];
  cin >> H >> W;

  int N;
  cin >> N;

  int a[10100];
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }

  vector<pair<int, int>> perm(H * N);
  int count = 1;
  for (int i = 0; i < H; i++) {
    int x;
    pair<int, int> p;
    if (count % 2) {
      for (int j = 0; j < W; j++) {
        p = make_pair(i, j);
        perm[x] = p;
        x++;
      }
    } else {
      for (int j = W - 1; j >= 0; j--) {
        p = make_pair(i, j);
        perm[x] = p;
        x++;
      }
    }
    count++;
  }

  int x = 0;
  for (int i = 1; i <= N; i++) {
    int count = 0;

    while (count < a[i]) {
      int h = perm[x].first, w = perm[x].second;
      mass[h][w] = i;
      x++;
      count++;
    }
  }
  // 結果の出力
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << mass[i][j] << " ";
    }
    cout << endl;
  }
}

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

int main() {
  int H, W;
  int mass[110][110];
  cin >> H >> W;

  int N;
  cin >> N;

  int a[10100];
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }

  vector<pair<int, int>> perm(10100);
  int count = 1;
  for (int i = 0; i < H; i++) {
    int x;
    pair<int, int> p;
    if (count % 2) {
      for (int j = 0; j < W; j++) {
        p = make_pair(i, j);
        perm[x] = p;
        x++;
      }
    } else {
      for (int j = W - 1; j >= 0; j--) {
        p = make_pair(i, j);
        perm[x] = p;
        x++;
      }
    }
    count++;
  }

  int x = 0;
  for (int i = 1; i <= N; i++) {
    int count = 0;

    while (count < a[i]) {
      int h = perm[x].first, w = perm[x].second;
      mass[h][w] = i;
      x++;
      count++;
    }
  }
  // 結果の出力
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << mass[i][j] << " ";
    }
    cout << endl;
  }
}