#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;

template<typename T>
struct RMQ
{
	vector< vector<int> > rm;
	vector<T> d;

	RMQ( const vector<T>& d ) : d(d) {
		int n = d.size();

		// rm[k][x] = z s.t. d[z] is the minimum in [x, x+2^k)
		rm.push_back( vector<int>(n) );
		for(int x=0; x<n; ++x)
			rm[0][x] = x;
		for(int k=1; (1<<k)<=n; ++k) {
			rm.push_back( rm[k-1] );
			for(int x=0; x+(1<<k-1)<n; ++x)
				if( d[rm[k][x]] > d[rm[k-1][x + (1<<k-1)]] )
					rm[k][x] = rm[k-1][x + (1<<k-1)];
		}
	}

	int operator()(int L, int R) const { // inclusive
		int k=0;
		for(; L+(1<<k) < R-(1<<k)+1; ++k) {}
		LL i = rm[k][L];
		LL j = rm[k][R-(1<<k)+1];
		return (d[i]<=d[j] ? i : j);
	}
};

class BuildingAdvertise
{
public:
	long long getMaxArea(vector <int> hseed, int n) 
	{
		// input
		LL j = 0;
		LL m = hseed.size();
		vector<LL> h(n);
		for(int i=0; i<n; ++i) {
			h[i] = hseed[j];
			LL s = (j+1)%m;
			hseed[j] = ( ( hseed[j] ^ hseed[s] ) + 13 ) % 835454957;
			j = s;
		}

		// solve
		return rec(RMQ<LL>(h), h, 0, n-1);
	}
	LL rec(const RMQ<LL>& rmq, vector<LL>& h, LL L, LL R)
	{
		LL result = 0;

		stack< pair<LL,LL> > S;
		S.push( make_pair(L,R) );
		while( !S.empty() )
		{
			L = S.top().first;
			R = S.top().second;
			S.pop();

			LL C = rmq(L, R);
			if( L < C ) S.push( make_pair(L,C-1) );
			if( C < R ) S.push( make_pair(C+1,R) );
			result = max(result, (R-L+1) * h[C]);
		}

		return result;
	}

// BEGIN CUT HERE
	public:
	void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); }
	private:
	template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
	void verify_case(int Case, const long long &Expected, const long long &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
	void test_case_0() { int Arr0[] = {3,6,5,6,2,4}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 6; long long Arg2 = 15LL; verify_case(0, Arg2, getMaxArea(Arg0, Arg1)); }
	void test_case_1() { int Arr0[] = {5,0,7,0,2,6,2}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 7; long long Arg2 = 7LL; verify_case(1, Arg2, getMaxArea(Arg0, Arg1)); }
	void test_case_2() { int Arr0[] = {1048589,2097165}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 100000; long long Arg2 = 104858900000LL; verify_case(2, Arg2, getMaxArea(Arg0, Arg1)); }
	void test_case_3() { int Arr0[] = {1,7,2,5,3,1}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 6; long long Arg2 = 8LL; verify_case(3, Arg2, getMaxArea(Arg0, Arg1)); }

// END CUT HERE
};
// BEGIN CUT HERE 
int main() { BuildingAdvertise().run_test(-1); }
// END CUT HERE
