$BEGINCUT$ $PROBLEMDESC$ $ENDCUT$ #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; $BEGINCUT$ #define ARRSIZE(x) (sizeof(x)/sizeof(x[0])) template void print( T a ) { cerr << a; } static void print( long long a ) { cerr << a << "L"; } static void print( string a ) { cerr << '"' << a << '"'; } template void print( vector a ) { cerr << "{"; for ( int i = 0 ; i != a.size() ; i++ ) { if ( i != 0 ) cerr << ", "; print( a[i] ); } cerr << "}" << endl; } template void eq( int n, T have, T need ) { if ( have == need ) { cerr << "Case " << n << " passed." << endl; } else { cerr << "Case " << n << " failed: expected "; print( need ); cerr << " received "; print( have ); cerr << "." << endl; } } template void eq( int n, vector have, vector need ) { if( have.size() != need.size() ) { cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements."; print( have ); print( need ); return; } for( int i= 0; i < have.size(); i++ ) { if( have[i] != need[i] ) { cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << "."; print( have ); print( need ); return; } } cerr << "Case " << n << " passed." << endl; } static void eq( int n, string have, string need ) { if ( have == need ) { cerr << "Case " << n << " passed." << endl; } else { cerr << "Case " << n << " failed: expected "; print( need ); cerr << " received "; print( have ); cerr << "." << endl; } } $ENDCUT$ #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i,a,b) for(int i=(a);i>=(b);--i) #define FOREACH(it,c) for(typeof((c).begin())it=(c).begin();it!=(c).end();++it) #define CLR(x) memset((x),0,sizeof((x))) #define SORT(x) sort(x.begin(), x.end()) #define REVERSE(x) reverse(x.begin(), x.end()) #define SZ(x) x.size() #define MP make_pair #define MPI make_pair #define PB push_back typedef long long LL; typedef vector VB; typedef vector VI; typedef vector > VVI; typedef vector VS; typedef pair PI; typedef vector > VPI; $BEGINCUT$ vector split( const string& s, const string& delim =" " ) { vector res; string t; for ( int i = 0 ; i != s.size() ; i++ ) { if ( delim.find( s[i] ) != string::npos ) { if ( !t.empty() ) { res.push_back( t ); t = ""; } } else { t += s[i]; } } if ( !t.empty() ) { res.push_back(t); } return res; } vector splitInt( const string& s, const string& delim =" " ) { vector tok = split( s, delim ); vector res; for ( int i = 0 ; i != tok.size(); i++ ) res.push_back( atoi( tok[i].c_str() ) ); return res; } $ENDCUT$ $BEGINCUT$ int s2i(string s) { stringstream ss; ss << s; int res; ss >> res; return res; } string i2s(int n) { stringstream ss; ss << n; string res; ss >> res; return res; } $ENDCUT$ class $CLASSNAME$ { public: $RC$ $METHODNAME$($METHODPARMS$) { $RC$ res; return res; } $WRITERCODE$ }; $BEGINCUT$ int main() { $MAINBODY$ return 0; } $ENDCUT$