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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int a;
  cin >> a;
  int n;
  n = a * a * a;
  return n;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a;
  cin >> a;
  int n;
  n = a * a * a;
  cout << n;
}
Problem p02915 (C++)

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

int main() {
  int n;
  std::cin >> n;
  return (n * n * n);
}

Fixed submission:
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  std::cout << n * n * n;
}
Problem p02915 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main() {

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

  ll n;
  cin >> n;

  cout << pow(n, 3) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main() {

  fast;

  ll n;
  cin >> n;

  cout << pow(n, 3) << endl;
}
Problem p02915 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int i;
  cin >> i;
  long long j = 1;
  while (i > 0) {
    j <<= 1;
  }
  cout << j;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int i;
  cin >> i;
  cout << i * i * i;
  return 0;
}
Problem p02915 (C++)

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

int main() {
  int N, Ans = 0;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    // cout << A[i] << endl;
  }
  int B[N];
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    // cout << B[i] << endl;
  }
  int C[N - 1];
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i];
    // cout << C[i] << endl;
  }
  for (int i = 0; i < N; i++) {
    Ans += B[A[i] - 1];
    if (i < N - 1) {
      if (A[i] == A[i + 1] - 1) {
        Ans += C[A[i] - 1];
      }
    }
  }

  cout << Ans << endl;
  return 0;
}

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

int main() {
  int a;
  cin >> a;
  cout << a * a * a << endl;
  return 0;
}
Problem p02916 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  for (int i = 0; i < n; i++)
    cin >> b.at(i);
  for (int i = 0; i < n - 1; i++)
    cin >> c.at(i);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += b.at(a.at(i) - 1);
    if (i > 0 && a.at(i) == a.at(i - 1) + 1)
      sum += c.at(a.at(i) - 1);
  }
  cout << sum << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  for (int i = 0; i < n; i++)
    cin >> b.at(i);
  for (int i = 0; i < n - 1; i++)
    cin >> c.at(i);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += b.at(a.at(i) - 1);
    if (i > 0 && a.at(i) == a.at(i - 1) + 1)
      sum += c.at(a.at(i) - 2);
  }
  cout << sum << endl;
}
Problem p02916 (C++)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int *a = (int *)malloc(n * sizeof(int));
  int *nxt = (int *)malloc(n * sizeof(int));
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++)
    nxt[a[i - 1]] = a[i];

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    ans += b;
  }
  for (int i = 1; i < n; i++) {
    int c;
    cin >> c;
    if (nxt[i] == i + 1)
      ans += c;
  }
  cout << ans;
  free(a);
  free(nxt);
  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int *a = (int *)malloc(n * sizeof(int));
  int *nxt = (int *)malloc((n + 1) * sizeof(int));
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++)
    nxt[a[i - 1]] = a[i];

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    ans += b;
  }
  for (int i = 1; i < n; i++) {
    int c;
    cin >> c;
    if (nxt[i] == i + 1)
      ans += c;
  }
  cout << ans;
  free(a);
  free(nxt);
  return 0;
}
Problem p02916 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

# 定義してないリストを参照するとエラーがでるからダミー置いといた。
A.append(100)
C.append(0)

total = 0

total = sum(B)

for i in range(1, N):
    if A[i] - A[i - 1] == 1:
        total += C[A[i] - 1 - 1]

print(total)

A = list(map(int, input().split()))
print(A)
print(sum(A))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

# 定義してないリストを参照するとエラーがでるからダミー置いといた。
A.append(100)
C.append(0)

total = 0

total = sum(B)

for i in range(1, N):
    if A[i] - A[i - 1] == 1:
        total += C[A[i] - 1 - 1]

print(total)
Problem p02916 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
if len(c) == 1:
    print(sum(b) + sum(c))
else:
    print(sum(b) + sum(c) - c[a[n - 1] - 1])


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = b[a[0] - 1]
for i in range(1, n):
    ans += b[a[i] - 1]
    if a[i] == a[i - 1] + 1:
        ans += c[a[i - 1] - 1]
