#include <bits/stdc++.h>
namespace IO{
    char buf[1000000],*p1,*p2;
    inline char getc(){
        if(p1==p2) p2=(p1=buf)+fread(buf,1,1000000,stdin);
        return p1==p2?EOF:*(p1++);
    }
    template<typename tp>inline void r(tp &n){
        n=0;char c=getc();
        while(!isdigit(c)) c=getc();
        while( isdigit(c)) n=n*10+c-48,c=getc();
    }
    template<typename tp>inline void w(tp  n){
        if(n/10) w(n/10);
        putchar(n%10+48);
    }
};
using namespace IO;
const int N=1e5+5;
using namespace std;
int n,L;
long long a[N],b[N];
int main(){

    //freopen("1.in","r",stdin);
    
    r(n),r(L);
    for(int i=1;i<=n;++i) r(a[i]);
    for(int i=1;i<=n;++i) r(b[i]);
    a[n+1]=L+1,b[n+1]=L+1;
    for(int i=n+1;i>=1;--i)
        a[i]=a[i]-a[i-1]-1,b[i]=b[i]-b[i-1]-1;
    long long ans=0,j=1,st=1;
    for(int i=1;i<=n+1;++i){
        if(!b[i]) continue;
        while(!a[j]) ++j;st=j;
        long long cur=0; 
        while(cur<b[i]&&j<=n+1) cur+=a[j++];
        if(cur!=b[i]) {puts("-1");return 0;}
        ans+=max(0ll,j-1-i)+max(0ll,i-st);
    }
    w(ans);
    return 0;
}
#include "bits/stdc++.h"

#define MOD  998244353
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  ll A = mod((a+1)*a/2,MOD);
  ll B = mod((b+1)*b/2,MOD);
  ll C = mod((c+1)*c/2,MOD);
  cout << mod(mod(C*B, MOD)*A, MOD)<<endl;
  
  return 0;
}
