#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#define N 201000
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
	while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
	if (flag)	x = -x;
}
using namespace std;
int n;
int a[N], b[N], h[N], htot;
long long ans;
inline void sol(int L, int R) {
	if (L + 1 == R)	return ;
//	printf("sol(%d, %d) : \n", L, R);
	int ptr = R;
	for (int i = L + 1; i < R; ++i) if (b[i] > a[i]) { ptr = i; break; }
//	printf("ptr = %d\n", ptr);
	int tol = a[ptr - 1];
	for (int i = ptr - 1; i > L; --i) {
		if (b[i] < tol) {
			int p = upper_bound(a + L, a + R + 1, b[i]) - a - 1;//bug
//			printf("i = %d, p = %d\n", i, p);
			ans += i - p;
			tol = b[i];
		}
	}
	int tor = a[ptr];
	for (int i = ptr; i < R; ++i) {
		if (b[i] > tor) {
			int p = lower_bound(a + L, a + R + 1, b[i]) - a;//bug bug
//			printf("i = %d, p = %d\n", i, p);
			ans += p - i;
			tor = b[i];
		}
	}
}
int main() {
	read(n);
	int L;
	read(L);
	++n; ++n;
	a[0] = b[0] = 0; a[n - 1] = b[n - 1] = L + 2 - n;//0 ... L + 1
	for (int i = 1; i < n - 1; ++i) read(a[i]), a[i] -= i;
	for (int i = 1; i < n - 1; ++i) read(b[i]), b[i] -= i;
//	for (int i = 0; i < n; ++i) printf("%d ", a[i]); puts("");
//	for (int i = 0; i < n; ++i) printf("%d ", b[i]); puts("");
	for (int i = 0; i < n; ++i) h[++htot] = a[i];
	htot = unique(h + 1, h + 1 + htot) - h - 1; h[htot + 1] = -12341;
	for (int i = 0; i < n; ++i) a[i] = lower_bound(h + 1, h + 1 + htot, a[i]) - h;
	for (int i = 0; i < n; ++i) {
		int v = lower_bound(h + 1, h + 1 + htot, b[i]) - h;
		if (h[v] != b[i]) return puts("-1"), 0;
		b[i] = v;
	}
//	for (int i = 0; i < n; ++i) printf("%d ", a[i]); puts("");
//	for (int i = 0; i < n; ++i) printf("%d ", b[i]); puts("");
	int lst = 0;
	for (int i = 1; i < n; ++i) if (a[i] == b[i]) {
//		printf("\ni = %d : \n", i);
		sol(lst, i); lst = i;
//		printf("ans = %lld\n", ans);
	}
	printf("%lld\n", ans);
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf (int)(1e18)
#define md (int)(998244353)
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;

const int M = 2e5 + 10;

int ex(int a,int b=md-2){
	int ans=1;
	while(b) {
		if(b&1) ans=(ans*a)%md;
		a=(a*a)%md,b/=2;
	}
	return ans;
} 
inline int add(int a,int b){
	a+=b;
	if(a>=md) a-=md;
	return a;
}
inline int sub(int a,int b){
	a-=b;
	if(a<0) a+=md;
	return a;
}
inline int mul(int a,int b){
	return (a*b)%md;
}

int f[M],iv[M];
int C(int n,int r){
	if(n<r) return 0;
	return mul(f[n],mul(iv[r],iv[n-r]));
}

void init(){
	f[0]=1;
	for(int i=1;i<M;++i) {
		f[i]=mul(i,f[i-1]);
	}
	iv[M-1]=ex(f[M-1]);
	for(int i=M-2;i>=0;--i) {
		iv[i]=mul(i+1,iv[i+1]);
	}
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
   	
   	init();
   	
   	int n,m,k;
   	cin>>n>>m>>k;
   	if(n==1 or m==1) {
   		cout<<ex(k,n+m-1);
   		return 0;
   	}
   	// Bi>=max(A) 
   	int ans=0;
   	rep(i,1,k+1) {
   		int now=sub(ex(i,n),ex(i-1,n));
   		now=mul(now,ex(k-i+1,m));
   		ans=add(ans,now);
   	}
   	cout<<ans;
   	
    return 0;
}