print(ans)
Problem p02916 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    cnt += b[a[i]];
    if (a[i] + 1 == a[i + 1])
      cnt += c[a[i]];
  }
  cout << cnt << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(100), b(100), c(100);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    cnt += b[a[i]];
    if (a[i] + 1 == a[i + 1])
      cnt += c[a[i]];
  }
  cout << cnt << endl;
}
Problem p02916 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    cnt += b[a[i]];
    if (a[i] + 1 == a[i + 1])
      cnt += c[a[i]];
  }
  cout << cnt << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n + 1);
  vector<int> c(n);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    cnt += b[a[i]];
    if (a[i] + 1 == a[i + 1])
      cnt += c[a[i]];
  }
  cout << cnt << endl;
}
Problem p02916 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(0);
  vector<int> b(0);
  vector<int> c(0);

  int in;

  for (int i = 0; i < n; i++) {
    cin >> in;
    a.push_back(in);
  }

  for (int i = 0; i < n; i++) {
    cin >> in;
    b.push_back(in);
  }

  for (int i = 0; i < n - 1; i++) {
    cin >> in;
    c.push_back(in);
  }

  int ans = 0;

  for (int i = 0; i < n; i++) {
    ans += b.at(a.at(i) - 1);
    if (i > 0) {
      if (a.at(i) - a.at(i - 1) == 1) {
        ans += c.at(a.at(i) - 1);
      }
    }
  }

  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(0);
  vector<int> b(0);
  vector<int> c(0);

  int in;

  for (int i = 0; i < n; i++) {
    cin >> in;
    a.push_back(in);
  }

  for (int i = 0; i < n; i++) {
    cin >> in;
    b.push_back(in);
  }

  for (int i = 0; i < n - 1; i++) {
    cin >> in;
    c.push_back(in);
  }

  int ans = 0;

  for (int i = 0; i < n; i++) {
    ans += b.at(a.at(i) - 1);
    if (i > 0) {
      if (a.at(i) - a.at(i - 1) == 1) {
        ans += c.at(a.at(i - 1) - 1);
      }
    }
  }

  cout << ans << endl;
}
Problem p02916 (C++)

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

using namespace std;

