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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
const int N = 2e5 + 3, M = 1e9 + 7;
struct node {
  int x, v;
} a[N];
struct segment {
  int l, r;
} c[N];
bool Cmpa(const node &a, const node &b) { return a.x < b.x; }
bool Cmpc(const segment &a, const segment &b) { return a.r < b.r; }
int n, b[N], f[N];
int main() {
  int s, t, m, mx;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i].x, &a[i].v);
  std::sort(a + 1, a + 1 + n, Cmpa);
  b[0] = 0;
  for (int i = 1; i <= n; i++) {
    for (s = 1, t = i; s < t;)
      m = s + t >> 1, b[m] > a[i].v ? t = m : s = m + 1;
    c[i].l = s;
    b[i] = std::max(b[i - 1], a[i].v);
  }
  b[n + 1] = M;
  for (int i = n; i; i--) {
    for (s = i, t = n; s < t;)
      m = s + t + 1 >> 1, b[m] < a[i].v ? s = m : t = m - 1;
    c[i].r = t;
    b[i] = std::min(b[i + 1], a[i].v);
  }
  std::sort(c + 1, c + 1 + n, Cmpc);
  mx = 0, f[0] = 1;
  for (int i = 1, j = 1; i <= n; i++) {
    f[i] = (2ll * f[i - 1] - (mx ? f[mx - 1] : 0) + M) % M;
    for (; c[j].r <= i; j++)
      mx = std::max(mx, c[j].l);
  }
  printf("%d\n", (f[n] - f[mx - 1] + M) % M);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
const int N = 2e5 + 3, M = 1e9 + 7;
struct node {
  int x, v;
} a[N];
struct segment {
  int l, r;
} c[N];
bool Cmpa(const node &a, const node &b) { return a.x < b.x; }
bool Cmpc(const segment &a, const segment &b) { return a.r < b.r; }
int n, b[N], f[N];
int main() {
  int s, t, m, mx;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i].x, &a[i].v);
  std::sort(a + 1, a + 1 + n, Cmpa);
  b[0] = 0;
  for (int i = 1; i <= n; i++) {
    for (s = 1, t = i; s < t;)
      m = s + t >> 1, b[m] > a[i].v ? t = m : s = m + 1;
    c[i].l = s;
    b[i] = std::max(b[i - 1], a[i].v);
  }
  b[n + 1] = M;
  for (int i = n; i; i--) {
    for (s = i, t = n; s < t;)
      m = s + t + 1 >> 1, b[m] < a[i].v ? s = m : t = m - 1;
    c[i].r = t;
    b[i] = std::min(b[i + 1], a[i].v);
  }
  std::sort(c + 1, c + 1 + n, Cmpc);
  mx = 0, f[0] = 1;
  for (int i = 1, j = 1; i <= n; i++) {
    f[i] = (2ll * f[i - 1] - (mx ? f[mx - 1] : 0) + M) % M;
    for (; j <= n && c[j].r <= i; j++)
      mx = std::max(mx, c[j].l);
  }
  printf("%d\n", (f[n] - f[mx - 1] + M) % M);
  return 0;
}
Problem p03709 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const int N = 500005, M = 1000000007;
using namespace std;
int n, x, y, b[N], c[N];
struct seg {
  int a, b;
} l[N], s[N];
bool operator<(seg x, seg y) { return x.b == y.b ? x.a < y.a : x.b < y.b; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d%d", c + i, &l[i].b), l[i].a = c[i];
  sort(l, l + n), sort(c, c + n);
  for (int i = n - 1; ~i; i--) {
    x = l[i].a = upper_bound(c, c + n, l[i].a) - c;
    for (int j = x; j <= n; j += j & -j)
      b[j] = max(b[j], i);
    for (int j = x; j; j -= j & -j)
      s[i].b = max(s[i].b, b[j]);
  }
  memset(b, 0x3f, N * 4);
  for (int i = 0; i < n; i++) {
    x = l[i].a;
    for (int j = x; j; j -= j & -j)
      b[j] = min(b[j], i);
    s[i].a = 1e9;
    for (int j = x; j <= n; j += j & -j)
      s[i].a = min(s[i].a, b[j]);
  }
  sort(s, s + n);
  memset(b, 0, N * 4);
  b[1] = 1;
  for (int i = 0; i < n; i++) {
    for (x = s[i].a + 1, y = 0; x <= n + 1; x += x & -x)
      (y += b[x]) %= M;
    for (x = s[i].b + 2; x; x -= x & -x)
      (b[x] += y) %= M;
  }
  printf("%d", b[n + 1]);
  return b[n + 1];
}

