Artifact fd5e5eb809d8d0f915f42b2470fbb0d08f8c580c
#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;
class AlternateColors2 { public:
long long countWays(int n, int k)
{
LL total = 0;
for(int mini=0; mini*3<=n; ++mini)
{
if(mini*3 == n) {
total += rgb(mini, mini, mini, k) ? 1 : 0;
} else {
total += rgb(mini, mini, n-mini*2, k) ? 1 : 0;
total += rgb(mini, n-mini*2, mini, k) ? 1 : 0;
total += rgb(n-mini*2, mini, mini, k) ? 1 : 0;
int free = n - mini*3;
if(free >= 2) {
if(k <= mini*3) {
if((k-1)%3==0) {
total += (free - 1)*3;
}
} else {
total += twoball(free, k-mini*3) * 2;
}
}
}
}
return total;
}
bool rgb(int r, int g, int b, int k) {
int mini = min(r, min(g, b));
if( k <= mini*3 )
return (k-1)%3==0;
r -= mini;
g -= mini;
b -= mini;
k -= mini*3;
if(r==0) return false;
if(g==0) return xx(r,b,k);
if(b==0) return xx(r,g,k);
}
bool xx(int r, int g, int k)
{
int mini = min(r,g);
if( k <= mini*2 )
return (k-1)%2 == 0;
r -= mini;
g -= mini;
k -= mini*2;
return r>0;
}
LL twoball(int n, int k)
{
int MM = (k-1)/2;
LL total = MM;
if( (MM+1)*2 <= n && (k-1)%2==0 )
total += (n-(MM+1)*2 + 1);
return total;
}
};
// 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 long long& Expected, const long long& 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(_, AlternateColors2().countWays(n, k));}
int main(){
CASE(0)
int n = 1;
int k = 1;
long long _ = 1LL;
END
CASE(1)
int n = 3;
int k = 3;
long long _ = 3LL;
END
CASE(2)
int n = 6;
int k = 4;
long long _ = 9LL;
END
CASE(3)
int n = 6;
int k = 1;
long long _ = 21LL;
END
CASE(4)
int n = 1000;
int k = 2;
long long _ = 1LL;
END
CASE(5)
int n = 100000;
int k = 100000;
long long _ = 1666700000LL;
END
CASE(6)
int n = 100000;
int k = 100;
long long _ = -1LL;
END
/*
CASE(7)
int n = ;
int k = ;
long long _ = LL;
END
*/
}
// END CUT HERE