int main() {
  int n, ans, temp;
  cin >> n;

  vector<int> a(20), b(50), c(50);

  rep(i, n) { cin >> a.at(i); }

  rep(i, n) { cin >> b.at(i); }

  rep(i, n - 1) { cin >> c.at(i); }

  ans = 0;

  rep(i, n) {
    temp = b.at(i);
    ans += temp;
  }

  rep(i, n - 1) {
    int FoodNo = a.at(i);
    if (FoodNo + 1 == a.at(i + 1)) {
      FoodNo = a.at(i);
      ans += c.at(FoodNo);
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main() {
  int n, ans, temp;
  cin >> n;

  vector<int> a(21), b(51), c(51);

  rep(i, n) { cin >> a.at(i); }

  rep(i, n) { cin >> b.at(i); }

  rep(i, n - 1) { cin >> c.at(i); }

  ans = 0;

  rep(i, n) {
    temp = b.at(i);
    ans += temp;
  }

  rep(i, n - 1) {
    int FoodNo = a.at(i);
    if (FoodNo + 1 == a.at(i + 1)) {
      FoodNo = a.at(i);
      ans += c.at(FoodNo);
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (b); i > (a); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long

signed main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  rootdada;
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  rep(i, 0, n - 1) cin >> c[i];
  int s = 0;
  rep(i, 0, n) {
    s += b[a[i] - 1];
    if ((i != 0) && a[i] == a[i - 1] + 1) {
      s += c[a[i - 1] - 1];
    }
  }
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (b); i > (a); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long

signed main() {

  rootdada;
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  rep(i, 0, n - 1) cin >> c[i];
  int s = 0;
  rep(i, 0, n) {
    s += b[a[i] - 1];
    if ((i != 0) && a[i] == a[i - 1] + 1) {
      s += c[a[i - 1] - 1];
    }
  }
  cout << s << endl;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  vector<int> B(N);
  for (int i = 0; i < N; i++)
    cin >> B.at(i);
  vector<int> C(N - 1);
  for (int i = 0; i < N - 1; i++)
    cin >> C.at(i);
  int sum = 0;
  for (int i = 0; i < N; i++)
    sum += B.at(i);

  for (int i = 0; i < N - 1; i++) {
    if (A.at(i + 1) - A.at(i) == 1)
      sum += C.at(A.at(i));
  }
  cout << sum << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  vector<int> B(N);
  for (int i = 0; i < N; i++)
    cin >> B.at(i);
  vector<int> C(N - 1);
  for (int i = 0; i < N - 1; i++)
    cin >> C.at(i);
  int sum = 0;
  for (int i = 0; i < N; i++)
    sum += B.at(i);

  for (int i = 0; i < N - 1; i++) {
    if (A.at(i + 1) - A.at(i) == 1)
      sum += C.at(A.at(i) - 1);
  }
  cout << sum << endl;

  return 0;
}
Problem p02916 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  // vector<int> b(n);
  int ans = 0;
  int tmp;
  vector<int> c(n - 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    ans += tmp;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) + 1 == a.at(i + 1)) {
      ans += c.at(a.at(i));
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  // vector<int> b(n);
  int ans = 0;
  int tmp;
  vector<int> c(n - 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    ans += tmp;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) + 1 == a.at(i + 1)) {
      ans += c.at(a.at(i) - 1);
    }
  }
  cout << ans << endl;
}
Problem p02916 (C++)

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

int main() {
  int N;
  int tManzoku = 0;
  cin >> N;
  vector<int> Ryouri(N);
  vector<int> Manzoku(N);
  vector<int> mBonus(N - 1);
  for (int i = 0; i < N; i++)
    cin >> Ryouri.at(i);
  for (int i = 0; i < N; i++)
    cin >> Manzoku.at(i);
  for (int i = 0; i < N - 1; i++)
    cin >> mBonus.at(i);
  for (int i = 0; i < N; i++) {
    if (i == 0)
      tManzoku += Manzoku.at(Ryouri.at(i) - 1);
    else {
      if (Ryouri.at(i) - 1 == Ryouri.at(i - 1))
        tManzoku += Manzoku.at(Ryouri.at(i) - 1) + mBonus.at(i - 2);
      else {
        tManzoku += Manzoku.at(Ryouri.at(i) - 1);
      }
    }
  }
  cout << tManzoku << endl;
}

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

int main() {
  int N;
  int tManzoku = 0;
  cin >> N;
  vector<int> Ryouri(N);
  vector<int> Manzoku(N);
  vector<int> mBonus(N - 1);
  for (int i = 0; i < N; i++)
    cin >> Ryouri.at(i);
  for (int i = 0; i < N; i++)
    cin >> Manzoku.at(i);
  for (int i = 0; i < N - 1; i++)
    cin >> mBonus.at(i);
  for (int i = 0; i < N; i++) {
    tManzoku += Manzoku.at(Ryouri.at(i) - 1);
    if (i != 0 && Ryouri.at(i - 1) + 1 == Ryouri.at(i))
      tManzoku += mBonus.at(Ryouri.at(i - 1) - 1);
  }
  cout << tManzoku << endl;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int cnt;
int ans;

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N - 1);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  for (int i = 0; i < N; i++)
    cin >> B.at(i);
  for (int i = 0; i < N - 1; i++)
    cin >> C.at(i);
  int tmp;
  for (auto &i : A) {
    if (i == tmp + 1)
      ans += (B.at(i - 1) + C.at(tmp - 1));
    else
      ans += B.at(i - 1);
    tmp = i;
  }
  cout << ans << endl;
}


Fixed submission:
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int cnt;
int ans;

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N - 1);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  for (int i = 0; i < N; i++)
    cin >> B.at(i);
  for (int i = 0; i < N - 1; i++)
    cin >> C.at(i);
  int tmp = -1;
  for (auto &i : A) {
    if (i == tmp + 1)
      ans += (B.at(i - 1) + C.at(tmp - 1));
    else
      ans += B.at(i - 1);
    tmp = i;
  }
  cout << ans << endl;
}
Problem p02916 (C++)

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

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

  vector<int> A(N), B(N), C(N - 1);

  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  for (int i = 0; i < N; i++)
    cin >> B.at(i);
  for (int i = 0; i < N - 1; i++)
    cin >> C.at(i);

  int ans = 0;

  for (int i = 0; i < N; i++) {
    ans += B.at(i);
  }

  for (int i = 1; i < N; i++) {
    if (A.at(i) - 1 == A.at(i - 1)) {
      ans += C.at(i);
    }
  }

  cout << ans << endl;
}


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

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

  vector<int> A(N), B(N), C(N - 1);

  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  for (int i = 0; i < N; i++)
    cin >> B.at(i);
  for (int i = 0; i < N - 1; i++)
    cin >> C.at(i);

  int ans = 0;

  for (int i = 0; i < N; i++) {
    ans += B.at(i);
  }

  for (int i = 1; i < N; i++) {
    if (A.at(i) - 1 == A.at(i - 1)) {
      ans += C.at(A.at(i) - 2);
    }
  }

  cout << ans << endl;
}
Problem p02916 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int ans;
  ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  vector<int> C(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> C.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) + 1 == A.at(i + 1)) {
      ans += C.at(A.at(i));
    }
  }
  for (int i = 0; i < N; i++) {
    ans += B.at(i);
  }
  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int ans;
  ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  vector<int> C(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> C.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) + 1 == A.at(i + 1)) {
      ans += C.at(A.at(i) - 1);
    }
  }
  for (int i = 0; i < N; i++) {
    ans += B.at(i);
  }
  cout << ans << endl;
}
Problem p02916 (C++)

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

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (auto &i : a)
    cin >> i;
  for (auto &i : b)
    cin >> i;
  for (auto &i : c)
    cin >> i;
  int sut = 0;
  int prex = 0;
  for (auto xa : a) {
    sut += b.at(xa - 1);
    if (xa == prex + 1)
      sut += c.at(xa - 2);
    prex = xa;
  }
  cout << sut << endl;
  return 0;
}


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

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (auto &i : a)
    cin >> i;
  for (auto &i : b)
    cin >> i;
  for (auto &i : c)
    cin >> i;
  int sut = 0;
  int prex = 0;
  for (auto xa : a) {
    sut += b.at(xa - 1);
    if (xa >= 2 && xa == prex + 1)
      sut += c.at(xa - 2);
    prex = xa;
  }
  cout << sut << endl;
  return 0;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
  if (r > n - r)
    r = n - r; // because C(n, r) == C(n, n - r)
  long long ans = 1;
  int i;

  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }

  return ans;
}
ll mod(ll a, ll b, ll m) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    ll y = mod(a, b / 2, m);
    return (y * y) % m;
  } else {
    return ((a % m) * mod(a, b - 1, m)) % m;
  }
}