Fixed submission:
#include <bits/stdc++.h>
const int N = 500005, M = 1000000007;
using namespace std;
int n, x, y, b[N], c[N];
struct seg {
  int a, b;
} l[N], s[N];
bool operator<(seg x, seg y) { return x.b == y.b ? x.a < y.a : x.b < y.b; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d%d", c + i, &l[i].b), l[i].a = c[i];
  sort(l, l + n), sort(c, c + n);
  for (int i = n - 1; ~i; i--) {
    x = l[i].a = upper_bound(c, c + n, l[i].a) - c;
    for (int j = x; j <= n; j += j & -j)
      b[j] = max(b[j], i);
    for (int j = x; j; j -= j & -j)
      s[i].b = max(s[i].b, b[j]);
  }
  memset(b, 0x3f, N * 4);
  for (int i = 0; i < n; i++) {
    x = l[i].a;
    for (int j = x; j; j -= j & -j)
      b[j] = min(b[j], i);
    s[i].a = 1e9;
    for (int j = x; j <= n; j += j & -j)
      s[i].a = min(s[i].a, b[j]);
  }
  sort(s, s + n);
  memset(b, 0, N * 4);
  b[1] = 1;
  for (int i = 0; i < n; i++) {
    for (x = s[i].a + 1, y = 0; x <= n + 1; x += x & -x)
      (y += b[x]) %= M;
    for (x = s[i].b + 2; x; x -= x & -x)
      (b[x] += y) %= M;
  }
  printf("%d", b[n + 1]);
}
Problem p03710 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long ll;
const int p = 1e9 + 7;

void up(int &a, int b) { (a += b) >= p && (a -= p); }

ll f[101][3];

int T, k;
ll x, y, ans;

void dfs(ll a, ll b, int t) {
  if (t + 1 == k) {
    ans += ((y - a) / b + (x - a) / b) % p;
    return;
  }

  for (a += b; (x - b * f[k - t][1]) / a >= f[k - t][2] &&
               (y - b * f[k - t + 1][1]) / a >= f[k - t + 1][2];
       a += b)
    dfs(b, a, t + 1);
}

int main() {
  f[1][0] = f[1][1] = f[2][0] = f[2][2] = 1;
  for (int i = 3; i <= 100; ++i)
    for (int j = 0; j <= 2; ++j)
      f[i][j] = f[i - 2][j] + f[i - 1][j];

  scanf("%d", &T);
  for (; T--;) {
    scanf("%lld%lld", &x, &y);
    if (x > y)
      std::swap(x, y);

    if (x < 2) {
      printf("1 %lld\n", y % p);
      continue;
    }

    for (k = 2; f[k][0] <= x && f[k + 1][0] <= y; ++k)
      ;
    if ((k -= 2) < 2) {
      printf("1 %lld\n", x * y % p);
      continue;
    }

    ans = 0;
    for (int i = 2;
         f[k][1] + f[k][2] * i <= x && f[k + 1][1] + f[k + 1][2] * i <= y; ++i)
      dfs(1, i, 1);
    printf("%d %lld\n", k, ans % p);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
const int p = 1e9 + 7;

void up(int &a, int b) { (a += b) >= p && (a -= p); }

ll f[101][3];

int T, k;
ll x, y, ans;

void dfs(ll a, ll b, int t) {
  if (t + 1 == k) {
    ans += ((y - a) / b + (x - a) / b) % p;
    return;
  }

  for (a += b; f[k - t][1] * b + f[k - t][2] * a <= x &&
               f[k - t + 1][1] * b + f[k - t + 1][2] * a <= y;
       a += b)
    dfs(b, a, t + 1);
}

int main() {
  f[1][0] = f[1][1] = f[2][0] = f[2][2] = 1;
  for (int i = 3; i <= 100; ++i)
    for (int j = 0; j <= 2; ++j)
      f[i][j] = f[i - 2][j] + f[i - 1][j];

  scanf("%d", &T);
  for (; T--;) {
    scanf("%lld%lld", &x, &y);
    if (x > y)
      std::swap(x, y);

    if (x < 2) {
      printf("1 %lld\n", y % p);
      continue;
    }

    for (k = 2; f[k][0] <= x && f[k + 1][0] <= y; ++k)
      ;
    if ((k -= 2) < 2) {
      printf("1 %lld\n", x * y % p);
      continue;
    }

    ans = 0;
    for (int i = 2;
         f[k][1] + f[k][2] * i <= x && f[k + 1][1] + f[k + 1][2] * i <= y; ++i)
      dfs(1, i, 1);
    printf("%d %lld\n", k, ans % p);
  }

  return 0;
}
Problem p03710 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long
#define MP make_pair
#define N 805

using namespace std;
typedef pair<int, int> Pair;

inline int input() {
  int x;
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48))
    ;
  return x;
}

const int mod = 1e9 + 7;
const int MAX = 88;
int Q, x, y;
int f[100];

vector<Pair> P[100]; // P[i] 存的是 f(x, y) == i 的 优秀的对

void init() {
  f[0] = 1, f[1] = 2;
  for (int i = 2; i <= MAX; ++i)
    f[i] = f[i - 1] + f[i - 2];
  P[1].push_back(MP(1, 2)), P[1].push_back(MP(1, 3)), P[1].push_back(MP(1, 4));

  for (int i = 1; i <= MAX; ++i)
    for (auto p : P[i]) {
      int x = p.first, y = p.second;
      for (int j = x + y; j <= f[i + 1] << 1; j += y)
        P[i + 1].push_back(MP(y, j));
    }
}

void solve(int x, int y) {
  int k = 1;
  if (x > y)
    swap(x, y);
  while (f[k] <= x && f[k + 1] <= y)
    ++k;
  printf("%lld ", k);

  if (k == 1) {
    printf("%lld\n", x % mod * y % mod);
    return void();
  }

  int res = 0;
  for (auto p : P[k - 1]) {
    int xd = p.first, yd = p.second;
    if (yd <= x)
      res += (y - xd) / yd % mod;
    if (yd <= y)
      res += (x - xd) / yd % mod;
  }

  printf("%lld\n", res % mod);
}

