Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
 
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
 
 
void f(int i, int j){
 
}
 
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    a.push_back(-1);
    int soko = 0, top = 0;
    ll mon = 1000;
    while(true){
        bool ok = false;
        for(int j = top+1; j < n; j++){
            if (a[j-1] >= a[j] && a[j] < a[j+1]){
                soko = j;
            }
            if (a[j-1] <= a[j] && a[j] > a[j+1]){
                top = j;
                ok = true;
                break;
            }
        }
        if (!ok) break;
        if (a[soko] > a[top]) break;
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
 
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
 
 
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    a.push_back(-1);
    int soko = 0, top = 0;
    ll mon = 1000;
    while(true){
        bool ok = false;
        for(int j = top+1; j < n; j++){
            if (a[j-1] >= a[j] && a[j] < a[j+1]){
                soko = j;
            }
            if (a[j-1] <= a[j] && a[j] > a[j+1]){
                top = j;
                ok = true;
                break;
            }
        }
        if (!ok) break;
        if (a[soko] > a[top]) break;
        for(int i = soko; i < top; i++){
            ll kabu = mon / a[i];
            mon %= a[i];
            mon += kabu * a[i+1];
        }
    }
    cout << mon << endl;
}
    }
    cout << mon << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:1: error: a template declaration cannot appear at block scope
   52 | template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
      | ^~~~~~~~
a.cc:59:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   59 | int main(){
      |         ^~
a.cc:59:9: note: remove parentheses to default-initialize a variable
   59 | int main(){
      |         ^~
      |         --
a.cc:59:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:59:11: error: a function-definition is not allowed here before '{' token
   59 | int main(){
      |           ^