ll modinv(ll a, ll m) {
  return mod(a, m - 2, m);
  // works only for prime m.
  // else calculate phi(m)-1.
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];
  for (int i = 1; i <= n - 1; i++)
    cin >> c[i];
  int p = -1;
  for (int i = 1; i <= n; i++) {

    ans += b[a[i]];
    if (a[i] == p + 1)
      ans += c[a[i] - 1];
    p = a[i];
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
  if (r > n - r)
    r = n - r; // because C(n, r) == C(n, n - r)
  long long ans = 1;
  int i;

  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }

  return ans;
}
ll mod(ll a, ll b, ll m) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    ll y = mod(a, b / 2, m);
    return (y * y) % m;
  } else {
    return ((a % m) * mod(a, b - 1, m)) % m;
  }
}

ll modinv(ll a, ll m) {
  return mod(a, m - 2, m);
  // works only for prime m.
  // else calculate phi(m)-1.
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1), b(n + 1), c(n + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];
  for (int i = 1; i <= n - 1; i++)
    cin >> c[i];
  int p = -1;
  for (int i = 1; i <= n; i++) {

    ans += b[a[i]];
    if (a[i] == p + 1)
      ans += c[a[i] - 1];
    p = a[i];
  }
  cout << ans;
  return 0;
}
Problem p02916 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int>> vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int INF = 1e9 + 5;
int main() {
  int n;
  cin >> n;
  vi a;
  vi b;
  vi c;
  int x;

  for (int i = 0; i < n; i++) {
    cin >> x;
    a.pb(x);
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    b.pb(x);
  }

  while (true) {
    int input;
    cin >> input;
    if (input == -100)
      break;
    c.pb(input);
  }

  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += b[a[i] - 1];
  }
  for (int i = 0; i < (n - 1); i++) {
    if ((a[i + 1] - a[i]) == 1) {
      sum += c[a[i] - 1];
    }
  }
  cout << sum;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int>> vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int INF = 1e9 + 5;
int main() {
  int n;
  cin >> n;
  vi a;
  vi b;
  vi c;
  int x;

  for (int i = 0; i < n; i++) {
    cin >> x;
    a.pb(x);
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    b.pb(x);
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    c.pb(x);
  }

  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += b[a[i] - 1];
  }
  for (int i = 0; i < (n - 1); i++) {
    if ((a[i + 1] - a[i]) == 1) {
      sum += c[a[i] - 1];
    }
  }
  cout << sum;
}
Problem p02916 (C++)

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

#define rep(i, n) for (int i = 1; i <= (int)n; i++)
#define rep2(i, m, n) for (int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; // 2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;

/*FUNCs=================================================*/