signed main() {
#ifndef ONLINE_JUDGE
  freopen("fibo.in", "r", stdin);
  freopen("fibo.out", "w", stdout);
  freopen("fibo.log", "w", stderr);
#endif

  init();
  Q = input();
  while (Q--) {
    x = input(), y = input();
    solve(x, y);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long
#define MP make_pair
#define N 805

using namespace std;
typedef pair<int, int> Pair;

inline int input() {
  int x;
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48))
    ;
  return x;
}

const int mod = 1e9 + 7;
const int MAX = 88;
int Q, x, y;
int f[100];

vector<Pair> P[100]; // P[i] 存的是 f(x, y) == i 的 优秀的对

void init() {
  f[0] = 1, f[1] = 2;
  for (int i = 2; i <= MAX; ++i)
    f[i] = f[i - 1] + f[i - 2];
  P[1].push_back(MP(1, 2)), P[1].push_back(MP(1, 3)), P[1].push_back(MP(1, 4));

  for (int i = 1; i <= MAX; ++i)
    for (auto p : P[i]) {
      int x = p.first, y = p.second;
      for (int j = x + y; j <= f[i + 1] << 1; j += y)
        P[i + 1].push_back(MP(y, j));
    }
}

void solve(int x, int y) {
  int k = 1;
  if (x > y)
    swap(x, y);
  while (f[k] <= x && f[k + 1] <= y)
    ++k;
  printf("%lld ", k);

  if (k == 1) {
    printf("%lld\n", x % mod * y % mod);
    return void();
  }

  int res = 0;
  for (auto p : P[k - 1]) {
    int xd = p.first, yd = p.second;
    if (yd <= x)
      res += (y - xd) / yd % mod;
    if (yd <= y)
      res += (x - xd) / yd % mod;
  }

  printf("%lld\n", res % mod);
}

