#include #define int long long using namespace std; int read(){ int x=0,f=1; char c=getchar(); while(!(c>='0'&&c<='9')){ if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=x*10+c-'0'; c=getchar(); } return x*f; } void write(int x){ if(x<0){ putchar('-'); x=-x; } if(x>9) write(x/10); putchar(x%10+'0'); return ; } string s; int sum=0; const int M=1000000007; void dfs(int now,int last,stack st){//0 ? 1 ? 2? if(now==s.size()){ sum++; sum%=M; return ; } if(last==0){ if(s[now]==')'){ if(!st.empty()){ int x=st.top(); st.pop(); if(x==0){ stack a=st; a.push(1); dfs(now+1,1,a); a=st; a.push(2); dfs(now+1,2,a); } else{ stack a=st; a.push(0); dfs(now+1,0,a); } } } else{ stack a=st; a.push(0); dfs(now+1,0,a); a=st; a.push(1); dfs(now+1,1,a); a=st; a.push(2); dfs(now+1,2,a); } } if(last==1){ if(s[now]==')'){ if(!st.empty()){ int x=st.top(); st.pop(); if(x==0){ stack a=st; a.push(2); dfs(now+1,2,a); } else{ stack a=st; a.push(0); dfs(now+1,0,a); } } } else{ stack a=st; a.push(0); dfs(now+1,0,a); a=st; a.push(2); dfs(now+1,2,a); } } if(last==2){ if(s[now]==')'){ if(!st.empty()){ int x=st.top(); st.pop(); if(x==0){ stack a=st; a.push(1); dfs(now+1,1,a); } else{ stack a=st; a.push(0); dfs(now+1,0,a); } } } else{ stack a=st; a.push(1); dfs(now+1,1,a); } } return ; } signed main(){ int n=read(); cin>>s; stack s; dfs(0,0,s); cout<