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



Sample input:
2 2 0


Sample output:
abab

Submission status: Wrong Answer

Solution code:
def work(a,b,c,A,B,C):
 if A==0:
  return work(b,c,'',B,C,0)
 if B==0:
  if C==0:
   return a*A
  else:
   return work(a,c,'',A,C,0)
 if C==0:
  return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0)
 cmod = C%A
 if B <= A-cmod:
  return work(a+c*(C/A),a+c*(C/A)+b,a+c*(C/A+1),A-cmod-B,B,cmod)
 else:
  B = B - (A-cmod)
  bmod = B%A
  if bmod>=cmod:
   return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A)+b*(B/A+2),a+c*(C/A+1)+b*(B/A+1),A-bmod,bmod-cmod,cmod)
  else:
   return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),a+c*(C/A+1)+b*(B/A+1),A-cmod,cmod-bmod,bmod)

if __name__ == '__main__':
 s = raw_input()
 a,b,c = [int(i) for i in s.split()]
 print(work('a','b','c',a,b,c))

Submission status: Wrong Answer

Solution code:
def work(a,b,c,A,B,C):
    if A==0:
        return work(b,c,'',B,C,0)
    if B==0:
        if C==0:
            return a*A
        else:
            return work(a,c,'',A,C,0)
    if C==0:
        return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0)
    cmod = C%A
    bmod = B%(A-cmod)
    return work(a+c*(C/A+1),a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),cmod,A-cmod-bmod,bmod)

if __name__ == '__main__':
    s = raw_input()
    a,b,c = [int(i) for i in s.split()]
    print(work('a','b','c',a,b,c))

Submission status: Wrong Answer

Solution code:
def work(a,b,c,A,B,C):
    if A==0:
        return work(b,c,'',B,C,0)
    if B==0:
        if C==0:
            return a*A
        else:
            return work(a,c,'',A,C,0)
    if C==0:
        return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0)
    cmod = C%A
    bmod = B%(A-cmod)
    return work(a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),a+c*(C/A+1),A-cmod-bmod,bmod,cmod)

if __name__ == '__main__':
    s = raw_input()
    a,b,c = [int(i) for i in s.split()]
    print(work('a','b','c',a,b,c))

Submission status: Wrong Answer

Solution code:
def work(a,b,c,A,B,C):
    if A==0:
        return work(b,c,'',B,C,0)
    if B==0:
        if C==0:
            return a*A
        else:
            return work(a,c,'',A,C,0)
    if C==0:
        return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0)
    cmod = C%A
    bmod = B%A
    if cmod+bmod<=A:
        return work(a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),A-cmod-bmod,bmod,cmod)
    else:
        return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),a+c*(C/A+1)+b*(B/A+1),A-cmod,A-bmod,bmod+cmod-A)

if __name__ == '__main__':
    s = raw_input()
    a,b,c = [int(i) for i in s.split()]
    print(work('a','b','c',a,b,c))

Submission status: Wrong Answer

Solution code:
def work(a,b,c,A,B,C):
    if A==0:
        return work(b,c,'',B,C,0)
    if B==0:
        if C==0:
            return a*A
        else:
            return work(a,c,'',A,C,0)
    if C==0:
        return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0)
    cmod = C%A
    bmod = B%A
    if cmod+bmod<=A:
        return work(a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),A-cmod-bmod,bmod,cmod)
    else:
        return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),a+c*(C/A+1)+b*(B/A+1),bmod,cmod,bmod+cmod-A)

if __name__ == '__main__':
    s = raw_input()
    a,b,c = [int(i) for i in s.split()]
    print(work('a','b','c',a,b,c))

Submission status: Wrong Answer

Solution code:
def work(a,b,c,A,B,C):
    if A==0:
        return work(b,c,'',B,C,0)
    if B==0:
        if C==0:
            return a*A
        else:
            return work(a,c,'',A,C,0)
    if C==0:
        return work(a+b*(B/A+1),a+b*(B/A),'',B%A,A-B%A,0)
    cmod = C%A
    bmod = B%A
    if cmod+bmod<=A:
        return work(a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),A-cmod-bmod,bmod,cmod)
    else:
        return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),a+c*(C/A+1)+b*(B/A+1),bmod,cmod,bmod+cmod-A)

if __name__ == '__main__':
    s = raw_input()
    a,b,c = [int(i) for i in s.split()]
    print(work('a','b','c',a,b,c))

Submission status: Wrong Answer

Solution code:
from itertools import permutations,count,chain
from collections import deque

def helper(s):
  for i in range(len(s)):
    yield s[i:]+s[:i]

def naive(a,b,c):
  return max(min(helper(s)) for s in permutations('a'*a+'b'*b+'c'*c))

def solve(a,b,c):
  def helper(a,b,c):
    cnt = (a,b,c).count(0)
    if cnt == 3:
      return []
    elif cnt == 2:
      n,i = max((x,i) for i,x in enumerate((a,b,c)))
      return [i]*n
    elif cnt == 1:
      (l,nl),(u,nu) = ((i,x) for i,x in enumerate((a,b,c)) if x != 0)
      
      n = nl//nu
      return tuple(reversed(([u]+[l]*n)*nu + [l]*(nl-n*nu)))



    n0 = c%a
    n1 = a - n0

    m0 = b%n1
    m1 = n1-m0
    R = helper(m1,m0,n0)

    nc = c//a
    nb = b//n1

    s = ([0] + [2]*nc + [1]*nb, [0] + [2]*nc + [1]*(nb+1), [0] + [2]*(nc+1))
    return tuple(chain.from_iterable(s[r] for r in R))

  s = ('a','b','c')
  return ''.join(s[i] for i in helper(a,b,c))