signed main() {

  init();
  Q = input();
  while (Q--) {
    x = input(), y = input();
    solve(x, y);
  }
  return 0;
}
Problem p03711 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> a = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x, y;
  cin >> x >> y;
  if (a.at(x) == a.at(y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> a = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x, y;
  cin >> x >> y;
  if (a.at(x - 1) == a.at(y - 1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03711 (Python)

Buggy submission (status: Runtime Error):
L = [0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]

x, y = map(int, input().split())

if L(x) == L(y):
    print("Yes")
else:
    print("No")


Fixed submission:
L = [0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]

x, y = map(int, input().split())

print(["No", "Yes"][L[x] == L[y]])
Problem p03711 (Python)

Buggy submission (status: Runtime Error):
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if (x in a and y in a) or (x in b and y in b) or (x in c in y in c):
    print("Yes")
else:
    print("No")


Fixed submission:
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print("Yes")
else:
    print("No")
Problem p03711 (C++)

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

using namespace std;

int main() {
  int a[] = {1, 3, 5, 7, 8, 10, 12};
  int b[] = {4, 6, 9, 11};
  int c[] = {2};
  int x, y, i, z = 0;

  cin >> x >> y;

  for (i = 0; i < 7; i++) {
    if (x == a[i]) {
      for (i = 0; i < 7; i++) {
        if (y == a[i]) {
          cout << "Yes" << endl;
          z = 1;
        }
      }
    } else if (x == b[i]) {
      for (i = 0; i < 4; i++) {
        if (y == b[i]) {
          cout << "Yes" << endl;
          z = 2;
        }
      }
    } else if (x == c[i]) {
      for (i = 0; i < 1; i++) {
        if (y == c[i]) {
          cout << "Yes" << endl;
          z = 3;
        }
      }
    }
  }
  if (z == 0) {
    cout << "No" << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  int a[] = {1, 3, 5, 7, 8, 10, 12};
  int b[] = {4, 6, 9, 11};
  int c[] = {2};
  int x, y, i, z = 0;

  cin >> x >> y;

  for (i = 0; i < 7; i++) {
    if (x == a[i]) {
      for (i = 0; i < 7; i++) {
        if (y == a[i]) {
          cout << "Yes" << endl;
          z = 1;
        }
      }
    } else if (x == b[i]) {
      for (i = 0; i < 4; i++) {
        if (y == b[i]) {
          cout << "Yes" << endl;
          z = 2;
        }
      }
    } else if (x == c[i]) {
      break;
    }
  }
  if (z == 0) {
    cout << "No" << endl;
  }

  return 0;
}
Problem p03711 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vector<int> vec(12);
  vec = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  if (vec.at(a + 1) == vec.at(b + 1))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vector<int> vec(12);
  vec = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  if (vec.at(a - 1) == vec.at(b - 1))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03711 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main() {
  int a, b;
  while (scanf("%d%d", &a, &b)) {
    if (a == b)
      printf("Yes\n");
    else if ((a == 4 || a == 6 || a == 9 || a == 11) &&
             (b == 4 || b == 6 || b == 9 || b == 11))
      printf("Yes\n");
    else if ((a == 1 || a == 3 || a == 5 || a == 7 || a == 10 || a == 8 ||
              a == 12) &&
             (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 ||
              b == 12))
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main() {
  int a, b;
  while (scanf("%d%d", &a, &b) == 2) {
    if (a == b)
      printf("Yes\n");
    else if ((a == 4 || a == 6 || a == 9 || a == 11) &&
             (b == 4 || b == 6 || b == 9 || b == 11))
      printf("Yes\n");
    else if ((a == 1 || a == 3 || a == 5 || a == 7 || a == 10 || a == 8 ||
              a == 12) &&
             (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 ||
              b == 12))
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}
Problem p03711 (C++)

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

int main() {
  int x, y;
  cin >> x >> y;
  vector<int> vec;
  vec = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  if (vec.at(x) == vec.at(y)) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


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

int main() {
  int x, y;
  cin >> x >> y;
  vector<int> vec;
  vec = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  if (vec.at(x) == vec.at(y)) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}
Problem p03711 (C++)

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

int main() {
  int a[13] = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};
  int x, y;
  while (scanf("%d%d", &x, &y)) {
    printf(a[x] - a[y] ? "No" : "Yes");
    printf("\n");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int a[13] = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};
  int x, y;
  //	while(){
  scanf("%d%d", &x, &y);
  printf(a[x] - a[y] ? "No" : "Yes");
  return 0;
}
Problem p03711 (C++)

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

int main() {

  string str = "012131313131";
  int x = 0, y = 0;

  cin >> x >> y;

  if (str.at(x) == str.at(y)) {

    cout << "Yes" << endl;

  } else {

    cout << "No" << endl;
  }

  return 0;
}

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

int main() {

  string str = "0121313113131";
  int x = 0, y = 0;

  cin >> x >> y;

  if (str.at(x) == str.at(y)) {

    cout << "Yes" << endl;

  } else {

    cout << "No" << endl;
  }

  return 0;
}
Problem p03711 (C++)

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

using namespace std;
int x, y;
vector<int> sets[2];
int main() {
  cin >> x >> y;
  if (x == 2 || y == 2) {
    cout << "No" << endl;
    return 0;
  }
  sets[0].push_back(1);
  sets[0].push_back(3);
  sets[0].push_back(5);
  sets[0].push_back(7);
  sets[0].push_back(8);
  sets[0].push_back(10);
  sets[0].push_back(12);
  sets[1].push_back(4);
  sets[1].push_back(6);
  sets[1].push_back(9);
  sets[1].push_back(11);
  int set_x, set_y;
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < sets[i].size(); ++i) {
      if (x == sets[i][j])
        set_x = i;
      if (y == sets[i][j])
        set_y = i;
    }
  }
  if (set_y == set_x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;
int x, y;
vector<int> sets[2];
int main() {
  cin >> x >> y;
  if (x == 2 || y == 2) {
    cout << "No" << endl;
    return 0;
  }
  sets[0].push_back(1);
  sets[0].push_back(3);
  sets[0].push_back(5);
  sets[0].push_back(7);
  sets[0].push_back(8);
  sets[0].push_back(10);
  sets[0].push_back(12);
  sets[1].push_back(4);
  sets[1].push_back(6);
  sets[1].push_back(9);
  sets[1].push_back(11);
  int set_x, set_y;
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < sets[i].size(); ++j) {
      if (x == sets[i][j])
        set_x = i;
      if (y == sets[i][j])
        set_y = i;
    }
  }
  if (set_y == set_x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03712 (C++)

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

int main() {
  int h, w, i, j;
  cin >> h >> w;

  string pic[h][w];
  for (i = 0; i < h + 2; i++) {
    for (j = 0; j < w + 2; j++) {
      pic[i][j] = '#';
    }
  }

  for (i = 1; i < h + 1; i++) {
    for (j = 1; j < w + 1; j++) {
      cin >> pic[i][j];
    }
  }

  for (i = 0; i < h + 2; i++) {
    for (j = 0; j < w + 2; j++) {
      cout << pic[i][j];
    }
    cout << endl;
  }
}


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

int main() {
  int h, w, i, j;
  cin >> h >> w;

  char pic[h + 2][w + 2];
  for (i = 0; i < h + 2; i++) {
    for (j = 0; j < w + 2; j++) {
      pic[i][j] = '#';
    }
  }

  for (i = 1; i < h + 1; i++) {
    for (j = 1; j < w + 1; j++) {
      cin >> pic[i][j];
    }
  }

  for (i = 0; i < h + 2; i++) {
    for (j = 0; j < w + 2; j++) {
      cout << pic[i][j];
    }
    cout << endl;
  }
}
Problem p03712 (C++)

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

int main() {
  int h, w;
  cin >> h >> w;
  char a[101][101];
  char b[101][101];

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cin >> a[y][x];
    }
  }

  for (int y = 0; y < h + 2; y++) {
    for (int x = 0; x < w + 2; x++) {
      b[y][x] = '#';
    }
  }

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      b[y + 1][x + 1] = a[y][x];
    }
  }

  for (int y = 0; y < h + 2; y++) {
    for (int x = 0; x < w + 2; x++) {
      cout << b[y][x];
    }
    cout << endl;
  }

  return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  char a[105][105];
  char b[105][105];

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cin >> a[y][x];
    }
  }

  for (int y = 0; y < h + 2; y++) {
    for (int x = 0; x < w + 2; x++) {
      b[y][x] = '#';
    }
  }

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      b[y + 1][x + 1] = a[y][x];
    }
  }

  for (int y = 0; y < h + 2; y++) {
    for (int x = 0; x < w + 2; x++) {
      cout << b[y][x];
    }
    cout << endl;
  }

  return 0;
}
Problem p03712 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char ans[h + 2][w + 2];
  char input[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> input[i][j];
    }
  }
  for (int i = 0; i < h + 2; h++) {
    for (int j = 0; j < w + 2; j++) {
      if (i == 0 || i == h + 1) {
        if (j == 0 || j == w + 1) {
          ans[i][j] = '#';
        }
      } else {
        ans[i][j] = input[i - 1][j - 1];
      }
    }
  }
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      cout << ans[i][j];
    }
    cout << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char ans[h + 2][w + 2];
  memset(ans, '#', sizeof(ans));
  for (int i = 1; i <= h; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= w; j++) {
      ans[i][j] = s.at(j - 1);
    }
  }
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      cout << ans[i][j];
    }
    cout << endl;
  }
}
Problem p03712 (C++)

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a;
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  cout << endl;
  for (int i = 0; i < h; i++) {
    cout << "#" << a[i] << "#" << endl;
  }
  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  cout << endl;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  cout << endl;
  for (int i = 0; i < h; i++) {
    cout << "#" << a[i] << "#" << endl;
  }
  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  cout << endl;
}
Problem p03712 (C++)

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

