#ifndef INCLUDED_MAIN #define INCLUDED_MAIN #include __FILE__ int main() { int n; string s; cin>>n>>s; vector p(n+1,0); rep(i,n){ p[i+1]=p[i]+(s[i]=='('?1:-1); } ll mn=p[0]; int t=0; srep(i,1,n){ if(p[i]<=mn){ mn=p[i]; t=i; } } int k=(n-(t%n))%n; ll balance=0, flips=0; rep(i,n){ char c=s[(i+k)%n]; if(c=='(') balance++; else balance--; if(balance<0){ flips++; balance=1; } } flips+=balance/2; cout<>r>>m; //namesugi return 0; } /////// library zone /////// #else #include using namespace std; #define rep(i,n) for(ll i=0;i #define vc vector ll calc_min(const string &s){ stack st; for(char c:s){ if(c=='('){ st.push(0); } else { ll cur=st.top(); st.pop(); ll sc=(cur==0 ? 2 : cur+1); if(st.empty()) st.push(sc); else{ ll t=st.top(); st.pop(); st.push(t+sc); } } } return st.empty()?0:st.top(); } bool taio(const string &s){ ll bal=0; for(char c:s){ if(c=='(') bal++; else{ if(bal==0) return false; bal--; } } return bal==0; } template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} void no() { cout<<"No"<& a) { ll ans=0; for(auto i:a) ans+=i; return ans; } #endif