#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/
  
  ll n;
  cin>>n;
  
  ll arr[n], arr1[n];
  rep(n)
        cin>>arr[i];
  rep(n)
        cin>>arr1[i];
  ll ans = 0;
  rep(n)
        ans+=(arr[i]*arr1[i]);
  if(ans == 0)
    cout<<"Yes"<<'\n';        
  else cout<<"No\n";
  
  return 0;
}
   
   
 
#include<bits/stdc++.h>
using namespace std;

const int N=500010;
char s[N],t[N];
int sta[N],top;
int n;

void fail(){printf("-1\n");exit(0);}

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	int las=0;
	for(int i=n;i>=1;i--) if(t[i]=='1') sta[++top]=i;
	long long ans=0;
	for(int i=1;i<=n;i++)
		if(s[i]=='1'){
			if(las) ans+=i-las,las=0;
			else if(top && sta[top]<=i) ans+=i-sta[top],top--;
			else las=i;
		}
	if(las || top) fail();
	printf("%lld\n",ans);
}