/*
written by- Piyush Golani
language- c++
country- India
College- N.I.T Jamshedpur
*/
#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<queue>
#include<cctype>
using namespace std;
#define pb push_back
#define all(s) s.begin(),s.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>=b;i--)
#define PI 3.1415926535897932384626433832795
#define INF 2000000000
#define BIG_INF 7000000000000000000LL
#define mp make_pair
#define eps 1e-9
#define LL long long
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define mod 1000000007
#define mm 10000000
string inttostring(int n)
{
stringstream a;
a<<n;
return a.str();
}
int stringtoint(string A)
{
istringstream a(A);
int p;
a>>p;
return p;
}
class CakeParty {
public:
int digit(int a)
{
return inttostring(a).size();
}
string get(int a,int b)
{
if(digit(a)==digit(b)) return inttostring(a);
string cand1="1";
f(i,0,digit(a)) cand1+="0";
string cand2=inttostring(a);
f(i,0,cand2.size())
{
if(cand1[i]==cand2[i]) continue;
if(cand1[i]<cand2[i]) return cand1;
if(cand1[i]>cand2[i]) break;
}
return cand2;
}
string makeMove( vector <int> pieces ) {
int max1=-INF;
int n=pieces.size();
if(n==1)
{
return "CAKE 0 PIECES "+inttostring(pieces[0]);
}
f(i,0,n) max1=max(max1,pieces[i]);
int max2=-INF;
f(i,0,n)
{
if(pieces[i]==max1) continue;
max2=max(max2,pieces[i]);
}
int c1=0,c2=0;
f(i,0,n)
{
if(pieces[i]==max1) c1++;
if(pieces[i]==max2) c2++;
}
string cake="A";
f(i,0,n) if(pieces[i]==max1) {cake=min(cake,inttostring(i));}
string p;
if(c1%2==0) p='1';
else
{
if(c1>1) p='1';
else
{
if(c2%2!=0)
{
p=inttostring(max1-max2);
}
else
{
p=get(max1-max2+1,max1);
}
}
}
//cout<<c1<<" "<<c2<<"\n";
//cout<<p<<"\n";
string res="CAKE "+ cake +" PIECES "+ p;
return res;
}
};
// BEGIN CUT HERE
namespace moj_harness {
int run_test_case(int);
void run_test(int casenum = -1, bool quiet = false) {
if (casenum != -1) {
if (run_test_case(casenum) == -1 && !quiet) {
cerr << "Illegal input! Test case " << casenum << " does not exist." << endl;
}
return;
}
int correct = 0, total = 0;
for (int i=0;; ++i) {
int x = run_test_case(i);
if (x == -1) {
if (i >= 100) break;
continue;
}
correct += x;
++total;
}
if (total == 0) {
cerr << "No test cases run." << endl;
} else if (correct < total) {
cerr << "Some cases FAILED (passed " << correct << " of " << total << ")." << endl;
} else {
cerr << "All " << total << " tests passed!" << endl;
}
}
int verify_case(int casenum, const string &expected, const string &received, clock_t elapsed) {
cerr << "Example " << casenum << "... ";
string verdict;
vector<string> info;
char buf[100];
if (elapsed > CLOCKS_PER_SEC / 200) {
sprintf(buf, "time %.2fs", elapsed * (1.0/CLOCKS_PER_SEC));
info.push_back(buf);
}
if (expected == received) {
verdict = "PASSED";
} else {
verdict = "FAILED";
}
cerr << verdict;
if (!info.empty()) {
cerr << " (";
for (int i=0; i<(int)info.size(); ++i) {
if (i > 0) cerr << ", ";
cerr << info[i];
}
cerr << ")";
}
cerr << endl;
if (verdict == "FAILED") {
cerr << " Expected: \"" << expected << "\"" << endl;
cerr << " Received: \"" << received << "\"" << endl;
}
return verdict == "PASSED";
}
int run_test_case(int casenum__) {
switch (casenum__) {
case 0: {
int pieces[] = {47};
string expected__ = "CAKE 0 PIECES 47";
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 1: {
int pieces[] = {3,3};
string expected__ = "CAKE 0 PIECES 1";
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 2: {
int pieces[] = {3,5};
string expected__ = "CAKE 1 PIECES 2";
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 3: {
int pieces[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1};
string expected__ = "CAKE 0 PIECES 1";
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 4: {
int pieces[] = {3,3,112};
string expected__ = "CAKE 2 PIECES 110";
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 5: {
int pieces[] = {3,3,1};
string expected__ = "CAKE 0 PIECES 1";
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 6: {
int pieces[] = {4,7,4,7,4,7,4,7,47,47,47,47};
string expected__ = "CAKE 10 PIECES 1";
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}
// custom cases
/* case 7: {
int pieces[] = ;
string expected__ = ;
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}*/
/* case 8: {
int pieces[] = ;
string expected__ = ;
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}*/
/* case 9: {
int pieces[] = ;
string expected__ = ;
clock_t start__ = clock();
string received__ = CakeParty().makeMove(vector <int>(pieces, pieces + (sizeof pieces / sizeof pieces[0])));
return verify_case(casenum__, expected__, received__, clock()-start__);
}*/
default:
return -1;
}
}
}
int main(int argc, char *argv[]) {
if (argc == 1) {
moj_harness::run_test();
} else {
for (int i=1; i<argc; ++i)
moj_harness::run_test(atoi(argv[i]));
}
}
// END CUT HERE
LyoKd3JpdHRlbiBieS0gUGl5dXNoIEdvbGFuaQpsYW5ndWFnZS0gYysrCmNvdW50cnktIEluZGlhCkNvbGxlZ2UtIE4uSS5UIEphbXNoZWRwdXIKKi8KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGU8Y3N0ZGlvPgojaW5jbHVkZTxzc3RyZWFtPgojaW5jbHVkZTxhbGdvcml0aG0+CiNpbmNsdWRlPGNzdGRsaWI+CiNpbmNsdWRlPGNzdHJpbmc+CiNpbmNsdWRlPG1hcD4KI2luY2x1ZGU8cXVldWU+CiNpbmNsdWRlPGNjdHlwZT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBhbGwocykgcy5iZWdpbigpLHMuZW5kKCkKI2RlZmluZSBmKGksYSxiKSBmb3IoaW50IGk9YTtpPGI7aSsrKQojZGVmaW5lIEYoaSxhLGIpIGZvcihpbnQgaT1hO2k+PWI7aS0tKQojZGVmaW5lIFBJIDMuMTQxNTkyNjUzNTg5NzkzMjM4NDYyNjQzMzgzMjc5NQojZGVmaW5lIElORiAyMDAwMDAwMDAwCiNkZWZpbmUgQklHX0lORiA3MDAwMDAwMDAwMDAwMDAwMDAwTEwKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBlcHMgMWUtOQojZGVmaW5lIExMIGxvbmcgbG9uZwojZGVmaW5lIHNpKG4pIHNjYW5mKCIlZCIsJm4pCiNkZWZpbmUgc2xsKG4pIHNjYW5mKCIlbGxkIiwmbikKI2RlZmluZSBtb2QgMTAwMDAwM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llY2VzWzBdKTsKICAgIH0KICAgIGYoaSwwLG4pIG1heDE9bWF4KG1heDEscGllY2VzW2ldKTsKICAgIGludCBtYXgyPS1JTkY7CiAgICBmKGksMCxuKQogICAgewogICAgICAgIGlmKHBpZWNlc1tpXT09bWF4MSkgY29udGludWU7CiAgICAgICAgbWF4Mj1tYXgobWF4MixwaWVjZXNbaV0pOwogICAgfQogICAgaW50IGMxPTAsYzI9MDsKICAgIGYoaSwwLG4pCiAgICB7CiAgICAgICAgaWYocGllY2VzW2ldPT1tYXgxKSBjMSsrOwogICAgICAgIGlmKHBpZWNlc1tpXT09bWF4MikgYzIrKzsKICAgIH0KICAgIHN0cmluZyBjYWtlPSJBIjsKICAgIGYoaSwwLG4pIGlmKHBpZWNlc1tpXT09bWF4MSkge2Nha2U9bWluKGNha2UsaW50dG9zdHJpbmcoaSkpO30KICAgIHN0cmluZyBwOwogICAgaWYoYzElMj09MCkgcD0nMSc7CiAgICBlbHNlCiAgICB7CiAgICAgICAgaWYoYzE+MSkgcD0nMSc7CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgaWYoYzIlMiE9MCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcD1pbnR0b3N0cmluZyhtYXgxLW1heDIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcD1nZXQobWF4MS1tYXgyKzEsbWF4MSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICAvL2NvdXQ8PGMxPDwiICI8PGMyPDwiXG4iOwogICAgLy9jb3V0PDxwPDwiXG4iOwogICAgc3RyaW5nIHJlcz0iQ0FLRSAiKyBjYWtlICsiIFBJRUNFUyAiKyBwOwogICAgcmV0dXJuIHJlczsKICAgfQp9OwoKLy8gQkVHSU4gQ1VUIEhFUkUKbmFtZXNwYWNlIG1val9oYXJuZXNzIHsKICAgIGludCBydW5fdGVzdF9jYXNlKGludCk7Cgl2b2lk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