Problem:
Score : 1600 points

Problem Statement

For a string S, let f(S) be the lexicographically smallest cyclic shift of S.
For example, if S = babca, f(S) = ababc because this is the smallest among all cyclic shifts (babca, abcab, bcaba, cabab, ababc).

You are given three integers X, Y, and Z.
You want to construct a string T that consists of exactly X as, exactly Y bs, and exactly Z cs.
If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.

Compute the lexicographically largest possible value of f(T).

Constraints

1 \leq X + Y + Z \leq 50

X, Y, Z are non-negative integers.

Input

Input is given from Standard Input in the following format:

X Y Z

Output

Print the answer.

Sample Input 1

2 2 0

Sample Output 1

abab

T must consist of two as and two bs.

If T = aabb, f(T) = aabb.

If T = abab, f(T) = abab.

If T = abba, f(T) = aabb.

If T = baab, f(T) = aabb.

If T = baba, f(T) = abab.

If T = bbaa, f(T) = aabb.

Thus, the largest possible f(T) is abab.

Sample Input 2

1 1 1

Sample Output 2

acb

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

string solve(int X,int Y,int Z)
{
	//printf("%d %d %d\n",X,Y,Z);
	if(Y==0&&Z==0)
	{
		string ret="";
		for(int i=0;i<X;i++) ret+="A";
		return ret;
	}
	if(X==0)
	{
		string ret=solve(Y,Z,0);
		for(int i=0;i<ret.size();i++)
		{
			if(ret[i]=='A') ret[i]='B';
			else ret[i]='C';
		}
		return ret;
	}
	else if(Y==0)
	{
		string ret=solve(X,Z,0);
		for(int i=0;i<ret.size();i++) if(ret[i]=='B') ret[i]='C';
		return ret;
	}
	if(Z==0)
	{
		if(X%Y==0)
		{
			string ret="";
			for(int i=0;i<Y;i++)
			{
				for(int j=0;j<X/Y;j++) ret+="A";
				ret+="B";
			}
			return ret;
		}
		string ret=solve(X%Y,Y-(X%Y),0);
		string ans="";
		for(int i=0;i<ret.size();i++)
		{
			if(ret[i]=='A')
			{
				for(int j=0;j<=X/Y;j++) ans+="A";
				ans+="B";
			}
			else
			{
				for(int j=0;j<X/Y;j++) ans+="A";
				ans+="B";
			}
		}
		//printf("%d %d %d : %s\n",X,Y,Z,ans.c_str());
		return ans;
	}
	int z=X%(Y+Z),k=(X+Y+Z-1)/(Y+Z);
	if(z==0) z=Y+Z;
	if(z<=Z)
	{
		string ret=solve(z,Y,Z-z);
		string ans="";
		for(int i=0;i<ret.size();i++)
		{
			if(ret[i]=='A')
			{
				for(int j=0;j<k;j++) ans+="A";
				ans+="C";
			}
			else
			{
				for(int j=0;j<k-1;j++) ans+="A";
				ans+=ret[i];
			}
		}
		//printf("%d %d %d : %s\n",X,Y,Z,ans.c_str());
		return ans;
	}
	else
	{
		string ret=solve(z-Z,Z,Y-(z-Z));
		string ans="";
		for(int i=0;i<ret.size();i++)
		{
			if(ret[i]=='C')
			{
				for(int j=0;j<k-1;j++) ans+="A";
				ans+="B";
			}
			else
			{
				for(int j=0;j<k;j++) ans+="A";
				if(ret[i]=='A') ans+="B";
				else ans+="C";
			}
		}
		return ans;
	}
	return "";
}
int main()
{
	int X,Y,Z;
	scanf("%d %d %d",&X,&Y,&Z);
	string ret=solve(X,Y,Z);
	for(int i=0;i<ret.size();i++)
	{
		if(ret[i]=='A') ret[i]='a';
		if(ret[i]=='B') ret[i]='b';
		if(ret[i]=='C') ret[i]='c';
	}
	printf("%s\n",ret.c_str());
	return 0;
}