Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ss second
- #define ff first
- #define p_b push_back
- #define endl "\n"
- #ifndef LOCAL
- #define cerr if(0)cerr
- #endif // LOCAL
- typedef long long ll;
- typedef long double ld;
- const ll INF = 9223372036854775807;
- const ll INFINT = 2147483647;
- const int N = 1000006;
- const int NN = 1006;
- const int MOD = 1000000007;
- void DIE(string s) {
- cout << s << endl;
- exit(0);
- }
- void DIE(ll x) {
- cout << x << endl;
- exit (0);
- }
- void DIE(int x) {
- cout << x << endl;
- exit(0);
- }
- void YES() {
- DIE("YES");
- }
- void Yes() {
- DIE("Yes");
- }
- void yes() {
- DIE("yes");
- }
- void NO() {
- DIE("NO");
- }
- void No() {
- DIE("No");
- }
- void no() {
- DIE("no");
- }
- /////////////////
- // Write below //
- /////////////////
- int main () {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #ifdef LOCAL
- freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
- #else
- //freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
- //freopen ("mole.in", "r", stdin);freopen ("mole.out", "w", stdout);
- #endif // LOCAL
- int n;
- cin >> n;
- n <<= 1;
- string s;
- cin >> s;
- int ans = 0;
- int bal = 0;
- for (int i = 0; i < n; i++) {
- if (s[i] == '(') bal++;
- else bal--;
- if (bal < 0) {
- bal += 2;
- ans++;
- }
- }
- //cerr << ans << ' ' << bal << endl;
- cout << ans + bal / 2;
- }
- /////////////////
- // Write above //
- /////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement