#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(i64 i=0; i void chmin(A& l, const A& r){ if(r < l) l = r; } template void chmax(A& l, const A& r){ if(l < r) l = r; } using namespace std; void testcase(){ i64 N; cin >> N; string S; cin >> S; i64 R, M; cin >> R >> M; if(N%2 == 1){ cout << "-1\n"; return; } i64 cnt = 0; for(char c : S) cnt += (c == '(' ? 1 : -1); vector dep(N+1); rep(i,N) dep[i+1] = dep[i] + (S[i] == '(' ? 1 : -1); vector mindepL(N+1), mindepR(N+1); rep(i,N) mindepL[i+1] = min(mindepL[i], dep[i+1]); mindepR[N] = dep[N]; for(i64 i=N-1; i>=0; i--) mindepR[i] = min(mindepR[i+1], dep[i]); i64 ans = INF; if(dep[N] <= 0){ rep(i,N){ i64 offset = R * ((N-i)%N) + M * (-dep[N] / 2); i64 s = min(mindepL[i] + dep[N], mindepR[i]) - dep[i]; s = (-(s - dep[N]) + 1) / 2 * 2 * M; chmin(ans, s + offset); } } else { rep(i,N){ i64 offset = R * ((N-i)%N) + M * (dep[N] / 2); i64 s = min(mindepL[i] + dep[N], mindepR[i]) - dep[i]; s = (-s + 1) / 2 * 2 * M; chmin(ans, s + offset); } } cout << ans << "\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }