#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000009
typedef long long LL;
int n;
char s1[MAXN],s2[MAXN];
int pp1[MAXN],pp2[MAXN];
stack<int> pps;
LL pb(int l,int r,int pp[],int fl){
if(l+1==r){
return 0;
}
if(pp[r-1]==l+1){
if(fl){
return pb(l+1,r-1,pp,1);
}else{
return pb(l+1,r-1,pp,1)+1;
}
}
LL res=2-fl;
for(int i=l+1;i<=r-1;i=pp[i]+1){
res+=pb(i,pp[i],pp,0);
}
return res;
}
LL calc(int l,int r){
if(l+1==r){
return 0;
}
LL res=0;
for(int i=l;i<=r;i=pp1[i]+1){
if(pp1[i]==pp2[i]){
res+=calc(i+1,pp1[i]-1);
}else{
res+=pb(i,pp1[i],pp1,0);
}
}
for(int i=l;i<=r;i=pp2[i]+1){
if(pp1[i]!=pp2[i]){
res+=pb(i,pp2[i],pp2,0);
}
}
return res;
}
int main(){
scanf("%d",&n);
scanf("%s",s1+1);
scanf("%s",s2+1);
for(int i=1;i<=n;i++){
if(s1[i]=='('){
pps.push(i);
}else{
pp1[i]=pps.top();
pp1[pp1[i]]=i;
pps.pop();
}
}
for(int i=1;i<=n;i++){
if(s2[i]=='('){
pps.push(i);
}else{
pp2[i]=pps.top();
pp2[pp2[i]]=i;
pps.pop();
}
}
if(s1==s2){
printf("0\n");
}else{
printf("%lld",calc(1,n));
}
return 0;
}