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

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

/* define */
#define Yes(X) puts((X) ? "Yes" : "No")
#define YES(X) puts((X) ? "YES" : "NO")
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1000000007;

/* alias */
typedef long long ll;
typedef unsigned u;

/* function */
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int cmp2(const void *a, const void *b) { return *(int *)b - *(int *)a; }
int gcd(int a, int b) {
  if (b != 0)
    return gcd(b, a % b);
  return a;
}
ll Lgcd(ll a, ll b) {
  if (b != 0)
    return Lgcd(b, a % b);
  return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
ll Llcm(ll a, ll b) { return a / Lgcd(a, b) * b; }

/* main */

int main() {
  int n, h[10000] = {0}, f = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    if (h[i] > h[i - 1])
      h[i]--;
    if (h[i] < h[i - 1])
      f = 0;
  }
  Yes(f);
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

/* define */
#define Yes(X) puts((X) ? "Yes" : "No")
#define YES(X) puts((X) ? "YES" : "NO")
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1000000007;

/* alias */
typedef long long ll;
typedef unsigned u;

/* function */
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int cmp2(const void *a, const void *b) { return *(int *)b - *(int *)a; }
int gcd(int a, int b) {
  if (b != 0)
    return gcd(b, a % b);
  return a;
}
ll Lgcd(ll a, ll b) {
  if (b != 0)
    return Lgcd(b, a % b);
  return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
ll Llcm(ll a, ll b) { return a / Lgcd(a, b) * b; }

/* main */

int main() {
  int n, h[100000] = {0}, f = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    if (h[i] > h[i - 1])
      h[i]--;
    if (h[i] < h[i - 1])
      f = 0;
  }
  Yes(f);
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep0(i, n) for (int i = 0; i <= (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define REP(a, b) for (int ii = a; ii <= (b); ++ii)
#define mREP(a, b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  /*
  　　　　　 　 _... ..._
  　　　　　 , ´⌒ ⌒ヽ
  　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
  　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
  　　　　　　△ﾑ,8ﾑﾌつ
  　　　　　/(ﾝ_/＿ヽ＼
  　　　　 ～～i_ﾌ_ﾌ～´
  */
  int n;
  cin >> n;
  vector<ll> a(n);
  ll temp = -1;
  bool sc = true;
  rep0(i, n - 1) { scanf("%lld", a[i]); }
  rep0(j, n - 1) {
    if (temp > a[j]) {
      sc = false;
    } else if (temp < a[j]) {
      temp = a[j] - 1;
    } else {
      temp = a[j];
    }
  }
  cout << ((sc) ? "Yes" : "No") << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep0(i, n) for (int i = 0; i <= (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define REP(a, b) for (int ii = a; ii <= (b); ++ii)
#define mREP(a, b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  /*
  　　　　　 　 _... ..._
  　　　　　 , ´⌒ ⌒ヽ
  　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
  　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
  　　　　　　△ﾑ,8ﾑﾌつ
  　　　　　/(ﾝ_/＿ヽ＼
  　　　　 ～～i_ﾌ_ﾌ～´
  */
  int n;
  cin >> n;
  vector<ll> a(n);
  ll temp = -1;
  bool sc = true;
  rep0(i, n - 1) { scanf("%lld", &a[i]); }
  rep0(j, n - 1) {
    if (temp > a[j]) {
      sc = false;
    } else if (temp < a[j]) {
      temp = a[j] - 1;
    } else {
      temp = a[j];
    }
  }
  cout << ((sc) ? "Yes" : "No") << endl;
  return 0;
}
Problem p02953 (C++)

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

using namespace std;

int main() {
  int n, i, j;
  cin >> n;
  int h[n];
  for (i = 0; i < n; i++) {
    cin >> h[i];
  }
  string ans = "Yes";

  for (i = 0; i < n - 1; i++) {
    if (ans == "No")
      break;
    for (j = i + 1; j < n; j++) {
      if (h[i] - h[j] >= 2) {
        ans = "No";
        break;
      }
    }
  }

  cout << ans << endl;
}

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

using namespace std;

int main() {
  int n, i, j;
  cin >> n;
  int h[n];
  for (i = 0; i < n; i++) {
    cin >> h[i];
  }
  string ans = "Yes";

  int maxh[n];
  int max = 0;
  for (i = 0; i < n; i++) {
    if (max <= h[i]) {
      max = h[i];
      maxh[i] = max;
    } else
      maxh[i] = max;
  }

  for (i = 0; i < n; i++) {
    if (maxh[i] - h[i] >= 2)
      ans = "No";
  }

  cout << ans << endl;
}
Problem p02953 (Python)

Buggy submission (status: Runtime Error):
"""
https://atcoder.jp/contests/abc136/tasks/abc136_c
"""

import numpy as np


def calc(N: int, values: np.ndarray) -> bool:
    # 要素が1つなら確定でOK
    if len(values) == 1:
        return True

    # 2つ以上下がっている部分があるとNG
    gradient = np.diff(values)
    if np.min(gradient) <= -2:
        return False

    # 要素が2つでならこの時点でOK確定
    if len(values) == 2:
        return True

    # 1つ下がってから、上がる前に、1つ下がるとNG
    gradient_without_zero = gradient[gradient != 0]
    gradient_without_last = gradient_without_zero[:-1]
    gradient_without_first = gradient_without_zero[1:]
    if np.min(gradient_without_first + gradient_without_last) <= -2:
        return False
    return True


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    (N,) = load_input_as_int_array()
    values = load_input_as_int_array()
    result = calc(N, values)
    print("Yes" if result else "No")


main()


Fixed submission:
"""
https://atcoder.jp/contests/abc136/tasks/abc136_c
"""

import numpy as np


def calc(N: int, values: np.ndarray) -> bool:
    # 要素が1つなら確定でOK
    if len(values) == 1:
        return True

    # 2つ以上下がっている部分があるとNG
    gradient = np.diff(values)
    if np.min(gradient) <= -2:
        return False

    # 要素が2つでならこの時点でOK確定
    if len(values) == 2:
        return True

    # 1つ下がってから、上がる前に、1つ下がるとNG
    gradient_without_zero = gradient[gradient != 0]
    if len(gradient_without_zero) == 0:
        return True
    gradient_without_last = gradient_without_zero[:-1]
    gradient_without_first = gradient_without_zero[1:]
    if np.min(gradient_without_first + gradient_without_last) <= -2:
        return False
    return True


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    (N,) = load_input_as_int_array()
    values = load_input_as_int_array()
    result = calc(N, values)
    print("Yes" if result else "No")


main()
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7; // 10^9+7

int main() {
  int n;
  ll h[200000];
  int sw[200000];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    sw[i] = 0;
  }
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  int flg = 0;
  for (int i = 0; i < n - 1; i++) {
    if (h[i] > h[i + 1] + 1) {
      flg = 1;
    } else if (h[i] == h[i + 1] + 1) {
      h[i]--;
      sw[i] = 1;
      for (int j = i; j > 0; j--) {
        if (h[j - 1] > h[j] + 1) {
          flg = 1;
          break;
        } else if (h[j - 1] == h[j] + 1) {
          if (sw[j - 1] == 1) {
            flg = 1;
            break;
          } else {
            h[j - 1]--;
            sw[j - 1] = 1;
          }
        }
      }
    }
    if (flg == 1)
      break;
  }

  if (flg == 1)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7; // 10^9+7

int main() {
  int n;
  ll h[200000];
  int sw[200000];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    sw[i] = 0;
  }
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  int flg = 0;
  for (int i = 0; i < n - 1; i++) {
    if (h[i] > h[i + 1] + 1) {
      flg = 1;
    } else if (h[i] == h[i + 1] + 1) {
      h[i]--;
      sw[i] = 1;
      for (int j = i; j > 0; j--) {
        if (h[j - 1] > h[j] + 1) {
          flg = 1;
          break;
        } else if (h[j - 1] == h[j] + 1) {
          if (sw[j - 1] == 1) {
            flg = 1;
            break;
          } else {
            h[j - 1]--;
            sw[j - 1] = 1;
          }
        } else if (h[j - 1] <= h[j]) {
          break;
        }
      }
    }
    if (flg == 1)
      break;
  }

  if (flg == 1)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> arr(n);
  vector<bool> v(n, false);

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

  bool flag = true;

  for (int i = 1; i < n && i >= 0;) {

    if (arr[i - 1] - arr[i] > 1) {
      flag = false;
      break;
    } else if (arr[i] - arr[i - 1] >= 0) {
      i++;
      continue;
    } else if (arr[i - 1] > arr[i]) {

      while (i > 0 && arr[i - 1] > arr[i]) {
        if (v[i - 1] == false) {
          arr[i - 1]--;
          i--;
          v[i - 1] = true;
        } else {
          flag = false;
          break;
        }
      }
    }
  }

  if (flag)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}


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

using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> arr(n);
  vector<bool> v(n, false);

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

  bool flag = true;

  for (int i = n - 2; i >= 0; i--) {
    if (arr[i + 1] < arr[i]) {
      if (arr[i + 1] + 1 == arr[i])
        arr[i]--;
      else {
        flag = false;
        break;
      }
    }
  }

  if (flag)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i, n) for (lint i = 0; i < (n); i++)
#define REP1(i, n) for (lint i = 1; i < (n); i++)

lint N;

int canAlinement(vector<lint> *v) {
  map<int, int> hash;
  for (int i = N - 1; i > 0; --i) {
    for (int j = N - 1; j > 0; --j) {
      if ((*v).at(j - 1) > (*v).at(j)) {
        --(*v).at(j - 1);
        ++hash[j - 1];
        if (hash[j - 1] > 1) {
          return 0;
        }
      }
    }
  }
  return 1;
}

int main(void) {
  cin >> N;
  vector<lint> H(N);

  REP(i, N) cin >> H[i];
  canAlinement(&H) ? cout << "Yes" << endl : cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i, n) for (lint i = 0; i < (n); i++)
#define REP1(i, n) for (lint i = 1; i < (n); i++)

lint N;

int canAlinement(vector<lint> *v) {
  map<int, int> hash;
  for (int j = N - 1; j > 0; --j) {
    if ((*v).at(j) - (*v).at(j - 1) <= (-2)) {
      return 0;
    } else if ((*v).at(j) - (*v).at(j - 1) == (-1)) {
      --(*v).at(j - 1);
    }
  }
  return 1;
}

int main(void) {
  cin >> N;
  vector<lint> H(N);

  REP(i, N) cin >> H[i];
  canAlinement(&H) ? cout << "Yes" << endl : cout << "No" << endl;
  return 0;
}
Problem p02953 (C++)

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

using namespace std;

int main() {
  int n;
  int h[10000];
  int ans = 0;
  int f = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  h[0]--;

  for (int i = 0; i < n - 1; i++) {
    if (h[i] > h[i + 1]) {
      f = 1;
      break;
    }

    if (h[i] < h[i + 1]) {
      h[i + 1]--;
    }
  }

  if (f == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n;
  int h[100000];
  int ans = 0;
  int f = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  h[0]--;

  for (int i = 0; i < n - 1; i++) {
    if (h[i] > h[i + 1]) {
      f = 1;
      break;
    }

    if (h[i] < h[i + 1]) {
      h[i + 1]--;
    }
  }

  if (f == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, a[10010], minn = 0X7fffffff;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = n; i >= 1; i--) {
    if (a[i] - minn >= 2) {
      cout << "No" << endl;
      return 0;
    }
    minn = min(minn, a[i]);
  }
  cout << "Yes" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, a[100010], minn = 0X7FFFFFFF;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = n; i >= 1; i--) {
    if (a[i] - minn >= 2) {
      cout << "No" << endl;
      return 0;
    }
    minn = min(minn, a[i]);
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p02953 (C++)

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

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  if (N == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  if (N == 2) {
    if (vec.at(1) - vec.at(0) >= 2) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
    return 0;
  }

  for (int i = N - 1; i >= 1; i--) {
    if (vec.at(i - 1) - vec.at(i) >= 2 || vec.at(i - 2) - vec.at(i) >= 2) {
      // NoとすべきでないところをNoとしている可能性
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  if (N == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  if (N == 2) {
    if (vec.at(1) - vec.at(0) >= 2) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
    return 0;
  }

  vector<int> newVec;
  newVec.push_back(vec.at(0));
  int last = vec.at(N - 1);
  for (int i = 1; i < N - 1; i++) {
    if (vec.at(i) != vec.at(i + 1)) {
      newVec.push_back(vec.at(i));
    }
  }
  newVec.push_back(last);

  for (int i = newVec.size() - 1; i > 1; i--) {
    if (newVec.at(i - 1) - newVec.at(i) >= 2 ||
        newVec.at(i - 2) - newVec.at(i) >= 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define rep(a, b, c) for (ll a = b; a <= c; a++)
#define per(a, b, c) for (ll a = b; a >= c; a--)
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
const int inf = 0x3f3f3f3f;
const int N = 1e3 + 5;
const int M = 2e5 + 5;

int n;
int a[N];

int main() {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  bool flag = 1;
  a[1]--;
  rep(i, 2, n) {
    if (a[i] < a[i - 1]) {
      flag = 0;
      break;
    } else if (a[i] > a[i - 1])
      a[i]--;
  }
  printf("%s\n", flag ? "Yes" : "No");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define rep(a, b, c) for (ll a = b; a <= c; a++)
#define per(a, b, c) for (ll a = b; a >= c; a--)
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 5;
const int M = 2e5 + 5;

int n;
int a[N];

int main() {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  bool flag = 1;
  a[1]--;
  rep(i, 2, n) {
    if (a[i] < a[i - 1]) {
      flag = 0;
      break;
    } else if (a[i] > a[i - 1])
      a[i]--;
  }
  printf("%s\n", flag ? "Yes" : "No");
  return 0;
}
Problem p02953 (C++)

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

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

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

  for (int i = N - 1; i >= 0; i--) {
    if (H.at(i) < H.at(i - 1)) {
      H.at(i - 1)--;
    }

    if (H.at(i) < H.at(i - 1)) {
      printf("No");
      return 0;
    }
  }

  printf("Yes");
  return 0;
}

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

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

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

  for (int i = N - 1; i > 0; i--) {
    if (H.at(i) < H.at(i - 1)) {
      H.at(i - 1)--;
    }

    if (H.at(i) < H.at(i - 1)) {
      printf("No");
      return 0;
    }
  }

  printf("Yes");
  return 0;
}
Problem p02953 (C++)

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

int n, h[10010];

int main() {
  cin >> n >> h[0];
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  h[0]--;
  for (int i = 1; i < n; i++) {
    cin >> h[i];
    if (h[i] > h[i - 1])
      h[i]--;
    if (h[i] < h[i - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

int n, h[100010];

int main() {
  cin >> n >> h[0];
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  h[0]--;
  for (int i = 1; i < n; i++) {
    cin >> h[i];
    if (h[i] > h[i - 1])
      h[i]--;
    if (h[i] < h[i - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p02953 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
h = [int(x) for x in input().split()]
h.reverse()

flag = True

for i in range(1, n):
    print(h, i)

    if h[i - 1] >= h[i]:
        continue
    elif h[i] == h[i - 1] + 1:
        h[i] -= 1
    else:
        flag = False
        break

print("Yes") if flag else print("No")


Fixed submission:
n = int(input())
h = [int(x) for x in input().split()]
h.reverse()

flag = True

for i in range(1, n):
    if h[i - 1] >= h[i]:
        continue
    elif h[i] == h[i - 1] + 1:
        h[i] -= 1
    else:
        flag = False
        break

print("Yes") if flag else print("No")
Problem p02953 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys

input = sys.stdin.readline

N = int(input())
H = [int(item) for item in input().split()]

cand = []
cand += [H[0], H[0] - 1]
for i in range(1, N):
    new_cand = []
    for c in cand:
        if c <= H[i] - 1:
            new_cand += [H[i], H[i] - 1]
        elif c == H[i]:
            new_cand += [H[i]]
    cand = new_cand
    if len(cand) == 0:
        print("No")
        break
else:
    print("Yes")


Fixed submission:
import sys

input = sys.stdin.readline

N = int(input())
H = [int(item) for item in input().split()]

cand = []
cand += [H[0], H[0] - 1]
for i in range(1, N):
    new_cand = []
    for c in cand:
        if c <= H[i] - 1:
            new_cand += [H[i], H[i] - 1]
        elif c == H[i]:
            new_cand += [H[i]]
    cand = list(set(new_cand))
    if len(cand) == 0:
        print("No")
        break
else:
    print("Yes")
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int64_t> H(n);
  for (int i = 0; i < n; i++) {
    cin >> H.at(i);
  }
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  for (int i = n; i > 0; i--) {
    if (H.at(i - 1) + 1 == H.at(i)) {
      H.at(i - 1)--;
    } else if (H.at(i - 1) > H.at(i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int64_t> H(n);
  for (int i = 0; i < n; i++) {
    cin >> H.at(i);
  }
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  for (int i = n - 1; i > 0; i--) {
    if (H.at(i - 1) - 1 == H.at(i)) {
      H.at(i - 1)--;
    } else if (H.at(i - 1) > H.at(i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p02953 (C++)

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

int main() {
  int N;
  vector<int> a(109);
  cin >> N;
  string ans = "Yes";
  for (int i = 0; i < N; i++)
    cin >> a.at(i);
  for (int i = 1; i < N; i++) {
    if (a[i - 1] <= a[i] - 1)
      a[i] -= 1;
    if (a[i] < a[i - 1]) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  vector<int> a(100000);
  cin >> N;
  string ans = "Yes";
  for (int i = 0; i < N; i++)
    cin >> a.at(i);
  for (int i = 1; i < N; i++) {
    if (a[i - 1] <= a[i] - 1)
      a[i] -= 1;
    if (a[i] < a[i - 1]) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}
Problem p02953 (C++)

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

using namespace std;

int n;
int *x = new int[n];

void solve() {
  bool f = true;
  int diff;

  if (n == 1) {
    cout << "Yes" << endl;
  } else {
    for (int i = n - 1; 0 < i; i--) {
      diff = x[i] - x[i - 1];
      if (diff <= -2) {
        f = false;
        break;
      } else if (diff == -1) {
        x[i - 1]--;
      }
    }

    if (f)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  solve();
}


Fixed submission:
#include <iostream>

using namespace std;

int n;
int x[100000];

void solve() {
  bool f = true;
  int diff;

  if (n == 1) {
    cout << "Yes" << endl;
  } else {
    for (int i = n - 1; 0 < i; i--) {
      diff = x[i] - x[i - 1];
      if (diff <= -2) {
        f = false;
        break;
      } else if (diff == -1) {
        x[i - 1]--;
      }
    }

    if (f)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  solve();
}
Problem p02953 (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 Hs[10005];

int main() {
  int N, H;
  cin >> N;
  rep(i, N) { scanf("%d", &Hs[i]); }
  for (int i = 1; i < N; i++) {
    Hs[i] -= (Hs[i - 1] < Hs[i] ? 1 : 0);
    if (Hs[i - 1] > Hs[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int Hs[100005];

int main() {
  int N, H;
  cin >> N;
  rep(i, N) { scanf("%d", &Hs[i]); }
  for (int i = 1; i < N; i++) {
    Hs[i] -= (Hs[i - 1] < Hs[i] ? 1 : 0);
    if (Hs[i - 1] > Hs[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 1005
#define int long long
using namespace std;
int n, m, a[N], cnt[N], tot;
char c[N];
bool b[N];
signed main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  bool bo = 1;
  for (int i = 1; i <= n; i++) {
    if (i == 1 && a[i])
      a[i]--;
    else {
      if (a[i] - 1 >= a[i - 1])
        a[i]--;
      else if (a[i] < a[i - 1]) {
        bo = 0;
        break;
      }
    }
  }
  if (bo)
    puts("Yes");
  else
    puts("No");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define N 100005
#define int long long
using namespace std;
int n, m, a[N], cnt[N], tot;
char c[N];
bool b[N];
signed main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  bool bo = 1;
  for (int i = 1; i <= n; i++) {
    if (i == 1 && a[i])
      a[i]--;
    else {
      if (a[i] - 1 >= a[i - 1])
        a[i]--;
      else if (a[i] < a[i - 1]) {
        bo = 0;
        break;
      }
    }
  }
  if (bo)
    puts("Yes");
  else
    puts("No");
  return 0;
}
Problem p02953 (C++)

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

int n, a[100001], f = 0;

void work(int num, int step) {
  if (step == n + 1) {
    f = 1;
    return;
  }
  if (a[step] >= num)
    work(a[step], step + 1);
  if (a[step] + 1 >= num)
    work(a[step] + 1, step + 1);
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  work(a[1], 2);
  if (f == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int n, a[100001], f = 0;

void work(int num, int step) {
  if (step == n + 1) {
    f = 1;
    return;
  }
  if (a[step] >= num)
    work(a[step], step + 1);
  else if (a[step] + 1 >= num)
    work(a[step] + 1, step + 1);
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  work(a[1], 2);
  if (f == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main() {
  int n, h[200001], x = 1;
  cin >> n;
  rep(i, n) cin >> h[i];
  rep(i, n - 1) if (h[i] > h[i + 1] + 1) x = 0;
  vector<int> H;
  H.push_back(h[0]);
  rep(i, n - 1) if (h[i] != h[i + 1]) H.push_back(h[i + 1]);
  rep(i, H.size() - 2) if (H[i] == H[i + 1] + 1 && H[i + 1] == H[i + 2] + 1) x =
      0;
  if (x)
    cout << "Yes";
  else
    cout << "No";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main() {
  int n, h[200001], x = 1;
  cin >> n;
  rep(i, n) cin >> h[i];
  rep(i, n - 1) if (h[i] > h[i + 1] + 1) x = 0;
  vector<int> H;
  H.push_back(h[0]);
  rep(i, n - 1) if (h[i] != h[i + 1]) H.push_back(h[i + 1]);
  rep(i, (H.size() - 2) * (H.size() > 2)) if (H[i] == H[i + 1] + 1 &&
                                              H[i + 1] == H[i + 2] + 1) x = 0;
  if (x)
    cout << "Yes";
  else
    cout << "No";
}
Problem p02953 (C++)

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

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

  vector<int> data(n);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
  }
  bool ret = false;
  int max = 0;
  for (int i = 0; i < n; i++) {

    if (max - 1 > data.at(i + 1)) {
      ret = true;
    }

    if (max < data.at(i)) {
      max = data.at(i);
    }
  }

  cout << (ret ? "No" : "Yes") << endl;
}

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

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

  vector<int> data(n);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
  }
  bool ret = false;
  int max = 0;
  for (int i = 0; i < n; i++) {

    if (max - 1 > data.at(i)) {
      ret = true;
    }

    if (max < data.at(i)) {
      max = data.at(i);
    }
  }

  cout << (ret ? "No" : "Yes") << endl;
}
Problem p02953 (C++)

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

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

  int N;
  cin >> N;
  long H[10009];
  int s = 0;
  cin >> H[0];
  for (int i = 1; i < N; i++) {
    cin >> H[i];
    if (H[i - 1] < H[i]) {
      H[i]--;
      continue;
    }
    if (H[i - 1] > H[i]) {
      s = 1;
      break;
    }
  }
  if (s == 1)
    cout << "No";
  else
    cout << "Yes";
}

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

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

  int N;
  cin >> N;
  long H[110000];
  int s = 0;
  cin >> H[0];
  for (int i = 1; i < N; i++) {
    cin >> H[i];
    if (H[i - 1] < H[i]) {
      H[i]--;
      continue;
    }
    if (H[i - 1] > H[i]) {
      s = 1;
      break;
    }
  }
  if (s == 1)
    cout << "No";
  else
    cout << "Yes";
}
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n, h[100000], m = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    for (int j = 0; j < i; j++) {
      if (h[j] - h[i] > 1)
        m++;
    }
  }
  if (m)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n, h[100000], m = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < n - 1; i++) {
    if (h[n - 2 - i] - h[n - 1 - i] > 1) {
      m++;
      break;
    } else if (h[n - 2 - i] - h[n - 1 - i] == 1)
      h[n - 2 - i]--;
  }
  if (m)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p02953 (C++)

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

int main() {
  int a, s, v = 1;
  cin >> a;
  vector<int> z(a);
  for (s = 0; s < a; s++) {
    cin >> z.at(s);
  }
  reverse(z.begin(), z.end());
  for (s = 0; s < a; s++) {
    if (z.at(s) + 1 == z.at(s + 1)) {
      z.at(s + 1) -= 1;
    }
    if (z.at(s) + 1 < z.at(s + 1)) {
      v = 0;
      break;
    }
  }
  if (v == 0) {
    cout << "No" << endl;
  }
  if (v == 1) {
    cout << "Yes" << endl;
  }
}

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

int main() {
  int a, s, v = 1;
  cin >> a;
  vector<int> z(a);
  for (s = 0; s < a; s++) {
    cin >> z.at(s);
  }
  reverse(z.begin(), z.end());
  for (s = 0; s < a - 1; s++) {
    if (z.at(s) + 1 == z.at(s + 1)) {
      z.at(s + 1) -= 1;
    }
    if (z.at(s) + 1 < z.at(s + 1)) {
      v = 0;
      break;
    }
  }
  if (v == 0) {
    cout << "No" << endl;
  }
  if (v == 1) {
    cout << "Yes" << endl;
  }
}
Problem p02953 (C++)

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

using namespace std;

typedef pair<long long, long long> P;

int main() {
  int n, a[10009];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool ans = true;
  a[0]--;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      ans = false;
      break;
    } else {
      if (a[i] == a[i - 1]) {
        a[i] = a[i];
      } else {
        a[i]--;
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

using namespace std;

typedef pair<long long, long long> P;

int main() {
  long long n, a[100009];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool ans = true;
  a[0]--;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      ans = false;
      break;
    } else {
      if (a[i] == a[i - 1]) {
        a[i] = a[i];
      } else {
        a[i]--;
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02953 (C++)

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

int main() {
  int N = 0;
  int max = 0;
  int H[10000] = {0};
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  for (int i = N - 1; i > 0; i--) {
    if (H[i] + 1 == H[i - 1]) {
      H[i - 1] -= 1;
    }

    if (H[i] + 1 < H[i - 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

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

int main() {
  long long int N = 0;
  long long int max = 0;
  long long int H[100000] = {0};
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  for (int i = N - 1; i > 0; i--) {
    if (H[i] + 1 == H[i - 1]) {
      H[i - 1] -= 1;
    }

    if (H[i] + 1 < H[i - 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define oset                                                                   \
  tree<int, null_type, less_equal<int>, rb_tree_tag,                           \
       tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, i;
  cin >> n;
  vector<long long int> num(n);
  for (i = 0; i < n; i++) {
    cin >> num[i];
  }
  long long int l = num[0];
  for (i = 1; i < n; i++) {
    if (num[i] > l) {
      num[i--];
    } else if (num[i] < l) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define oset                                                                   \
  tree<int, null_type, less_equal<int>, rb_tree_tag,                           \
       tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, i;
  cin >> n;
  vector<long long int> num(n);
  for (i = 0; i < n; i++) {
    cin >> num[i];
  }
  long long int maxi = INT_MIN;
  for (i = 0; i < n; i++) {
    if (num[i] > maxi) {
      maxi = num[i];
    } else {
      if (maxi - num[i] >= 2) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p02953 (C++)

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

using namespace std;

typedef long long ll;

int main() {
  int N;
  while (cin >> N) {
    int a[10005], i, flag = 1;
    for (i = 0; i < N; i++)
      scanf("%d", &a[i]);
    a[0]--;
    for (i = 1; i < N; i++) {
      if (a[i] < a[i - 1]) {
        flag = 0;
        break;
      }
      if (a[i] > a[i - 1])
        a[i]--;
    }
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  int N;
  while (cin >> N) {
    int a[100005], i, flag = 1;
    for (i = 0; i < N; i++)
      scanf("%d", &a[i]);
    a[0]--;
    for (i = 1; i < N; i++) {
      if (a[i] < a[i - 1]) {
        flag = 0;
        break;
      }
      if (a[i] > a[i - 1])
        a[i]--;
    }
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
Problem p02953 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, a[100010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i < n; i++)
    if (a[i] > a[i + 1]) {
      if (a[i] - a[i + 1] >= 2) {
        printf("No");
        return 0;
      }
      a[i + 1]++;
    }
  printf("Yes");
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  // 整数の入力
  int n;
  int a[100000];
  bool flag[100000];
  int count, count_s;
  unsigned int ans = 0;
  int counts = 0;

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

  for (int i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      if (flag[i] == false) {
        a[i] -= 1;
        flag[i] = true;
        i = -1;
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  // 整数の入力
  int n;
  int a[100000];
  bool flag[100000];
  int count, count_s;
  unsigned int ans = 0;
  int counts = 0;

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

  for (int i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      if (flag[i] == false) {
        a[i] -= 1;
        flag[i] = true;
        i = i - 2;
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}
Problem p02953 (C++)

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

// g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v)                                                               \
  for (auto i : v)                                                             \
    cout << i << " ";

int main() {
  fast;
  ll a = 0, n;
  cin >> n;
  vi arr(n);
  REP(i, 0, n)
  cin >> arr[i];
  vi diff(n - 1);
  REP(i, 0, n - 1)
  diff[i] = arr[i + 1] - arr[i];
  for (ll i = 0; i < n - 1; i++) {
    ll j = i, c = 0;
    while (j < n - 1 && diff[j] <= 0) {
      c += diff[j];
      j++;
    }
    a = min(a, c);
    j = i;
  }
  if (a < -1)
    cout << "No\n";
  else
    cout << "Yes\n";
  return 0;
}


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

// g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v)                                                               \
  for (auto i : v)                                                             \
    cout << i << " ";

int main() {
  fast;
  ll a = 0, n;
  cin >> n;
  vi arr(n);
  REP(i, 0, n)
  cin >> arr[i];
  vi diff(n - 1);
  REP(i, 0, n - 1)
  diff[i] = arr[i + 1] - arr[i];
  for (ll i = 0; i < n - 1; i++) {
    ll j = i, c = 0;
    while (j < n - 1 && diff[j] <= 0) {
      c += diff[j];
      j++;
    }
    a = min(a, c);
    i = j;
  }
  if (a < -1)
    cout << "No\n";
  else
    cout << "Yes\n";
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  LL N;
  cin >> N;
  vector<LL> H(N);

  rep(i, N) { cin >> H[i]; }

  rep(i, N) {
    LL comp = H[N - i - 1];
    LL max_elem = *max_element(H.begin(), H.end() - i - 1);
    if (max_elem - 1 <= comp) {
      continue;
    } else {
      cout << "No";
      return 0;
    }
  }

  cout << "Yes";
  return 0;
}

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

int main() {
  LL N;
  cin >> N;
  vector<LL> H(N);

  rep(i, N) { cin >> H[i]; }

  bool noflag = false;
  for (int i = N - 1; i > 0; i--) {
    LL comp = H[i] - H[i - 1];

    if (comp == -1) {
      H[i - 1]--;
    } else if (comp <= -2) {
      cout << "No";
      return 0;
    }
  }

  cout << "Yes";
  return 0;
}
Problem p02953 (C++)

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

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

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

  int ans = 1;

  for (int i = N; i > 0; i--) {
    if (H.at(i) < H.at(i - 1)) {
      H.at(i - 1) -= 1;
      if (H.at(i) < H.at(i - 1)) {
        ans = 0;
        break;
      } else
        continue;
    } else
      continue;
  }

  if (ans == 1)
    cout << "Yes" << endl;

  else if (ans == 0)
    cout << "No" << endl;
}

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

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

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

  int ans = 1;

  for (int i = N - 1; i > 0; i--) {
    if (H.at(i) < H.at(i - 1)) {
      H.at(i - 1) -= 1;
      if (H.at(i) < H.at(i - 1)) {
        ans = 0;
        break;
      } else
        continue;
    } else
      continue;
  }

  if (ans == 1)
    cout << "Yes" << endl;

  else if (ans == 0)
    cout << "No" << endl;
}
Problem p02953 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

#ifdef DEBUG
#define IFD if (true)
#else
#define IFD if (false)
#endif

int main() {
  int N;
  int H[10000];

  cin >> N;
  rep(i, N) { cin >> H[i]; }

  rep(i, N - 1) {
    if (H[i] < H[i + 1]) {
      H[i + 1]--;
    }
    if (H[i] > H[i + 1]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

#ifdef DEBUG
#define IFD if (true)
#else
#define IFD if (false)
#endif

int main() {
  int N;
  int H[100000];

  cin >> N;
  rep(i, N) { cin >> H[i]; }

  rep(i, N - 1) {
    if (H[i] < H[i + 1]) {
      H[i + 1]--;
    }
    if (H[i] > H[i + 1]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}
Problem p02953 (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 n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) { cin >> h.at(i); }
  h.at(0)--;
  bool b = true;

  rep(i, n - 1) {
    if (h.at(i) < h.at(i + 1)) {
      h.at(i + 1)--;
    }
    if (h.at(i) > h.at(i + 1)) {
      b = false;
      break;
    }
    // cout<<h.at(i)<<" ";
  }
  if (h.at(n - 2) > h.at(n - 1))
    b = false;
  if (b)
    cout << "Yes";
  else {
    cout << "No";
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) { cin >> h.at(i); }
  h.at(0)--;
  bool b = true;

  rep(i, n - 1) {
    if (h.at(i) < h.at(i + 1)) {
      h.at(i + 1)--;
    }
    if (h.at(i) > h.at(i + 1)) {
      b = false;
      break;
    }
    // cout<<h.at(i)<<" ";
  }
  if (n != 1) {
    if (h.at(n - 2) > h.at(n - 1))
      b = false;
  }
  if (b)
    cout << "Yes";
  else {
    cout << "No";
  }
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {

  int n;
  cin >> n;
  vector<double> a(n);
  rep(i, n) { cin >> a.at(i); }

  rep(i, n) {
    if (n == 1) {
      cout << "Yes" << endl;
      break;
    }
    if (a.at(i + 1) == a.at(i))
      continue;
    else if (a.at(i + 1) > a.at(i))
      a.at(i + 1)--;
    else if (a.at(i + 1) < a.at(i)) {
      cout << "No" << endl;
      break;
    }
    if (i == (n - 2)) {
      cout << "Yes" << endl;
      break;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {

  int n;
  cin >> n;
  vector<double> a(n);
  rep(i, n) { cin >> a.at(i); }

  rep(i, n) {
    if (n == 1) {
      cout << "Yes" << endl;
      break;
    }
    if (a.at(i + 1) > a.at(i))
      a.at(i + 1)--;
    else if (a.at(i + 1) < a.at(i)) {
      cout << "No" << endl;
      break;
    }
    if (i == (n - 2)) {
      cout << "Yes" << endl;
      break;
    }
  }
  return 0;
}
Problem p02953 (C++)

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i, N) cin >> H.at(i);

  string ans = "Yes";

  if (N != 1) {
    H.at(0)--;
    for (int i = 1; i < N; i++) {
      if (H.at(i - 1) == H.at(i)) {
        if (H.at(i) > H.at(i + 1)) {
          ans = "No";
          break;
        }
      } else if (H.at(i - 1) < H.at(i))
        H.at(i)--;
      else if (H.at(i - 1) > H.at(i)) {
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i, N) cin >> H.at(i);

  string ans = "Yes";

  if (N != 1) {
    H.at(0)--;
    for (int i = 1; i < N; i++) {
      if (H.at(i - 1) == H.at(i))
        continue;
      else if (H.at(i - 1) < H.at(i))
        H.at(i)--;
      else if (H.at(i - 1) > H.at(i)) {
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
}