#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main()
{

    int n;cin>>n;
    ll arr[n+3],arr1[n+3];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int j=0;j<n;j++)cin>>arr1[j];
    ll prev=-1,mx=0;
    for(int i=0;i<n;i++)
    {
        mx=max(mx,arr[i]);
        ll k=(arr[i]*arr1[i]);
        prev=max(prev,k);
        if(i>0)
        {
           prev=max(mx*arr1[i],prev);
        }
        cout<<prev<<endl;
    }
    return 0;
}

#include <cstdio>

#define rep( i, a, b ) for( int (i) = (a) ; (i) <= (b) ; (i) ++ )
#define per( i, a, b ) for( int (i) = (a) ; (i) >= (b) ; (i) -- )

typedef long long LL;

const int MAXN = 5e5 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

int S[MAXN], T[MAXN];
int N;

int main()
{
	read( N );
	int l1 = 0, l2 = 0;
	rep( i, 1, N ) { int d;
		scanf( "%1d", &d );
		if( d ) S[++ l1] = i;
	}
	rep( i, 1, N ) { int d;
		scanf( "%1d", &d );
		if( d ) T[++ l2] = i;
	}
	int r = 1; LL ans = 0;
	for( int i = 1 ; i <= l1 ; i ++ )
		if( r <= l2 && S[i] >= T[r] )
			ans += S[i] - T[r], r ++;
		else
		{
			if( i == l1 ) return puts( "-1" ), 0;
			ans += S[i + 1] - S[i], i ++;
		}
	if( r <= l2 ) return puts( "-1" ), 0;
	write( ans ), putchar( '\n' );
	return 0;
}