int main() {
  int N, M;
  string s, t;
  cin >> N >> M;

  vector<char> vec(N);
  s = "";
  t = "";

  for (int i = 0; i < M + 2; i++)
    s += "#";

  cout << s << endl;

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

    for (int j = 0; j < M; j++) {
      cin >> vec.at(j);
      t += vec.at(j);
    }

    cout << "#" << t << "#" << endl;
    t = "";
  }

  cout << s << endl;
}


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

int main() {
  int N, M;
  string s, t;
  cin >> N >> M;

  vector<char> vec(100);
  s = "";
  t = "";

  for (int i = 0; i < M + 2; i++)
    s += "#";

  cout << s << endl;

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

    for (int j = 0; j < M; j++) {
      cin >> vec.at(j);
      t += vec.at(j);
    }

    cout << "#" << t << "#" << endl;
    t = "";
  }

  cout << s << endl;
}
Problem p03712 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main() {
  int H, W;
  std::cin >> H >> W;
  std::vector<std::vector<char>> A(H, std::vector<char>(W));
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      std::cin >> A[i][j];

  for (int i = 0; i < W + 2; ++i)
    std::cout << '#';
  std::cout << std::endl;

  for (int i = 0; i < H; ++i) {
    std::cout << '#';
    for (int j = 0; i < W; ++j) {
      std::cout << A[i][j];
    }
    std::cout << '#' << std::endl;
  }

  for (int i = 0; i < W + 2; ++i)
    std::cout << '#';
  std::cout << std::endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main() {
  int H, W;
  std::cin >> H >> W;
  std::vector<std::vector<char>> A(H, std::vector<char>(W));
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      std::cin >> A[i][j];

  for (int i = 0; i < W + 2; ++i)
    std::cout << '#';
  std::cout << std::endl;

  for (int i = 0; i < H; ++i) {
    std::cout << '#';
    for (int j = 0; j < W; ++j) {
      std::cout << A[i][j];
    }
    std::cout << '#' << std::endl;
  }

  for (int i = 0; i < W + 2; ++i)
    std::cout << '#';
  std::cout << std::endl;

  return 0;
}
Problem p03712 (C++)

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

using namespace std;

int main(void) {
  int H, W;
  cin >> H >> W;

  vector<string> vec(H);

  for (int i = 0; i < H; i++) {
    cin >> vec.at(i);
  }

  for (int i = 1; i <= H + 2; i++) {
    if (i == 1 || i == H + 2) {
      for (int j = 1; j <= W + 2; j++)
        cout << "#";
      cout << endl;
    } else {
      cout << "#" << vec.at(i) << "#" << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int H, W;
  cin >> H >> W;

  vector<string> vec(H);

  for (int i = 0; i < H; i++) {
    cin >> vec.at(i);
  }

  for (int i = 1; i <= H + 2; i++) {
    if (i == 1 || i == H + 2) {
      for (int j = 1; j <= W + 2; j++)
        cout << "#";
      cout << endl;
    } else {
      cout << "#" << vec.at(i - 2) << "#" << endl;
    }
  }
  return 0;
}
Problem p03712 (C++)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int H, W = 0;
  cin >> H >> W;
  vector<string> data(100);
  rep(i, H + 2) {
    if (i == 0 || i == H + 1) {
      data.at(i) = string(W + 2, '#');
    } else {
      string line;
      cin >> line;
      line = '#' + line + '#';
      data.at(i) = line;
    }
  }

  rep(i, H + 2) { cout << data.at(i) << endl; }
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int H, W = 0;
  cin >> H >> W;
  vector<string> data(102);
  rep(i, H + 2) {
    if (i == 0 || i == H + 1) {
      data.at(i) = string(W + 2, '#');
    } else {
      string line;
      cin >> line;
      line = '#' + line + '#';
      data.at(i) = line;
    }
  }

  rep(i, H + 2) { cout << data.at(i) << endl; }
}
Problem p03712 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  char a[h][w];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < w + 2; i++) {
    cout << '#';
  }
  cout << endl;
  for (int i = 0; i < h; i++) {
    cout << '#';
    for (int j = 0; j < w; j++) {
      cout << a[i][j];
    }
    cout << '#' << endl;
  }
  for (int i = 0; i < w + 2; i++) {
    cout << '#';
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  char a[110][110];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < w + 2; i++) {
    cout << '#';
  }
  cout << endl;
  for (int i = 0; i < h; i++) {
    cout << '#';
    for (int j = 0; j < w; j++) {
      cout << a[i][j];
    }
    cout << '#' << endl;
  }
  for (int i = 0; i < w + 2; i++) {
    cout << '#';
  }
  cout << endl;
  return 0;
}
Problem p03712 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v;
  rep(i, h) cin >> v[i];
  rep(i, w + 2) cout << '#';
  cout << endl;
  rep(i, h) cout << '#' << v[i] << '#' << endl;
  rep(i, w + 2) cout << '#';
  cout << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  rep(i, h) cin >> v[i];
  rep(i, w + 2) cout << '#';
  cout << endl;
  rep(i, h) cout << '#' << v[i] << '#' << endl;
  rep(i, w + 2) cout << '#';
  cout << endl;
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<char> vec((W + 2) * (H + 2));
  int i = 0;

  rep(i, H + 2) {
    rep(j, W + 2) {
      if (i == 0 || i == H + 1) {
        vec.at(i * (W + 2) + j) = '#';
      } else {
        if (j == 0 || j == W + 1)
          vec.at(i * (W + 2) + j) = '#';
        else
          cin >> vec.at(i * (W + 2) + j);
      }
    }
  }

  rep(i, H + 2) {
    rep(j, W + 2) { cout << vec.at(i * (W + 2) + j); }
    cout << endl;
  }

  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<char> vec((W + 2) * (H + 2));
  int i = 0;

  rep(i, H + 2) {
    rep(j, W + 2) {
      if (i == 0 || i == H + 1) {
        vec.at(i * (W + 2) + j) = '#';
      } else {
        if (j == 0 || j == W + 1)
          vec.at(i * (W + 2) + j) = '#';
        else
          cin >> vec.at(i * (W + 2) + j);
      }
    }
  }

  rep(i, H + 2) {
    rep(j, W + 2) { cout << vec.at(i * (W + 2) + j); }
    cout << endl;
  }

  return 0;
}
Problem p03712 (C++)

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

