#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
long long n,m,i,j,a[2500005],b[2500005],ad,bd,mod,ans=0x1212121212121212ll;
long long calc(long long x,long long y)
{
	return (n-x)*(m-y)+a[x]+b[y];
}
int main()
{
	cin>>n>>m>>a[1]>>ad>>b[1]>>bd;
	fz(i,2,n){
		a[i]=(58ll*a[i-1]+ad)%(m+1);
	}
	fz(i,2,m){
		b[i]=(58ll*b[i-1]+bd)%(n+1);
	}
//	a[0]=b[0]=0;
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	fz1(i,n){
		a[i]+=a[i-1];
	}
	fz1(i,m){
		b[i]+=b[i-1];
	}
	j=n;
	fz0g(i,m){
		while(j>0&&calc(j,i)>=calc(j-1,i))j--;
		ans=min(ans,calc(j,i)); 
	}
	cout<<ans<<endl; 
	return 0;
}

### Prompt

Please create a solution in cpp to the following problem:

Example

Input

2 3 1 3 1 0


Output

2

### Response

```cpp
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
long long n,m,i,j,a[2500005],b[2500005],ad,bd,mod,ans=0x1212121212121212ll;
long long calc(long long x,long long y)
{
	return (n-x)*(m-y)+a[x]+b[y];
}
int main()
{
	cin>>n>>m>>a[1]>>ad>>b[1]>>bd;
	fz(i,2,n){
		a[i]=(58ll*a[i-1]+ad)%(m+1);
	}
	fz(i,2,m){
		b[i]=(58ll*b[i-1]+bd)%(n+1);
	}
//	a[0]=b[0]=0;
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	fz1(i,n){
		a[i]+=a[i-1];
	}
	fz1(i,m){
		b[i]+=b[i-1];
	}
	j=n;
	fz0g(i,m){
		while(j>0&&calc(j,i)>=calc(j-1,i))j--;
		ans=min(ans,calc(j,i)); 
	}
	cout<<ans<<endl; 
	return 0;
}

```