Language: Java

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cout.precision(12);
    cout << fixed;

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    set<pair<int, int> > s;
    for (int i = 0; i < n; i++) {
        s.insert({b[i], i});
    }
    long long ans = 0;
    while (!s.empty()) {
        auto p = *s.rbegin();
        s.erase(p);
        int x = p.first;
        int i = p.second;
        if (a[i] > b[i]) {
            cout << -1 << endl;
            return 0;
        }
        if (a[i] == b[i]) {
            continue;
        }
        int i0 = (i+n-1)%n;
        int i1 = (i+1)%n;
        int once = (b[i0] + b[i1]);
        int mx = max(b[i0], b[i1]);
        mx = max(mx, a[i]);
        int need = b[i] - mx;
        if (need < 0) {
            cout << -1 << endl;
            return 0;
        }
        int times = (need + once - 1) / once;
        ans += times;
        b[i] -= once * times;
        if (b[i] < a[i]) {
            cout << -1 << endl;
            return 0;
        }
        if (b[i] > a[i]) {
            s.insert({b[i], i});
        }
    }
    cout << ans << endl;

    return 0;
}


Compiler output:
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include <bits/stdc++.h>
         ^
Main.java:6: error: not a statement
    ios_base::sync_with_stdio(false);
    ^
Main.java:8: error: not a statement
    cout << fixed;
         ^
Main.java:11: error: not a statement
    cin >> n;
        ^
Main.java:12: error: not a statement
    vector<int> a(n), b(n);
                  ^
Main.java:14: error: not a statement
        cin >> a[i];
            ^
Main.java:17: error: not a statement
        cin >> b[i];
            ^
Main.java:21: error: not a statement
        s.insert({b[i], i});
                   ^
Main.java:21: error: not a statement
        s.insert({b[i], i});
                        ^
Main.java:23: error: not a statement
    long long ans = 0;
    ^
Main.java:30: error: not a statement
            cout << -1 << endl;
                       ^
Main.java:43: error: not a statement
            cout << -1 << endl;
                       ^
Main.java:50: error: not a statement
            cout << -1 << endl;
                       ^
Main.java:54: error: not a statement
            s.insert({b[i], i});
                       ^
Main.java:54: error: not a statement
            s.insert({b[i], i});
                            ^
Main.java:57: error: not a statement
    cout << ans << endl;
                ^
Main.java:5: error: unnamed classes are a preview feature and are disabled by default.
int main() {
^
  (use --enable-preview to enable unnamed classes)
Main.java:6: error: ';' expected
    ios_base::sync_with_stdio(false);
                             ^
Main.java:12: error: ';' expected
    vector<int> a(n), b(n);
                 ^
Main.java:12: error: ';' expected
    vector<int> a(n), b(n);
                   ^
Main.java:21: error: illegal start of expression
        s.insert({b[i], i});
                 ^
Main.java:21: error: ';' expected
        s.insert({b[i], i});
                      ^
Main.java:21: error: ';' expected
        s.insert({b[i], i});
                         ^
Main.java:21: error: illegal start of expression
        s.insert({b[i], i});
                          ^
Main.java:23: error: ';' expected
    long long ans = 0;
        ^
Main.java:25: error: illegal start of expression
        auto p = *s.rbegin();
                 ^
Main.java:54: error: illegal start of expression
            s.insert({b[i], i});
                     ^
Main.java:54: error: ';' expected
            s.insert({b[i], i});
                          ^
Main.java:54: error: ';' expected
            s.insert({b[i], i});
                             ^
Main.java:54: error: illegal start of expression
            s.insert({b[i], i});
                              ^
31 errors