Artifact 26bf2a688a29c24dfae5fef984a084b579fcc617
#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>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;
static const int MODVAL = 1000000007; // must be prime for op/
struct mint
{
int val;
mint():val(0){}
mint(int x):val(x%MODVAL) {} // x>=0
mint(size_t x):val(x%MODVAL) {} // x>=0
mint(LL x):val(x%MODVAL) {} // x>=0
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }
mint operator-(mint x) { return mint(0) - x; }
vector<mint> vMul( const vector< vector<mint> >& A, const vector<mint>& B )
{
const int n = A.size();
vector<mint> C(n);
for(int i=0; i<n; ++i)
for(int j=0; j<n; ++j)
C[i] += A[i][j] * B[j];
return C;
}
vector< vector<mint> > mMul( const vector< vector<mint> >& A, const vector< vector<mint> >& B )
{
const int n = A.size();
vector< vector<mint> > C(n, vector<mint>(n));
for(int i=0; i<n; ++i)
for(int j=0; j<n; ++j) {
mint Cij = 0;
for(int k=0; k<n; ++k)
Cij += A[i][k] * B[k][j];
C[i][j] = Cij;
}
return C;
}
vector< vector<mint> > mPow( vector< vector<mint> > M, LL t ) // t>0
{
vector< vector<mint> > R;
for(; t; t>>=1, M=mMul(M,M))
if( t&1 )
R = (R.empty() ? M : mMul(R,M));
return R;
}
class SplittingFoxes { public:
int sum(long long n, int S_, int L_, int R_)
{
mint S(S_), L(L_), R(R_);
enum {PR, PT, PL, PB, XR, XT, XL, XB, YR, YT, YL, YB, __};
vector< vector<mint> > M(13, vector<mint>(13));
M[PR][PR] = S; M[PR][YR] = S; M[PR][PT] = L; M[PR][PB] = R;
M[PT][PT] = S; M[PT][XT] = S; M[PT][PL] = L; M[PT][PR] = R;
M[PL][PL] = S; M[PL][YL] =-S; M[PL][PB] = L; M[PL][PT] = R;
M[PB][PB] = S; M[PB][XB] =-S; M[PB][PR] = L; M[PB][PL] = R;
M[XR][XR] = S; M[XR][__] = S; M[XR][XT] = L; M[XR][XB] = R;
M[XT][XT] = S; M[XT][__] = 0; M[XT][XL] = L; M[XT][XR] = R;
M[XL][XL] = S; M[XL][__] =-S; M[XL][XB] = L; M[XL][XT] = R;
M[XB][XB] = S; M[XB][__] = 0; M[XB][XR] = L; M[XB][XL] = R;
M[YR][YR] = S; M[YR][__] = 0; M[YR][YT] = L; M[YR][YB] = R;
M[YT][YT] = S; M[YT][__] = S; M[YT][YL] = L; M[YT][YR] = R;
M[YL][YL] = S; M[YL][__] = 0; M[YL][YB] = L; M[YL][YT] = R;
M[YB][YB] = S; M[YB][__] =-S; M[YB][YR] = L; M[YB][YL] = R;
M[__][__] = S+L+R;
vector<mint> V(13);
V[__] = 1;
return vMul(mPow(M, n), V)[PR].val;
}
};
// 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 int& Expected, const 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(_, SplittingFoxes().sum(n, S, L, R));}
int main(){
CASE(0)
long long n = 58LL;
int S = 2;
int L = 0;
int R = 0;
int _ = 0;
END
CASE(1)
long long n = 3LL;
int S = 1;
int L = 1;
int R = 0;
int _ = 1;
END
CASE(2)
long long n = 5LL;
int S = 1;
int L = 3;
int R = 2;
int _ = 34;
END
CASE(3)
long long n = 5LL;
int S = 1;
int L = 2;
int R = 3;
int _ = 999999973;
END
CASE(4)
long long n = 123456789LL;
int S = 987654321;
int L = 544;
int R = 544;
int _ = 0;
END
CASE(5)
long long n = 65536LL;
int S = 1024;
int L = 512;
int R = 4096;
int _ = 371473914;
END
/*
CASE(6)
long long n = LL;
int S = ;
int L = ;
int R = ;
int _ = ;
END
CASE(7)
long long n = LL;
int S = ;
int L = ;
int R = ;
int _ = ;
END
*/
}
// END CUT HERE