Language: C++

#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

const int mod = 1000000007;
struct mint {
    ll x; // using long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;
    vl ts(n), as(n);
    cin>>ts>>as;
    reverse(rng(as));
    
    vl hs(n);
    vl us(n);
    rep(i, n) {
        if (i == 0 || ts[i] > ts[i - 1]) {
            hs[i] = ts[i];
        }
        else {
            us[i] = ts[i];
        }
    }
    rep(i, n) {
        if (i == 0 || as[i] > as[i - 1]) {
            if ((hs[n - i - 1] != 0 && as[i] != hs[n - i - 1]) || (us[n - i - 1] != 0 && as[i] > us[n - i - 1]) {
                cout<<0<<endl;
                return 0;
            }
            hs[n - i - 1] = as[i];
        }
        else {
            if (us[n - i - 1] != 0) chmin(us[n - i - 1], as[i]);
            else us[n - i - 1] = as[i];
        }
    }
    
    mint ans = 1;
    rep(i, n) {
        if (us[i] == 0 || hs[i] != 0) continue;
        ans *= us[i];
    }
    cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:86:112: error: expected ';' before '{' token
   86 |             if ((hs[n - i - 1] != 0 && as[i] != hs[n - i - 1]) || (us[n - i - 1] != 0 && as[i] > us[n - i - 1]) {
      |                                                                                                                ^~
      |                                                                                                                ;
a.cc:90:34: error: expected ')' before ';' token
   90 |             hs[n - i - 1] = as[i];
      |                                  ^
      |                                  )
a.cc:86:16: note: to match this '('
   86 |             if ((hs[n - i - 1] != 0 && as[i] != hs[n - i - 1]) || (us[n - i - 1] != 0 && as[i] > us[n - i - 1]) {
      |                ^