print(solve(*map(int,input().split())))

Submission status: Wrong Answer

Solution code:
X, Y, Z = map(int, input().split())

d = []
if X > 0:
    if (Y+Z) > 0: 
        j = max(X//(Y+Z), 1)
    else:
        j = 1
    
    for _ in range(X//j):
        d.append("a"*j)
        
    for i in range(X-j*(X//j)):
        d[i] = d[i] + "a"
    
    for i in range(len(d)):
        d[i] = d[i] + "c"*(Z//X)
    
    for i in range(Z-(Z//X)*X):
        d[len(d)-i-1] = d[len(d)-i-1] + "c"
        
    for i in range(len(d)):
        d[i] = d[i] + "b"*(Y//X)
    
    for i in range(Y-(Y//X)*X):
        d[len(d)-i-1] = d[len(d)-i-1] + "b"
    
elif Y > 0:
    if (Z) > 0: 
        j = max(Y//Z, 1)
    else:
        j = 1
    
    for _ in range(Y//j):
        d.append("b"*j)
        
    for i in range(Y-j*(Y//j)):
        d[i] = d[i] + "b"    
    
    for i in range(len(d)):
        d[i] = d[i] + "c"*(Z//Y)
    
    for i in range(Z-(Z//Y)*Y):
        d[len(d)-i-1] = d[len(d)-i-1] + "c"
        
else:
    for _ in range(Z):
        d.append("c")

print("".join(d))

Submission status: Wrong Answer

Solution code:
X, Y, Z = map(int, input().split())

d = []
if X > 0:
    for _ in range(X):
        d.append("a")
    for i in range(len(d)):
        d[i] = d[i] + "c"*(Z//X)
    
    for i in range(Z-(Z//X)*X):
        d[len(d)-i-1] = d[len(d)-i-1] + "c"
        
    for i in range(len(d)):
        d[i] = d[i] + "b"*(Y//X)
    
    for i in range(Y-(Y//X)*X):
        d[len(d)-i-1] = d[len(d)-i-1] + "b"
    
elif Y > 0:
    for _ in range(Y):
        d.append("b")
    for i in range(len(d)):
        d[i] = d[i] + "c"*(Z//Y)
    
    for i in range(Z-(Z//Y)*Y):
        d[len(d)-i-1] = d[len(d)-i-1] + "c"
        
else:
    for _ in range(Z):
        d.append("c")

print("".join(d))

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations


def shift(seq):
    res = []
    for _ in range(len(seq)):
        res.append(seq)
        seq = seq[1:]+seq[0]
    return min(res)

N = [int(i) for i in input().split(" ")]

seq = "a"*N[0] + "b"*N[1] + "c"*N[2]
print(max([shift("".join(i)) for i in set([s for s in permutations(seq)])]))

Submission status: Accepted

Solution code:
def work(a,b,c,A,B,C):
 if A==0:
  return work(b,c,'',B,C,0)
 if B==0:
  if C==0:
   return a*A
  else:
   return work(a,c,'',A,C,0)
 if C==0:
  return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0)
 cmod = C%A
 if B <= A-cmod:
  return work(a+c*(C/A),a+c*(C/A)+b,a+c*(C/A+1),A-cmod-B,B,cmod)
 else:
  bmod = B%(A-cmod)
  return work(a+c*(C/A)+b*(B/(A-cmod)),a+c*(C/A)+b*(B/(A-cmod)+1),a+c*(C/A+1),A-bmod-cmod,bmod,cmod)

if __name__ == '__main__':
 s = raw_input()
 a,b,c = [int(i) for i in s.split()]
 print(work('a','b','c',a,b,c))

Submission status: Accepted

Solution code:
x, y, z = map(int, raw_input().split())
a = ['a'] * x + ['b'] * y + ['c'] * z

while len(a) > 1:
    a = sorted(a[1:-1] + [a[0] + a[-1]])

print a[0]

Submission status: Accepted

Solution code:
a,b,c = map(int,input().split())

L = [[0] for _ in range(a)] + [[1] for _ in range(b)] + [[2] for _ in range(c)]
while len(L) > 1:
  L[0] += L.pop()
  L.sort()
print(''.join(('a','b','c')[i] for i in L[0]))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def main():
    x,y,z = LI()
    a = ['a' for _ in range(x)] + ['b' for _ in range(y)] + ['c' for _ in range(z)]
    while len(a) > 1:
        a.sort()
        a[0] += a[-1]
        a = a[:-1]

    return a[0]


print(main())

Submission status: Runtime Error

Solution code:
def work(a,b,c,A,B,C):
    if A==0:
        return work(b,c,'',B,C,0)
    if B==0:
        if C==0:
            return a*A
        else:
            return work(a,c,'',A,C,0)
    if C==0:
        return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0)
    cmod = C%A
	if B <= A-cmod:
		return work(a+c*(C/A),a+c*(C/A)+b,a+c*(C/A+1),A-cmod-B,B,cmod)
	else:
		B = B - (A-cmod)
		bmod = B%A
		if bmod>=cmod:
			return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A)+b*(B/A+2),a+c*(C/A+1)+b*(B/A+1),A-bmod,bmod-cmod,cmod)
		else:
			return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),a+c*(C/A+1)+b*(B/A+1),A-cmod,cmod-bmod,bmod)

if __name__ == '__main__':
    s = raw_input()
    a,b,c = [int(i) for i in s.split()]
    print(work('a','b','c',a,b,c))