#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class TheUltimatePackages { public:
vector <int> count(int N, int D, vector <int> Xprefix, vector <int> Yprefix, int L, int seed)
{
vector<int> X(D), Y(D);
int XL = Xprefix.size();
for (int i = 0; i<XL; ++i) {
X[i] = Xprefix[i];
Y[i] = Yprefix[i];
}
long long state = seed;
for (int i = XL; i<D; ++i) {
state = (state * 1103515245 + 12345) % (1LL << 31);
int elen = 1 + state%L;
state = (state * 1103515245 + 12345) % (1LL << 31);
Y[i] = state % (N - elen);
X[i] = Y[i] + elen;
}
vector<int> maxdep(N, -1);
for (int i = 0; i < D; ++i)
maxdep[X[i]] = max(maxdep[X[i]], Y[i]);
vector<int> deped_by_all_larger;
int cur = N - 1;
for (int v = N - 1; v >= 0; --v) {
if (v == cur)
deped_by_all_larger.push_back(v);
if (maxdep[v] < cur)
cur = maxdep[v];
}
vector<int> mindep(N, N);
for (int i = 0; i < D; ++i)
mindep[Y[i]] = min(mindep[Y[i]], X[i]);
set<int> deped_by_all_smaller;
cur = 0;
for (int v = 0; v <= N-1; ++v) {
if (v == cur)
deped_by_all_smaller.insert(v);
if (cur < mindep[v])
cur = mindep[v];
}
int sum = 0;
int cnt = 0;
for (int v : deped_by_all_larger)
if (deped_by_all_smaller.count(v)) {
sum += v;
cnt += 1;
}
vector<int> ans = { cnt, sum };
return ans;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <int>& Expected, const vector <int>& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, TheUltimatePackages().count(N, D, Xprefix, Yprefix, L, seed));}
int main(){
CASE(0)
int N = 5;
int D = 4;
int Xprefix_[] = {1, 3, 2, 4};
vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_));
int Yprefix_[] = {0, 2, 1, 3};
vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_));
int L = 1;
int seed = 47;
int __[] = {5, 10 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(1)
int N = 5;
int D = 6;
int Xprefix_[] = {1, 2, 3, 4, 4, 4};
vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_));
int Yprefix_[] = {0, 0, 0, 1, 3, 2};
vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_));
int L = 1;
int seed = 64;
int __[] = {2, 4 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(2)
int N = 5;
int D = 4;
int Xprefix_[] = {2, 2, 3, 4};
vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_));
int Yprefix_[] = {0, 1, 2, 2};
vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_));
int L = 1;
int seed = 32532;
int __[] = {1, 2 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(3)
int N = 4;
int D = 3;
int Xprefix_[] = {3, 3, 2};
vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_));
int Yprefix_[] = {0, 2, 1};
vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_));
int L = 1;
int seed = 2555;
int __[] = {1, 3 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(4)
int N = 7;
int D = 0;
vector <int> Xprefix;
vector <int> Yprefix;
int L = 1;
int seed = 0;
int __[] = {0, 0 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(5)
int N = 2;
int D = 4;
int Xprefix_[] = {1, 1, 1, 1};
vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_));
int Yprefix_[] = {0, 0, 0, 0};
vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_));
int L = 1;
int seed = 0;
int __[] = {2, 1 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(6)
int N = 7;
int D = 12;
int Xprefix_[] = {2, 3, 4};
vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_));
int Yprefix_[] = {1, 2, 3};
vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_));
int L = 5;
int seed = 4747;
int __[] = {0, 0 };
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
/*
CASE(7)
int N = ;
int D = ;
int Xprefix_[] = ;
vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_));
int Yprefix_[] = ;
vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_));
int L = ;
int seed = ;
int __[] = ;
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(8)
int N = ;
int D = ;
int Xprefix_[] = ;
vector <int> Xprefix(Xprefix_, Xprefix_+sizeof(Xprefix_)/sizeof(*Xprefix_));
int Yprefix_[] = ;
vector <int> Yprefix(Yprefix_, Yprefix_+sizeof(Yprefix_)/sizeof(*Yprefix_));
int L = ;
int seed = ;
int __[] = ;
vector <int> _(__, __+sizeof(__)/sizeof(*__));
END
*/
}
// END CUT HERE