/*MAIN==================================================*/
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false); // cin cout 高速化

  int n;
  cin >> n;
  vi a(n), b(n), c(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  c.push_back(-100);

  int cnt = 0;
  int pre_I = -100;
  rep(i, n) {
    int I = a[i];
    cnt += b[I];
    if (I == pre_I + 1)
      cnt += c[pre_I];
    pre_I = I;
  }
  cout << cnt << '\n';
}

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

#define rep(i, n) for (int i = 1; i <= (int)n; i++)
#define rep2(i, m, n) for (int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; // 2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;

/*FUNCs=================================================*/

/*MAIN==================================================*/
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false); // cin cout 高速化

  int n;
  cin >> n;
  vi a(n + 1), b(n + 1), c(n + 1);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  c.push_back(-100);

  int cnt = 0;
  int pre_I = -100;
  rep(i, n) {
    int I = a[i];
    cnt += b[I];
    if (I == pre_I + 1)
      cnt += c[pre_I];
    pre_I = I;
  }
  cout << cnt << '\n';
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }

  int satis = 0;
  for (int i = 0; i < n; i++) {
    satis += b.at(a.at(i) - 1);
  }
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) == a.at(i + 1) - 1)
      satis += c.at(i + 1);
  }
  cout << satis << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }

  int satis = 0;
  for (int i = 0; i < n; i++) {
    satis += b.at(a.at(i) - 1);
  }
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) == a.at(i + 1) - 1)
      satis += c.at(a.at(i) - 1);
  }
  cout << satis << endl;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
/* ****mittal**** */
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define repr(i, a, b) for (ll int i = a; i >= b; i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define mp make_pair
using namespace std;

#define N 100005
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  //  cin>>TESTS;
  while (TESTS--) {
    ll n;
    cin >> n;
    ll a[28], b[28], c[28];
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
    }
    a[0] = 500;
    for (int i = 1; i <= n - 1; i++)
      cin >> c[i];
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
      ans += b[a[i]];
      if (a[i] = a[i - 1] + 1)
        ans += c[a[i]];
    }
    cout << ans;
  }
  return 0;
}

Fixed submission:
/* ****mittal**** */
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define repr(i, a, b) for (ll int i = a; i >= b; i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define mp make_pair
using namespace std;

#define N 100005
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  //  cin>>TESTS;
  while (TESTS--) {
    ll n;
    cin >> n;
    ll a[28], b[28], c[28];
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
    }
    a[0] = 500;
    for (int i = 1; i <= n - 1; i++)
      cin >> c[i];
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
      ans += b[a[i]];
      if (a[i] == a[i - 1] + 1)
        ans += c[a[i - 1]];
    }
    cout << ans;
  }
  return 0;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
