#define x first #define y second #define int long long #define endl '\n'
usingnamespace std;
typedef pair<int, int> PII;
constint N = 2010;
int T; int n; int a[N];
voidsolve() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i];
if (n == 1) { cout << 1 << endl; return; }
int res = 1e18; for (int i = (n % 2 ? 0 : -1); i < (n % 2? n : 0); i++) { vector<int> s; for (int j = 0; j < n; j++) if (i != j) s.push_back(a[j]); int ans = 0; for (int j = 0; j < s.size(); j += 2) ans = max(ans, s[j + 1] - s[j]); res = min(res, ans); }
#define x first #define y second #define int long long #define endl '\n'
usingnamespace std;
typedef pair<int, int> PII;
constint N = 200010;
int T; int n; string s;
voidsolve() { cin >> n >> s; s = ' ' + s;
vector<int> s0, s1; for (int i = 1; i <= n; i++) { if (s[i] == '0') s0.push_back(i); else s1.push_back(i); }
reverse(s1.begin(), s1.end());
int res = 0; for (int i = n; i >= 1; i--) { if (s[i] == '0') res += i; else { while (s0.size() && s0.back() > i) s0.pop_back(); while (s1.size() && s1.back() >= i) s1.pop_back(); if (s0.size()) s0.pop_back(); elseif (s1.size()) { s[s1.back()] = '0'; s1.pop_back(); } else res += i; } }