Language: C++

#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>

//定数
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl fact(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,O(logN)



signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl a[n];
    rep(i,n)cin >> a[i];
    uintl num = 0;
    uintl money = 1000;
    bool flag1[n];
    m0(flag1);
    rep(i,n - 1){
        if(a[i] < a[i + 1])flag1[i] = true;
    }
    for(intl i = 0; i < n; i++){
        if(!flag1[i])continue;
        intl j;
        intl mi = a[0];
        for(j = i; j < n - 1; j++){
            if(!flag1[j + 1]){
                i = j;
                break;
            }
            if(chmin(mi,a[j + 1]))flag1[j] = false;
            else flag1[j + 1] = false;
        }
    }
    bool flag2[n];
    m0(flag2);
    rep(i,n - 1){
        if(a[i] > a[i + 1])flag2[i] = true;
    }
    for(intl i = 0; i < n; i++){
        if(!flag2[i])continue;
        intl j;
        intl mx = a[0];
        for(j = i; j < n - 1; j++){
            if(!flag2[j + 1]){
                i = j;
                break;
            }
            if(chmax(mx,a[j + 1]))flag2[j] = false;
            else flag2[j + 1] = false;
        }
    }
    // rep(i,n)cout << flag1[i];
    // cout << endl;
    // rep(i,n)cout << flag2[i];
    // cout << endl;
    rep(i,n - 1){
        //debug(num);
        //debug(money);
        try{
            if(flag1[i]&&flag2[i])thwow;
            if(flag1[i]){
                num += (money / a[i]); 
                money -= (num * a[i]);
            }
            else if(flag2[i]){
                money += (num * a[i]);
                num = 0;
            }    
        }
        catch(){
            cout << a[n + 1];
        }
        
    }
    //debug(num);
    //debug(money);
    money += (num * a[n - 1]);
    num = 0;
    cout << money << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:100:35: error: 'thwow' was not declared in this scope
  100 |             if(flag1[i]&&flag2[i])thwow;
      |                                   ^~~~~
a.cc:110:15: error: expected type-specifier before ')' token
  110 |         catch(){
      |               ^