int main() {
  int in_height, out_height = 0;
  int in_width, out_width = 0;
  vector<vector<char>> picture(100, vector<char>(9));

  // 画枠入力
  cin >> in_height >> in_width;

  // 出力画像サイズ
  out_height = in_height + 2;
  out_width = in_width + 2;

  // 画像データ入力
  for (int i = 0; i < in_height; i++) {
    for (int j = 0; j < in_width; j++) {
      cin >> picture.at(i).at(j);
      // cout << picture.at(i).at(j);
    }
  }
  for (int i = 0; i < out_height; i++) {
    for (int j = 0; j < out_width; j++) {
      if (i == 0 || i == (out_height - 1)) {
        cout << '#';
      } else if (j == 0 || j == (out_width - 1)) {
        cout << '#';
      } else {
        // 画像本体
        cout << picture.at(i - 1).at(j - 1);
      }
      if (j == out_width - 1)
        cout << endl;
    }
  }
}

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

int main() {
  int in_height, out_height = 0;
  int in_width, out_width = 0;
  vector<vector<char>> picture(100, vector<char>(100));

  // 画枠入力
  cin >> in_height >> in_width;

  // 出力画像サイズ
  out_height = in_height + 2;
  out_width = in_width + 2;

  // 画像データ入力
  for (int i = 0; i < in_height; i++) {
    for (int j = 0; j < in_width; j++) {
      cin >> picture.at(i).at(j);
      // cout << picture.at(i).at(j);
    }
  }
  for (int i = 0; i < out_height; i++) {
    for (int j = 0; j < out_width; j++) {
      if (i == 0 || i == (out_height - 1)) {
        cout << '#';
      } else if (j == 0 || j == (out_width - 1)) {
        cout << '#';
      } else {
        // 画像本体
        cout << picture.at(i - 1).at(j - 1);
      }
      if (j == out_width - 1)
        cout << endl;
    }
  }
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<char> pic(H * W);
  for (int i = 0; i < H * W; i++) {
    cin >> pic.at(i);
  }
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
  for (int j = 0; j < H; j++) {
    cout << "#";
    for (int k = 0; k < W; k++) {
      cout << pic.at(H * j + k);
    }
    cout << "#" << endl;
  }
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<char> pic(H * W);
  for (int i = 0; i < H * W; i++) {
    cin >> pic.at(i);
  }
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
  for (int j = 0; j < H; j++) {
    cout << "#";
    for (int k = 0; k < W; k++) {
      cout << pic.at(W * j + k);
    }
    cout << "#" << endl;
  }
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
}
Problem p03712 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int h, w;

  cin >> h >> w;
  char a[100][100];

  rep(i, h + 2) {
    rep(j, w + 2) { a[i][j] = '#'; }
  }

  rep(i, h) {
    rep(j, w) { cin >> a[i + 1][j + 1]; }
  }

  rep(i, h + 2) {
    rep(j, w + 2) { cout << a[i][j]; }
    cout << endl;
  }
  cout << endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int h, w;

  cin >> h >> w;
  char a[h + 2][w + 2];

  rep(i, h + 2) {
    rep(j, w + 2) { a[i][j] = '#'; }
  }

  rep(i, h) {
    rep(j, w) { cin >> a[i + 1][j + 1]; }
  }

  rep(i, h + 2) {
    rep(j, w + 2) { cout << a[i][j]; }
    cout << endl;
  }
  cout << endl;

  return 0;
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> M(W);

  for (int i = 0; i < H; i++) {
    cin >> M.at(i);
  }

  for (int i = 0; i < H + 2; i++) {

    if (i == 0 || i == H + 1) {
      for (int x = 0; x < W + 2; x++) {
        cout << '#';
      }
      cout << endl;
    } else {
      cout << '#' << M.at(i - 1) << '#' << endl;
    }
  }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> M(H);

  for (int i = 0; i < H; i++) {
    cin >> M.at(i);
  }

  for (int i = 0; i < H + 2; i++) {

    if (i == 0 || i == H + 1) {
      for (int x = 0; x < W + 2; x++) {
        cout << '#';
      }
      cout << endl;
    } else {
      cout << '#' << M.at(i - 1) << '#' << endl;
    }
  }
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<char> A;
  for (int cnt_h = 0; cnt_h < H; ++cnt_h) {
    for (int cnt_w = 0; cnt_w < W; ++cnt_w) {
      char tmp;
      cin >> tmp;
      A.push_back(tmp);
    }
  }

  for (int cnt_h = -1; cnt_h < H + 1; ++cnt_h) {
    for (int cnt_w = -1; cnt_w < W + 1; ++cnt_w) {
      if ((0 <= cnt_h) && (cnt_h < H) && (0 <= cnt_w) && (cnt_w < W)) {
        cout << A.at(cnt_h * H + cnt_w);
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }

  return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<char> A;
  for (int cnt_h = 0; cnt_h < H; ++cnt_h) {
    for (int cnt_w = 0; cnt_w < W; ++cnt_w) {
      char tmp;
      cin >> tmp;
      A.push_back(tmp);
    }
  }

  for (int cnt_h = -1; cnt_h < H + 1; ++cnt_h) {
    for (int cnt_w = -1; cnt_w < W + 1; ++cnt_w) {
      if ((0 <= cnt_h) && (cnt_h < H) && (0 <= cnt_w) && (cnt_w < W)) {
        cout << A.at(cnt_h * W + cnt_w);
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }

  return 0;
}
Problem p03712 (C++)

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

char h[105][105];

int main() {
  for (int i = 1; i <= 200; i++) {
    for (int j = 1; j <= 200; j++) {
      h[i][j] = '#';
    }
  }
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 2; i <= 2 + n - 1; i++) {
    for (int j = 2; j <= 2 + m - 1; j++) {
      char x;
      scanf(" %c", &x);
      h[i][j] = x;
    }
  }
  for (int i = 1; i <= n + 2; i++) {
    for (int j = 1; j <= m + 2; j++) {
      if (j == m + 2)
        printf("%c\n", h[i][j]);
      else
        printf("%c", h[i][j]);
    }
  }
}

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

char h[205][205];

int main() {
  for (int i = 1; i <= 200; i++) {
    for (int j = 1; j <= 200; j++) {
      h[i][j] = '#';
    }
  }
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 2; i <= 2 + n - 1; i++) {
    for (int j = 2; j <= 2 + m - 1; j++) {
      char x;
      scanf(" %c", &x);
      h[i][j] = x;
    }
  }
  for (int i = 1; i <= n + 2; i++) {
    for (int j = 1; j <= m + 2; j++) {
      if (j == m + 2)
        printf("%c\n", h[i][j]);
      else
        printf("%c", h[i][j]);
    }
  }
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < W + 2; i++)
    cout << "#";
  cout << endl;
  for (int i = 0; i < H; i++) {
    vector<string> moji(W);
    cin >> moji.at(i);
    cout << "#" + moji.at(i) + "#" << endl;
  }
  for (int i = 0; i < W + 2; i++)
    cout << "#";
  cout << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < W + 2; i++)
    cout << "#";
  cout << endl;
  for (int i = 0; i < H; i++) {
    vector<string> moji(H);
    cin >> moji.at(i);
    cout << "#" + moji.at(i) + "#" << endl;
  }
  for (int i = 0; i < W + 2; i++)
    cout << "#";
  cout << endl;
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;

  char a[H + 2][W + 2];

  for (int i = 0; i < W + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      a[i][j] = '#';
    }
  }

  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
}

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

