#define _USE_MATH_DEFINES

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <queue>

#define	INF   1010101010LL
#define INFLL 1010101010101010101LL

using namespace std;
using Complex = complex<double>;

const int mod = 1000000007;
//const int mod = 998244353;

int main()
{
	int n;
	string s, t;
	cin >> n >> s >> t;
	long long ans = 0;
	queue<int> q;
	for (int i = 0; i < n; i++) {
		if (s[i] != t[i]) {
			q.push(i);
			i++;
			while (i < n) {
				if (s[i] == '1') {
					s[i] = '0';
					ans += i - q.front();
					q.pop();
				}
				if (s[i] != t[i]) {
					q.push(i);
				}
				if (q.empty()) {
					break;
				} else {
					i++;
				}
			}
			if (!q.empty()) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;

	return 0;
}
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(time(0));
 
 
long long powm(long long a, long long b,long long mod) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %mod;
        a = a * a %mod;
        b >>= 1;
    }
    return res;
}
 
 
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);      
}

const int mod=998244353;

signed main()
{
 
ios_base::sync_with_stdio(false); 
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
    }
#endif          

    int n,m,k;
    cin>>n>>m>>k;
    int ans=0;
    if(n==1&&m==1)
    {
        cout<<k;
        return 0;       
    }
    else if(n==1||m==1)
    {
        cout<<powm(k,n+m-1,mod);
        return 0;
    }

    for(int i=1;i<=k;i++)
    {
        int z=(powm(i,n,mod))-powm(i-1,n,mod)+mod;
        z%=mod;
        z*=(powm(k-i+1,m,mod));
        z%=mod;
        ans+=z;
        ans%=mod;
    }
    cout<<ans;

}