using namespace std;
signed main() {
  int a;
  cin >> a;
  vector<int> b(a);
  vector<int> c(a);
  vector<int> d(a - 1);
  rep(i, a) cin >> b.at(i);
  rep(i, a) cin >> c.at(i);
  rep(i, a - 1) cin >> d.at(i);
  int e = 0;
  rep(i, a) e += c.at(i);
  rep(i, a - 1) e += d.at(i);
  if (b.at(a - 1) == a)
    cout << e;
  else
    cout << e - d.at(b.at(a - 1));
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
using namespace std;
signed main() {
  int a;
  cin >> a;
  vector<int> b(a);
  vector<int> c(a);
  vector<int> d(a - 1);
  rep(i, a) cin >> b.at(i);
  rep(i, a) cin >> c.at(i);
  rep(i, a - 1) cin >> d.at(i);
  int e = 0;
  rep(i, a) e += c.at(i);
  rep(i, a - 1) {
    if (b.at(i) + 1 == b.at(i + 1))
      e += d.at(b.at(i) - 1);
  }
  cout << e;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, f, n) for (int(i) = (f); i < (n); i++)
#define LL long long int

/*
greater<int>()
sortの第三因数に入れて降順
sqrt(double) √を求める
pair<int,int> x=make_pair(a,b)
x.first
tuple
get<番目>(変数名)
*/
using namespace std;

LL lcm(LL n, LL m) {
  LL u;
  LL ansl = 0;
  for (u = m; u >= m; u++) {
    if (u % n == 0) {
      if (u % m == 0) {
        ansl = u;
        break;
      }
    }
  }
  return ansl;
}

int main(void) {

  int n;
  cin >> n;

  vector<int> a(n), b(n), c(n);
  rep(i, 1, n + 1) { scanf("%d", &a[i]); }
  rep(i, 1, n + 1) { scanf("%d", &b[i]); }

  rep(i, 1, n) { scanf("%d", &c[i]); }
  int mae = 6000;
  int ans = 0;
  rep(i, 1, n + 1) {
    if (a[i] == mae + 1) {
      ans += c[mae];
    }
    ans += b[a[i]];
    mae = a[i];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, f, n) for (int(i) = (f); i < (n); i++)
#define LL long long int

/*
greater<int>()
sortの第三因数に入れて降順
sqrt(double) √を求める
pair<int,int> x=make_pair(a,b)
x.first
tuple
get<番目>(変数名)
*/
using namespace std;

LL lcm(LL n, LL m) {
  LL u;
  LL ansl = 0;
  for (u = m; u >= m; u++) {
    if (u % n == 0) {
      if (u % m == 0) {
        ansl = u;
        break;
      }
    }
  }
  return ansl;
}

int main(void) {

  int n;
  cin >> n;

  int a[n + 1], b[n + 1], c[n + 1];
  rep(i, 1, n + 1) { scanf("%d", &a[i]); }
  rep(i, 1, n + 1) { scanf("%d", &b[i]); }

  rep(i, 1, n) { scanf("%d", &c[i]); }
  int mae = 6000;
  int ans = 0;
  rep(i, 1, n + 1) {
    if (a[i] == mae + 1) {
      ans += c[mae];
    }
    ans += b[a[i]];
    mae = a[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02916 (C++)

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

int main() {
  int n, sum = 0;
  cin >> n;

  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }

  for (int i = 0; i < n; i++) {
    sum += b.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) + 1 == a.at(i + 1)) {
      sum += c.at(i - 1);
    }
  }
  cout << sum;
}

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

int main() {
  int n, sum = 0;
  cin >> n;

  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }

  for (int i = 0; i < n; i++) {
    sum += b.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) + 1 == a.at(i + 1)) {
      sum += c.at(a.at(i) - 1);
    }
  }
  cout << sum;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  int ans = 0;
  rep(i, N) { cin >> A[i]; }
  rep(i, N) {
    cin >> B[i];
    ans += B[i];
  }
  rep(i, N) { cin >> C[i]; }
  rep(i, N) {
    if (A[i + 1] = A[i] + 1)
      ans += C[A[i] - 1];
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  int ans = 0;
  rep(i, N) { cin >> A[i]; }
  rep(i, N) {
    cin >> B[i];
    ans += B[i];
  }
  rep(i, N) { cin >> C[i]; }
  rep(i, N - 1) {
    if (A[i + 1] == A[i] + 1)
      ans += C[A[i] - 1];
  }
  cout << ans;
  return 0;
}
Problem p02916 (C++)

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

using namespace std;

int MOD = 1000000007;
int main(void) {
  int N, ans = 0;
  cin >> N;
  int A[N + 10], B[N + 10], C[N + 10];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N; i++)
    cin >> B[i];
  for (int i = 0; i < N - 1; i++)
    cin >> C[i];
  for (int i = 0; i < N; i++) {
    if (i != 0 && A[i - 1] + 1 == A[i]) {
      ans += C[A[i - 2]];
    }
    ans += B[A[i] - 1];
  }
  cout << ans << endl;
}


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

using namespace std;

int MOD = 1000000007;
int main(void) {
  int N, ans = 0;
  cin >> N;
  int A[N + 10], B[N + 10], C[N + 10];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N; i++)
    cin >> B[i];
  for (int i = 0; i < N - 1; i++)
    cin >> C[i];
  for (int i = 0; i < N; i++) {
    if (i != 0 && A[i - 1] + 1 == A[i]) {
      ans += C[A[i - 1] - 1];
    }
    ans += B[A[i] - 1];
  }
  cout << ans << endl;
}
Problem p02916 (C++)

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

int main() {
  int N;
  scanf("%d", &N);

  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A.at(i));
    A.at(i)--;
  }

  vector<int> B(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &B.at(i));
  }

  vector<int> C(N - 1, 0);
  for (int i = 0; i < N - 1; i++) {
    scanf("%d", &C.at(i));
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += B.at(A.at(i));
    if (i > 0 && A.at(i) == A.at(i - 1) - 1) {
      ans += C.at(A.at(i - 1));
    }
  }

  printf("%d", ans);
  return 0;
}


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

