#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1234576891234601LL;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, M, a0, ad, b0, bd;
	cin >> N >> M >> a0 >> ad >> b0 >> bd;
	vector<int> a(N), b(M);
	a[0] = a0;
	for (int i = 1; i < N; i++)
		a[i] = (a[i - 1] * 58 + ad) % (M + 1);
	b[0] = b0;
	for (int j = 1; j < M; j++)
		b[j] = (b[j - 1] * 58 + bd) % (N + 1);
	vector<int> c(N + 1);
	for (int j = 0; j < M; j++)
		c[b[j]]++;
	for (int i = N - 1; i >= 0; i--)
		c[i] += c[i + 1];
	vector<int> d(M + 1);
	for (int i = 0; i < N; i++)
		d[a[i]]++;
	ll unko = 0, ans = 0;
	int i = 1;
	for (int j = M; j >= 0; j--)
		while (d[j]--) {
			int k = min((ll)j, unko + c[i]);
			ans += k;
			unko += c[i] - k;
			i++;
		}
	cout << ans << endl;
}
### Prompt

Your task is to create a cpp solution to the following problem:

Example

Input

2 3 1 3 1 0


Output

2

### Response

```cpp
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1234576891234601LL;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, M, a0, ad, b0, bd;
	cin >> N >> M >> a0 >> ad >> b0 >> bd;
	vector<int> a(N), b(M);
	a[0] = a0;
	for (int i = 1; i < N; i++)
		a[i] = (a[i - 1] * 58 + ad) % (M + 1);
	b[0] = b0;
	for (int j = 1; j < M; j++)
		b[j] = (b[j - 1] * 58 + bd) % (N + 1);
	vector<int> c(N + 1);
	for (int j = 0; j < M; j++)
		c[b[j]]++;
	for (int i = N - 1; i >= 0; i--)
		c[i] += c[i + 1];
	vector<int> d(M + 1);
	for (int i = 0; i < N; i++)
		d[a[i]]++;
	ll unko = 0, ans = 0;
	int i = 1;
	for (int j = M; j >= 0; j--)
		while (d[j]--) {
			int k = min((ll)j, unko + c[i]);
			ans += k;
			unko += c[i] - k;
			i++;
		}
	cout << ans << endl;
}
```