每个格子记录其左下的45°直角梯形区域的和及左下矩形区域的和即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 3010
#define M 3000010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,m,q;
unsigned int A,B,C,ans,p[M],a[N][N],b[N][N];
inline unsigned int rng61()
{
A^=A<<;
A^=A>>;
A^=A<<;
unsigned int t=A;
A=B;
B=C;
C^=t^A;
return C;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj4972.in","r",stdin);
freopen("bzoj4972.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
scanf("%d%d%d%u%u%u",&n,&m,&q,&A,&B,&C);
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
a[i][j]=rng61();
for (int i=n;i>=;i--)
for (int j=;j<=m;j++)
b[i][j]=a[i][j]+=a[i+][j];
for (int i=n;i>=;i--)
for (int j=;j<=m;j++)
a[i][j]+=a[i+][j-],b[i][j]+=b[i][j-];
p[]=;for (int i=;i<=q;i++) p[i]=p[i-]*;
for (int i=;i<=q;i++)
{
int x=rng61()%n+,y=rng61()%m+,k=rng61()%min(x,y)+;
unsigned int tot=a[x-k+][y]-a[x+][y-k]-b[x+][y]+b[x+][y-k];
ans+=tot*p[q-i];
}
cout<<ans;
return ;
}