int main() {
  int N;
  scanf("%d", &N);

  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A.at(i));
    A.at(i)--;
  }

  vector<int> B(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &B.at(i));
  }

  vector<int> C(N - 1, 0);
  for (int i = 0; i < N - 1; i++) {
    scanf("%d", &C.at(i));
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += B.at(A.at(i));
    if (i > 0 && A.at(i) == A.at(i - 1) + 1) {
      ans += C.at(A.at(i - 1));
    }
  }

  printf("%d", ans);
  return 0;
}
Problem p02916 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <iostream>
#include <string>

int main(void) {
  //
  int N;
  N = 0;
  std::cin >> N;
  // A
  int *A = new int[N]();
  int *B = new int[N]();
  int *C = new int[N]();
  for (int i = 1; i <= N; i++) {
    while (!(std::cin >> A[i])) {
    }
    // std::cout << A[i] << std::endl;
    //
  }
  // B
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    while (!(std::cin >> B[i])) {
    }
  }
  // C
  for (int i = 1; i < N; i++) {
    sum += B[A[i]];
    // std::cout << B[A[i]] << std::endl;
    // std::cout << sum << std::endl;
    while (!(std::cin >> C[i])) {
    }
  }
  sum += B[A[N]];
  for (int i = 1; i < N; i++) {
    if (A[i] + 1 == A[i + 1]) {
      sum += C[A[i]];
    }
    // std::cout << sum << std::endl;
  }
  //

  std::cout << sum << std::endl;
  while (1) {
  }
  return 0;
}


Fixed submission:

#include <iostream>
#include <string>

int main(void) {
  //
  int N;
  N = 0;
  std::cin >> N;
  // A
  int *A = new int[N]();
  int *B = new int[N]();
  int *C = new int[N]();
  for (int i = 1; i <= N; i++) {
    while (!(std::cin >> A[i])) {
    }
    // std::cout << A[i] << std::endl;
    //
  }
  // B
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    while (!(std::cin >> B[i])) {
    }
  }
  // C
  for (int i = 1; i < N; i++) {
    sum += B[A[i]];
    // std::cout << B[A[i]] << std::endl;
    // std::cout << sum << std::endl;
    while (!(std::cin >> C[i])) {
    }
  }
  sum += B[A[N]];
  for (int i = 1; i < N; i++) {
    if (A[i] + 1 == A[i + 1]) {
      sum += C[A[i]];
    }
    // std::cout << sum << std::endl;
  }
  //

  std::cout << sum << std::endl;
  return 0;
}
Problem p02916 (C++)

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

int main() {
  int A;
  cin >> A;
  vector<int> b(A + 1);
  vector<int> c(A + 1);
  vector<int> d(A + 1);
  int ans = 0;

  for (int i = 0; i < A; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < A; i++) {
    cin >> c.at(i);
  }
  for (int i = 0; i < A - 1; i++) {
    cin >> d.at(i);
  }
  for (int i = 0; i < A; i++) {
    ans += c.at(b.at(i) - 1);
    if (b.at(i) == b.at(i + 1) - 1)
      ;
    ans += d.at(i - 1);
  }
  cout << ans << endl;
}


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