int main() {
  int H, W;
  cin >> H >> W;

  char a[H + 2][W + 2];

  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      a[i][j] = '#';
    }
  }

  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;
  char a[100][100], b[101][101];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i <= H + 1; i++) {
    for (int j = 0; j <= W + 1; j++) {
      b[i][j] = '#';
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      b[i + 1][j + 1] = a[i][j];
    }
  }
  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      cout << b[i][j];
    }
    cout << endl;
  }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  char a[101][101], b[102][102];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i <= H + 1; i++) {
    for (int j = 0; j <= W + 1; j++) {
      b[i][j] = '#';
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      b[i + 1][j + 1] = a[i][j];
    }
  }
  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      cout << b[i][j];
    }
    cout << endl;
  }
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<char> A(H * W);
  for (int i = 0; i < A.size(); i++) {
    cin >> A.at(i);
  }

  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;

  for (int j = 0; j < H; j++) {
    cout << '#';
    for (int i = 0; i < W; i++) {
      cout << A.at(H * j + i);
    }
    cout << '#' << endl;
  }

  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<char> A(H * W);
  for (int i = 0; i < A.size(); i++) {
    cin >> A.at(i);
  }

  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;

  for (int j = 0; j < H; j++) {
    cout << '#';
    for (int i = 0; i < W; i++) {
      cout << A.at(W * j + i);
    }
    cout << '#' << endl;
  }

  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> a(W);

  for (int i = 0; i < H; i++) {
    cin >> a.at(i);
  }

  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;

  for (int i = 0; i < H; i++) {
    cout << "#" << a.at(i) << "#" << endl;
  }
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
}


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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> a(H);

  for (int i = 0; i < H; i++) {
    cin >> a.at(i);
  }

  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;

  for (int i = 0; i < H; i++) {
    cout << "#" << a.at(i) << "#" << endl;
  }
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
}
Problem p03712 (C++)

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

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  char x[55];
  for (int i = 0; i < w + 2; i++)
    printf("#");
  printf("\n");
  for (int i = 0; i < h; i++) {
    scanf("%s", x);
    printf("#%s#\n", x);
  }
  for (int i = 0; i < w + 2; i++)
    printf("#");
  printf("\n");
}


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

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  char x[110];
  for (int i = 0; i < w + 2; i++)
    printf("#");
  printf("\n");
  for (int i = 0; i < h; i++) {
    scanf("%s", x);
    printf("#%s#\n", x);
  }
  for (int i = 0; i < w + 2; i++)
    printf("#");
  printf("\n");
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;

  for (int i = 0; i < W + 2; i++)
    cout << "#";
  cout << endl;
  for (int i = 0; i < H; i++) {
    vector<string> vec(W);
    cin >> vec.at(i);
    cout << "#" + vec.at(i) + "#" << endl;
  }
  for (int i = 0; i < W + 2; i++)
    cout << "#";
  cout << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;

  for (int i = 0; i < W + 2; i++)
    cout << "#";
  cout << endl;
  for (int i = 0; i < H; i++) {
    vector<string> vec(H);
    cin >> vec.at(i);
    cout << "#" + vec.at(i) + "#" << endl;
  }
  for (int i = 0; i < W + 2; i++)
    cout << "#";
  cout << endl;
}
Problem p03712 (C++)

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

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) { return (a + b - 1) / b; }
int round(int a, int b) { return (a + b / 2) / b; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
template <class T> bool amax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool amin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

// main
int main() {
  int H, W;
  char a[50][50];
  cin >> H >> W;
  REP(i, H) {
    REP(j, W) { cin >> a[i][j]; }
  }
  REP(i, H + 2) {
    REP(j, W + 2) {
      if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
        cout << '#';
      } else {
        cout << a[i - 1][j - 1];
      }
    }
    cout << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) { return (a + b - 1) / b; }
int round(int a, int b) { return (a + b / 2) / b; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
template <class T> bool amax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool amin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

// main
int main() {
  int H, W;
  char a[100][100];
  cin >> H >> W;
  REP(i, H) {
    REP(j, W) { cin >> a[i][j]; }
  }
  REP(i, H + 2) {
    REP(j, W + 2) {
      if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
        cout << '#';
      } else {
        cout << a[i - 1][j - 1];
      }
    }
    cout << endl;
  }

  return 0;
}
Problem p03712 (C++)

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

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> a(h);
  rep(i, h) cin >> a[i];

  rep(i, w + 2) cout << '#';
  cout << "\n";
  rep(i, w - 1) cout << '#' << a[i] << '#' << endl;
  rep(i, w + 2) cout << '#';
  cout << "\n";

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> a(h);
  rep(i, h) cin >> a[i];

  rep(i, w + 2) cout << '#';
  cout << "\n";
  rep(i, h) cout << '#' << a[i] << '#' << endl;
  rep(i, w + 2) cout << '#';
  cout << "\n";

  return 0;
}
Problem p03712 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> a(H);

  for (int i = 0; i < W; i++) {
    cin >> a.at(i);
  }

  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }

  cout << endl; // 改行

  for (int i = 0; i < H; i++) {
    cout << "#" << a.at(i) << "#" << endl;
  }

  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }

  cout << endl; // 改行
}

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> a(H);

  for (int i = 0; i < H; i++) {
    cin >> a.at(i);
  }

  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }

  cout << endl; // 改行

  for (int i = 0; i < H; i++) {
    cout << "#" << a.at(i) << "#" << endl;
  }

  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }

  cout << endl; // 改行
}