int main() {
  int A;
  cin >> A;
  vector<int> b(A + 1);
  vector<int> c(A + 1);
  vector<int> d(A + 1);
  int ans = 0;

  for (int i = 0; i < A; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < A; i++) {
    cin >> c.at(i);
  }
  for (int i = 0; i < A - 1; i++) {
    cin >> d.at(i);
  }
  for (int i = 0; i < A; i++) {
    ans += c.at(b.at(i) - 1);
    if (b.at(i) == b.at(i + 1) - 1) {
      ans += d.at(b.at(i) - 1);
    }
  }
  cout << ans << endl;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int chk = -1;
  int pnt = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);

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

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

  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }

  for (int i = 0; i < n; i++) {
    int x = a.at(i) - 1;
    pnt += b.at(x);
    if (x - 1 == chk) {
      pnt += c.at(x - 1);
    }
    chk = x;
  }

  cout << pnt << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int chk = -1;
  int pnt = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);

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

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

  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }

  for (int i = 0; i < n; i++) {
    int x = a.at(i) - 1;
    pnt += b.at(x);
    if (x - 1 == chk && x != 0) {
      pnt += c.at(x - 1);
    }
    chk = x;
  }

  cout << pnt << endl;
  return 0;
}
Problem p02916 (C++)

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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> a{0}, b{0}, c{0};
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < n; ++i)
    cin >> b[i];
  for (int i = 0; i < n - 1; ++i)
    cin >> c[i];

  for (int i = 0; i < n; ++i) {
    ans += b[a[i] - 1];
    if (a[i] + 1 == a[i + 1] && a[i + 1] != 0) {
      ans += c[a[i] - 1];
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  int n, ans = 0;
  cin >> n;
  int a[n], b[n], c[n - 1];
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < n; ++i)
    cin >> b[i];
  for (int i = 0; i < n - 1; ++i)
    cin >> c[i];

  for (int i = 0; i < n; ++i) {
    ans += b[a[i] - 1];
    if (a[i] + 1 == a[i + 1] && a[i + 1] != 0) {
      ans += c[a[i] - 1];
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02916 (C++)

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

int main() {

  int n;
  cin >> n;
  int ans = 0;
  int before = n + 1;
  vector<int> a(n), b(n), c(n - 1);

  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  for (int i = 0; i < n; i++)
    cin >> b.at(i);
  for (int i = 0; i < n - 1; i++)
    cin >> c.at(i);

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

    ans += b.at(a.at(i) - 1);
    if (a.at(i) - 1 == before)
      ans += c.at(a.at(i) - 1);
    before = a.at(i);
  }
  cout << ans << endl;

  return 0;
}

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

int main() {

  int n;
  cin >> n;
  int ans = 0;
  int before = n + 1;
  vector<int> a(n), b(n), c(n - 1);

  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  for (int i = 0; i < n; i++)
    cin >> b.at(i);
  for (int i = 0; i < n - 1; i++)
    cin >> c.at(i);

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

    ans += b.at(a.at(i) - 1);
    if (a.at(i) - 1 == before)
      ans += c.at(a.at(i) - 2);
    before = a.at(i);
  }
  cout << ans << endl;

  return 0;
}
Problem p02916 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define pp pair<int, int>
const int INF = 1001001001;
// int 2×10の9乗

// vector<vector<int>> a(n, vector<int>(m));
// rep(i,n){
// rep(j,m) cin >> a[i][j];
//}

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];
  for (int i = 1; i <= n - 1; i++)
    cin >> c[i];
  int ans = b[a[1]];
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1] + 1)
      ans += b[a[i]] + c[a[i - 1]];
    else
      ans += b[a[i]];
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define pp pair<int, int>
const int INF = 1001001001;
// int 2×10の9乗

// vector<vector<int>> a(n, vector<int>(m));
// rep(i,n){
// rep(j,m) cin >> a[i][j];
//}

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n - 1) cin >> c[i];
  rep(i, n) a[i]--;
  int ans = 0;
  rep(i, n) ans += b[a[i]];
  rep(i, n - 1) {
    if (a[i] + 1 == a[i + 1])
      ans += c[a[i]];
  }
  cout << ans << endl;
}
Problem p02916 (C++)

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

int main() {
  int n, a[n], b[n], c[n - 1];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i <= n; i++) {
    cin >> c[i];
  }
  int score = b[a[0] - 1];
  for (int i = 1; i < n; i++) {
    score += b[a[i] - 1];
    if (a[i] - a[i - 1] == 1)
      score += c[a[i - 1] - 1];
  }
  cout << score;
  return 0;
}


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

int main() {
  int n, a[21], b[21], c[21];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i <= n; i++) {
    cin >> c[i];
  }
  int score = b[a[0] - 1];
  for (int i = 1; i < n; i++) {
    score += b[a[i] - 1];
    if (a[i] - a[i - 1] == 1)
      score += c[a[i - 1] - 1];
  }
  cout << score;
  return 0;
}
Problem p02917 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[21], b[21], s = 0;
  cin >> n;
  for (int i = 1; i <= n - 1; i++)
    scanf("%d", &b[i]);
  for (int i = n - 1; i >= 1; i--) {
    if (i == n - 1) {
      a[i + 1] = b[i];
      a[i] = b[i];
    } else if (b[i] < a[i + 1]) {
      a[i + 1] = b[i];
      a[i] = b[i];
    } else
      a[i] = b[i];
  }
  for (int i = 1; i <= n; i++)
    s += a[i];
  cout << s;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[101], b[101], s = 0;
  cin >> n;
  for (int i = 1; i <= n - 1; i++)
    scanf("%d", &b[i]);
  for (int i = n - 1; i >= 1; i--) {
    if (i == n - 1) {
      a[i + 1] = b[i];
      a[i] = b[i];
    } else if (b[i] < a[i + 1]) {
      a[i + 1] = b[i];
      a[i] = b[i];
    } else
      a[i] = b[i];
  }
  for (int i = 1; i <= n; i++)
    s += a[i];
  cout << s;
  return 0;
}