This challenge uses the famous KMP algorithm. It isn't really important to understand how KMP works, but you should understand what it calculates.

A KMP algorithm takes a string, $\mbox{S}$, of length $N$ as input. Let's assume that the characters in $\mbox{S}$ are indexed from $\mbox{1}$ to $N$; for every prefix of $\mbox{S}$, the algorithm calculates the length of its longest valid border in linear complexity. In other words, for every $\boldsymbol{i}$ (where $1\leq i\leq N$) it calculates the largest $\boldsymbol{l}$ (where $0\leq l\leq i-1$) such that for every $\boldsymbol{p}$ (where $1\leq p\leq l$) there is $S[p]=S[i-l+p]$.

Here is an implementation example of KMP:

kmp[1] = 0;
for (i = 2; i <= N; i = i + 1){
    l = kmp[i - 1];
    while (l > 0 && S[i] != S[l + 1]){
        l = kmp[l];
    }
    if (S[i] == S[l + 1]){
        kmp[i] = l + 1;
    }
    else{
        kmp[i] = 0;
    }
}

Given a sequence $x_1,x_2,\ldots,x_{26}$, construct a string, $\mbox{S}$, that meets the following conditions:

The frequency of letter '$\boldsymbol{a}$' in $\mbox{S}$ is exactly $x_1$, the frequency of letter '$\boldsymbol{b}$' in $\mbox{S}$ is exactly $x_2$, and so on.
Let's assume characters of $\mbox{S}$ are numbered from $\mbox{1}$ to $N$, where $\sum\limits_{i=1}^{n}x_{i}=N$. We apply the KMP algorithm to $\mbox{S}$ and get a table, $kmp$, of size $N$. You must ensure that the sum of $kmp[i]$ for all $\boldsymbol{i}$ is minimal.

If there are multiple strings which fulfill the above conditions, print the lexicographically smallest one.

Input Format

A single line containing $26$ space-separated integers describing sequence $\boldsymbol{x}$. 

Constraints

The sum of all $x_i$ will be a positive integer $\leq10^{6}$.

Output Format

Print a single string denoting $\mbox{S}$.

Sample Input
2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample Output
aabb

Explanation

The output string must have two '$\boldsymbol{a}$' and two '$\boldsymbol{b}$'. There are several such strings but we must ensure that sum of $kmp[i]$ for all $1<=i<=4$ is minimal. See the figure below:

The minimum sum is $\mbox{1}$. Among all the strings that satisfy both the condition, "aabb" is the lexicographically smallest.

Source: hackerrank | Difficulty: MEDIUM_HARD
Tags: Constructive algorithms


Solutions:
from string import ascii_lowercase as A
import sys
x = list(map(int, input().split()))
used = [i for i in range(26) if x[i]]
if len(used) == 0:
	sys.exit()
if len(used) == 1:
	print(A[used[0]] * x[used[0]])
else:
	f = min(used, key=lambda a: (x[a], a))
	used = [a for a in used if a != f]
	if x[f] == 1:
		print(A[f] + ''.join((A[c] * x[c] for c in used)))
	elif f > used[0]:
		x[f] -= 1
		print(A[f] + ''.join((A[c] * x[c] for c in range(26))))
	elif 2 * (x[f] - 2) <= sum(x) - 2:
		res = 2 * A[f]
		b = ''.join((A[c] * x[c] for c in used))
		x[f] -= 2
		i = 0
		while x[f]:
			res += b[i] + A[f]
			i += 1
			x[f] -= 1
		res += b[i:]
		print(res)
	else:
		x[f] -= 1
		x[used[0]] -= 1
		print(A[f] + A[used[0]] + A[f] * x[f] + ''.join((A[c] * x[c] for c in used)))


x = list(map(int, input().strip().split()))
xp = list(set(x))
if 0 in xp:
	xp.remove(0)
minimo = min(xp)
i = 0
while x[i] != minimo:
	i += 1
letra_min = str(chr(97 + i))
sol = letra_min
x[i] -= 1
i2 = 0
while x[i2] == 0:
	i2 += 1
if i == i2:
	j = i + 1
	while j < len(x) and x[j] == 0:
		j += 1
	if j < len(x):
		if x[i] <= x[j]:
			for k in range(x[i]):
				sol += chr(97 + i) + chr(97 + j)
			for k in range(x[j] - x[i]):
				sol += chr(97 + j)
			x[i] = 0
			x[j] = 0
for j in range(len(x)):
	for k in range(x[j]):
		sol = sol + chr(97 + j)
print(sol)


import sys
c = [int(c_temp) for c_temp in input().strip().split(' ')]
letters = []
counts = []
min = -1
firstletter = -1
for i in range(26):
	if c[i] != 0:
		if firstletter == -1:
			firstletter = chr(ord('a') + i)
		letters += [chr(ord('a') + i)]
		counts += [c[i]]
		if min == -1 or counts[min] > c[i]:
			min = len(counts) - 1
letters = [letters[min]] + letters[0:min] + letters[min + 1:]
counts = [counts[min]] + counts[0:min] + counts[min + 1:]
s = ''
if firstletter == letters[0]:
	if counts[0] == 1 or counts[0] == 2 or len(counts) == 1:
		for i in range(len(letters)):
			for j in range(counts[i]):
				s += letters[i]
	elif sum(counts[1:]) + 2 >= counts[0]:
		s += letters[0] + letters[0]
		counts[0] -= 2
		while counts[0] > 0:
			s += letters[1]
			counts[1] -= 1
			if counts[1] == 0:
				letters = [letters[0]] + letters[2:]
				counts = [counts[0]] + counts[2:]
			s += letters[0]
			counts[0] -= 1
		for i in range(1, len(letters)):
			for j in range(counts[i]):
				s += letters[i]
	elif len(counts) > 2:
		s += letters[0]
		counts[0] -= 1
		s += letters[1]
		counts[1] -= 1
		for i in range(counts[0]):
			s += letters[0]
		counts[0] = 0
		s += letters[2]
		counts[2] -= 1
		for i in range(1, len(letters)):
			for j in range(counts[i]):
				s += letters[i]
	else:
		s += letters[0]
		counts[0] -= 1
		for i in range(counts[1]):
			s += letters[1]
		for i in range(counts[0]):
			s += letters[0]
else:
	s += letters[0]
	counts[0] -= 1
	i = 1
	while i < len(letters) and ord(letters[i]) < ord(letters[0]):
		for j in range(counts[i]):
			s += letters[i]
		i += 1
	for _ in range(counts[0]):
		s += letters[0]
	while i < len(letters):
		for j in range(counts[i]):
			s += letters[i]
		i += 1
print(s)


from itertools import permutations
from string import ascii_lowercase as letters
x = [int(x) for x in input().strip().split(' ')]
f = x.index(next((c for c in x if c > 0)))
m = min((c for c in x if c > 0))
ss = ''
if m == x[f] and m > 1:
	try:
		n = x[f + 1:].index(next((c for c in x[f + 1:] if c > 0))) + f + 1
		ss += letters[f] * 2
		ss += (letters[n] + letters[f]) * (m - 2)
		x[n] -= m - 2
		x[f] = 0
	except StopIteration:
		pass
else:
	i = x.index(m)
	ss += letters[i]
	x[i] -= 1
for (l, c) in zip(letters, x):
	ss += l * c
print(ss)


def iterCombo(n, L1, L2):
	if n == 1:
		return L1 + L2
	else:
		S = L1 * 2
		n -= 2
		for i in range(n):
			S += L2 + L1
		S += L2 * 2
		return S
X = [int(x) for x in input().strip().split()]
alphabet = 'abcdefghijklmnopqrstuvwxyz'
count = []
sortedcount = []
j = 0
for i in range(26):
	if X[i] > 0:
		count.append((X[i], alphabet[i], j))
		j += 1
sortedcount = sorted(count)
if len(count) == 0:
	print()
elif len(count) == 1:
	print(count[0][0] * count[0][1])
elif count[0][1] == sortedcount[0][1]:
	(c, letter, j) = sortedcount[0]
	S = iterCombo(c, letter, count[1][1])
	S += count[1][1] * (count[1][0] - c)
	for (c, letter, j) in count[2:]:
		S += letter * c
	print(S)
else:
	(c, letter, j) = sortedcount[0]
	S = letter
	if c == 1:
		count.remove(sortedcount[0])
	else:
		count[j] = (c - 1, letter, j)
	for (c, letter, j) in count:
		S += letter * c
	print(S)


import string
from itertools import zip_longest
from functools import partial

class Pair:

	def __init__(self, freq, letter):
		self.freq = freq
		self.letter = letter

	def __repr__(self):
		return 'Pair({0!r}, {1!r})'.format(self.freq, self.letter)
per_freq = lambda p: p.freq
per_letter = lambda p: p.letter
non_empty = lambda p: p.freq > 0
sorted_by_freq = lambda arr: sorted(filter(non_empty, arr), key=per_freq)
sorted_by_letter = lambda arr: sorted(filter(non_empty, arr), key=per_letter)

def kmp_table(S):
	N = len(S)
	kmp = [0] * N
	kmp[0] = 0
	for i in range(1, N):
		l = kmp[i - 1]
		while l > 0 and S[i] != S[l]:
			l = kmp[l - 1]
		if S[i] == S[l]:
			kmp[i] = l + 1
		else:
			kmp[i] = 0
	return kmp

def smallest_lexi(freqs):
	return ''.join((p.letter * p.freq for p in sorted_by_letter(freqs)))

def general_case(freqs):
	by_freq = sorted_by_freq(freqs)
	by_letter = sorted_by_letter(freqs)
	lowest = by_freq[0]
	ret = lowest.letter
	lowest.freq -= 1
	second = by_letter[0]
	ret += second.letter
	second.freq -= 1
	if second is lowest:
		other_string = smallest_lexi(by_freq[1:])
		ret += ''.join((x + y for (x, y) in zip_longest(other_string, lowest.letter * lowest.freq, fillvalue='')))
		return ret
	else:
		ret += smallest_lexi(by_freq)
		return ret
input_freqs = [Pair(int(x), string.ascii_letters[i]) for (i, x) in enumerate(input().strip().split())]
freqs = sorted([f for f in input_freqs if f.freq > 0], key=per_freq)
if freqs[0].freq <= 2:
	letter = freqs[0].letter
	freqs[0].freq -= 1
	print(freqs[0].letter + smallest_lexi(freqs))
else:
	s = general_case(freqs)
	print(s)


x = [int(x) for x in input().split()]
from string import ascii_lowercase as letters
s = ''.join([c * d for (c, d) in zip(letters, x)])
smallest = float('inf')
smallest_char = -1
for (c, d) in zip(letters, x):
	if 0 < d < smallest:
		smallest_char = c
		smallest = d
smallest_idx = ord(smallest_char) - ord('a')
danger = True
for d in x[:smallest_idx]:
	if d != 0:
		danger = False
swap_idx = str.find(s, smallest_char)
s = s[swap_idx] + s[:swap_idx] + s[swap_idx + 1:]

def interleave(a, b):
	a = list(a)
	b = list(b)
	ans = [val for pair in zip(a, b) for val in pair]
	extra_size = abs(len(a) - len(b))
	extra_list = max(a, b, key=len)
	if extra_size > 0:
		ans.extend(extra_list[-extra_size:])
	return ''.join(ans)
if danger:
	start = smallest_char * smallest
	end = s.replace(smallest_char, '')
	(start1, start2) = (start[:2], start[2:])
	s = start1 + interleave(end, start2)
print(s)


count = [int(i) for i in input().split()]
min_pos = 0
first = -1
second = -1
min_count = 10000000
for i in range(len(count)):
	if count[i] != 0:
		if first != -1 and second == -1:
			second = i
		if first == -1:
			first = i
		if count[i] < min_count:
			min_pos = i
			min_count = count[i]
charset = 'abcdefghijklmnopqrstuvwxyz'
if second == -1:
	result = charset[first] * count[first]
else:
	result = ''
	result += charset[min_pos]
	count[min_pos] -= 1
	if min_pos == first:
		result += (charset[first] + charset[second]) * count[first]
		count[second] -= count[first]
		count[first] = 0
	for i in range(len(count)):
		if count[i] != 0:
			result += charset[i] * count[i]
print(result)


import string
a = [int(_) for _ in input().split()]
c = string.ascii_lowercase
b = []
ans = ''
mn = min(filter(None, a))
for i in range(26):
	if a[i] == mn:
		ans += c[i]
		a[i] -= 1
		for j in range(i):
			ans += c[j] * a[j]
		if len(ans) == 1 and a[i]:
			while a[i]:
				ans += c[i]
				a[i] -= 1
				for j in range(i + 1, 26):
					if a[j]:
						ans += c[j]
						a[j] -= 1
						break
		for j in range(i, 26):
			ans += c[j] * a[j]
		break
print(ans)


import sys
frequencies = [int(inp) for inp in input().strip().split(' ')]
frequenciesAndChars = [(frequencies[i], i) for i in range(len(frequencies)) if frequencies[i] > 0]
sortedFrequencies = sorted(frequenciesAndChars)
result = ''
if len(sortedFrequencies) >= 2:
	iChar = sortedFrequencies[0][1]
	char = chr(ord('a') + iChar)
	if iChar == frequenciesAndChars[0][1] and frequencies[iChar] >= 3:
		iChar2 = frequenciesAndChars[1][1]
		char2 = chr(ord('a') + iChar2)
		result += char + (char + char2) * (frequencies[iChar] - 1)
		frequencies[iChar2] -= frequencies[iChar] - 1
		frequencies[iChar] = 0
	else:
		char = chr(ord('a') + iChar)
		result += char
		frequencies[iChar] -= 1
for iChar in range(len(frequencies)):
	freq = frequencies[iChar]
	if freq:
		char = chr(ord('a') + iChar)
		result += ''.join((char for i in range(freq)))
print(result)


def mySol(letters):
	min_c = 0
	S = ''
	oa = ord('a')
	m = 100000000000
	total = 0
	for i in range(26):
		total += letters[i]
		if letters[i] != 0 and letters[i] < m:
			m = letters[i]
			min_c = i
	if total == 0:
		return ''
	other_let = total - letters[min_c]
	S += chr(oa + min_c)
	letters[min_c] -= 1
	lex_less_count = 0
	for i in range(0, min_c):
		S += chr(oa + i) * letters[i]
		lex_less_count += letters[i]
		letters[i] = 0
	other_let -= lex_less_count
	if len(S) == 1 and lex_less_count == 0 and (letters[min_c] > 0):
		while letters[min_c] > 0 and other_let > 0:
			for i in range(min_c + 1, 26):
				while letters[i] > 0 and letters[min_c] > 0:
					S += chr(oa + min_c)
					S += chr(oa + i)
					letters[min_c] -= 1
					letters[i] -= 1
					other_let -= 1
	if letters[min_c] > 0:
		S += chr(oa + min_c) * letters[min_c]
		letters[min_c] = 0
	for i in range(min_c + 1, 26):
		S += chr(oa + i) * letters[i]
		other_let -= letters[i]
		letters[i] = 0
	S += chr(oa + min_c) * letters[min_c]
	total -= letters[min_c]
	letters[min_c] = 0
	return S
state = list(map(lambda x: int(x), input().split()))
print(mySol(state))


def get_next_index_front(not_index):
	for (index, num) in enumerate(nums):
		if num != 0 and index != not_index:
			return index
	return not_index

def get_next_index_before(not_index):
	found = False
	for (index, num) in reversed(list(enumerate(nums))):
		if index == not_index:
			found = True
		elif found and num != 0 and (index != not_index):
			return index
	return not_index

def get_base_index():
	min_num = float('inf')
	min_index = -1
	for (index, num) in enumerate(nums):
		if num != 0 and num < min_num:
			min_num = num
			min_index = index
	return min_index

def first_letter_algorithm():
	ans = ''
	base_index = get_base_index()
	ans += chr(char + base_index)
	nums[base_index] -= 1
	base = True
	while nums[base_index] > 0:
		if base:
			i = base_index
		else:
			i = get_next_index_front(base_index)
		ans += chr(char + i)
		nums[i] -= 1
		base = not base
	for (i, n) in enumerate(nums):
		ans += ''.join([chr(char + i)] * n)
	return ans

def not_first_letter_algorithm():
	ans = []
	base_index = get_base_index()
	ans.append(chr(char + base_index))
	nums[base_index] -= 1
	i = 0
	while i < len(nums):
		ans += [chr(char + i)] * nums[i]
		nums[i] = 0
		i += 1
	return ''.join(ans)
char = ord('a')
nums = [int(n) for n in input().split(' ')]
first_index = get_next_index_front(-1)
base_index = get_base_index()
if first_index == base_index:
	print(first_letter_algorithm())
else:
	print(not_first_letter_algorithm())


import sys
from string import ascii_lowercase as alphabet

def num_to_chr(n, num=1):
	return chr(n + 97) * num
x = [int(inp) for inp in input().strip().split(' ')]
n = sum(x)
used = []
first = None
minx = n + 1
for i in range(26):
	if x[i] > 0:
		used.append(i)
		if x[i] < minx:
			minx = x[i]
			first = i
if len(used) == 1:
	print(num_to_chr(used[0], n))
cfirst = num_to_chr(first)
s = cfirst
if first == used[0]:
	second = used[1]
	csecond = num_to_chr(second)
	s += (cfirst + csecond) * (x[first] - 1)
	s += csecond * (x[second] - x[first] + 1)
	used.pop(0)
	used.pop(0)
else:
	x[first] -= 1
for cnum in used:
	s += num_to_chr(cnum, x[cnum])
print(s)


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
inp = list(map(int, input().split()))
chr = sorted(map(list, filter(lambda p: p[0] != 0, zip(inp, string.ascii_lowercase))))
k = chr[0][1]
chr[0][0] -= 1
if chr[0][0] == 0:
	del chr[0]
chr = list(sorted(chr, key=lambda m: m[1]))
str = [k]
while chr:
	i = 0
	if len(str) > 1 and len(chr) > 1:
		if str[0] == str[1] == str[-1]:
			if k == chr[i][1]:
				i = 1
	str.append(chr[i][1])
	chr[i][0] -= 1
	if chr[i][0] == 0:
		del chr[i]
print(''.join(str))


import sys
ls = [int(t) for t in input().strip().split(' ')]
for i in range(26):
	if ls[i] > 0:
		break
mn = i
temp = i
for i in range(mn + 1, 26):
	if ls[i] > 0 and ls[i] < ls[mn]:
		mn = i
if temp != mn or ls[mn] <= 2 or sum(ls) == ls[mn]:
	ls[mn] = ls[mn] - 1
	print(chr(mn + 97), end='')
	for i in range(26):
		for j in range(ls[i]):
			print(chr(i + 97), end='')
	sys.exit()
print(chr(mn + 97), end='')
print(chr(mn + 97), end='')
ls[mn] = ls[mn] - 2
for i in range(mn + 1, 26):
	for j in range(ls[i]):
		print(chr(i + 97), end='')
		if ls[mn] != 0:
			print(chr(mn + 97), end='')
			ls[mn] = ls[mn] - 1


def addto(ar, char, count):
	for i in range(count):
		ar.append(char)

def get_least_count(ar):
	min = 1000000
	for i in range(len(ar)):
		if ar[i] != 0:
			if ar[i] < min:
				min = ar[i]
	return min
n = list(map(int, input().split()))
alpha = list('abcdefghijklmnopqrstuvwxyz')
s = []
for i in range(26):
	addto(s, alpha[i], n[i])
least_count = get_least_count(n)
least_char = 'null'
for i in range(26):
	if n[i] != 0 and least_char == 'null':
		least_char = alpha[i]
	if n[i] == least_count:
		lcc = alpha[i]
		n[i] -= 1
		break
output = []
i = least_count
if lcc == least_char:
	output.append(lcc)
	least_count -= 1
	while least_count > 0 or i < len(s):
		if least_count > 0:
			output.append(lcc)
			least_count -= 1
		if i < len(s):
			output.append(s[i])
			i += 1
else:
	output.append(lcc)
	for i in range(26):
		addto(output, alpha[i], n[i])
print(''.join(output))


def calculateKMP(s):
	N = len(s)
	kmp = [0 for i in range(N)]
	for i in range(1, N):
		l = kmp[i - 1]
		while l > 0 and s[i] != s[l]:
			l = kmp[l]
		if s[i] == s[l]:
			kmp[i] = l + 1
		else:
			kmp[i] = 0
	return kmp
X = list(map(int, input().strip().split(' ')))
mi = -1
m = 0
fnz = -1
snz = -1
for i in range(len(X)):
	if X[i] > 0:
		if fnz == -1:
			fnz = i
		elif snz == -1:
			snz = i
	if X[i] > 0 and (mi == -1 or X[i] < m):
		mi = i
		m = X[i]
answer = ''
if snz == -1:
	answer = chr(97 + mi) * X[mi]
elif mi == fnz:
	mrem = X[mi]
	srem = X[snz]
	answer = chr(97 + mi)
	mrem -= 1
	while mrem > 0 and srem > 0:
		answer += chr(97 + mi) + chr(97 + snz)
		mrem -= 1
		srem -= 1
	answer += chr(97 + snz) * srem
	for i in range(len(X)):
		count = 0 if i == mi or i == snz else X[i]
		answer += chr(97 + i) * count
else:
	answer = chr(97 + mi)
	for i in range(len(X)):
		count = X[i] if i != mi else X[i] - 1
		answer += chr(97 + i) * count
print(answer)


import sys

def main():
	freq = readints()
	s = ''
	min_index = 0
	index = 0
	headfreq = sys.maxsize
	headcount = 0
	for i in range(0, len(freq)):
		if freq[i] > 0:
			min_index = i
			break
	for i in range(0, len(freq)):
		if (freq[i] > 0) & (freq[i] < headfreq):
			index = i
			headfreq = freq[i]
	headcount = 1
	s = s + chr(ord('a') + index)
	for i in range(0, len(freq)):
		if i != index:
			for j in range(0, freq[i]):
				if (i > index) & (headcount < freq[index]) & (index == min_index):
					s = s + chr(ord('a') + index)
					headcount = headcount + 1
				elif (i > index) & (headcount < freq[index]) & (index != min_index):
					s = s + chr(ord('a') + index) * (freq[index] - headcount)
					headcount = headcount + freq[index] - headcount
				s = s + chr(ord('a') + i)
	if freq[index] > headcount:
		s = s + chr(ord('a') + index) * (freq[index] - headcount)
	print(s)

def readints():
	return [int(x) for x in input().split()]
main()


frq = [int(x) for x in input().strip().split()]
if sum(frq) == 0:
	print('')
	exit()
	pass
border = None
for i in range(26):
	if frq[i] > 0 and (border is None or frq[i] < frq[border]):
		border = i
		pass
	pass
base = ord('a')
s = chr(border + base)
frq[border] -= 1
for i in range(border):
	s += chr(i + base) * frq[i]
	frq[i] = 0
	pass
if len(s) == 1:
	i = border + 1
	while i < 26 and frq[i] == 0:
		i += 1
		pass
	while i < 26 and frq[border] > 0:
		s += chr(border + base) + chr(i + base)
		frq[border] -= 1
		frq[i] -= 1
		while i < 26 and frq[i] == 0:
			i += 1
			pass
		pass
	pass
for i in range(border, 26):
	s += chr(i + base) * frq[i]
	frq[i] = 0
	pass
print(s)


def solve(F):
	if sum(F) == 0:
		return []
	(b, fb) = (0, sum(F) + 1)
	for (i, f) in enumerate(F):
		if f > 0 and f < fb:
			b = i
			fb = f
	nba = sum(F[:b])
	nbc = sum(F[b + 1:])
	if nba > 0:
		s = [b]
		for (i, f) in enumerate(F):
			if i == b:
				s.extend([i] * (F[i] - 1))
			else:
				s.extend([i] * F[i])
		return s
	elif nbc > 0:
		s = [b]
		F[b] -= 1
		for i in range(b + 1, len(F)):
			if F[b] >= F[i]:
				s.extend([b, i] * F[i])
				F[b] -= F[i]
			else:
				s.extend([b, i] * F[b])
				s.extend([i] * (F[i] - F[b]))
				F[b] = max(0, F[b] - F[i])
		return s
	else:
		return [b] * F[b]
F = list(map(int, input().split()))
offset = ord('a')
print(''.join(map(lambda i: chr(offset + i), solve(F))))


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


def i2l(i):
	return chr(i + 97)

def fill_rest(A, d):
	for i in sorted(d):
		A += [i2l(i)] * d[i]

def next_d_i(d):
	p = sorted(d.keys())
	for i in range(1, len(p)):
		if d[p[i]] > 0:
			return p[i]
	return p[0]

def find_min_kmp(counts):
	d = [i for i in range(len(counts)) if counts[i] > 0]
	m = max(counts)
	D = {}
	for i in d:
		c = counts[i]
		D[i] = c
		m = min(m, c)
	ans_arr = []
	I = counts.index(m)
	ans_arr.append(i2l(I))
	D[I] -= 1
	if I > min(D.keys()):
		fill_rest(ans_arr, D)
	else:
		while D[I] > 1:
			D[I] -= 1
			ans_arr.append(i2l(I))
			i = next_d_i(D)
			D[i] -= 1
			ans_arr.append(i2l(i))
		fill_rest(ans_arr, D)
	print(''.join(ans_arr))
counts = [int(i) for i in input().split()]
find_min_kmp(counts)


counts = [int(x) for x in input().split()]
total_count = 0
for i in range(26):
	total_count += counts[i]
smallest_count = total_count
for i in range(26):
	if counts[i] != 0:
		smallest_count = min(smallest_count, counts[i])
first_letter = -1
for i in range(26):
	if counts[i] == smallest_count:
		first_letter = i
		break
outStr = chr(ord('a') + first_letter)
counts[first_letter] -= 1
idx = 0
while len(outStr) < total_count:
	if counts[idx] != 0:
		if idx == first_letter:
			if len(outStr) == 1 or total_count - len(outStr) == counts[idx] or outStr[-1] != chr(ord('a') + first_letter) or (outStr[1] != chr(ord('a') + first_letter)):
				outStr += chr(ord('a') + idx)
				counts[idx] -= 1
				idx = 0
			else:
				idx = (idx + 1) % 26
		else:
			outStr += chr(ord('a') + idx)
			counts[idx] -= 1
			idx = 0
	else:
		idx = (idx + 1) % 26
print(outStr)


import math

def calcKmp(S):
	kmp = [0 for x in S]
	kmp[0] = 0
	for i in range(1, len(S)):
		k = kmp[i - 1]
		while k > 0 and S[i] != S[k]:
			k = kmp[k - 1]
		if S[i] == S[k]:
			kmp[i] = k + 1
		else:
			kmp[i] = 0
	return kmp

def testKmp(length, options):
	tests = [0 for x in range(0, length)]
	for i in range(0, options ** length):
		tests = [0 for x in range(0, length)]
		value = i
		digit = 0
		while value != 0:
			tests[digit] = value % options
			digit += 1
			value = value // options
		print(''.join([chr(x + 97) for x in tests]))
		print(calcKmp(tests))
		print(sum(calcKmp(tests)))
freqs = [int(x) for x in input().split(' ')]
minCharFreq = freqs[0]
minCharIndex = 0
for i in range(0, 26):
	if freqs[i] > 0 and (minCharFreq > freqs[i] or minCharFreq == 0):
		minCharFreq = freqs[i]
		minCharIndex = i
result = []
if freqs[minCharIndex] > 0:
	result.append(minCharIndex)
	freqs[minCharIndex] -= 1
hasPrevChars = False
for i in range(0, minCharIndex):
	for j in range(0, freqs[i]):
		result.append(i)
		hasPrevChars = True
if not hasPrevChars:
	while freqs[minCharIndex] > 0:
		result.append(minCharIndex)
		freqs[minCharIndex] -= 1
		for i in range(minCharIndex + 1, 26):
			if freqs[i] > 0:
				result.append(i)
				freqs[i] -= 1
				break
else:
	while freqs[minCharIndex] > 0:
		result.append(minCharIndex)
		freqs[minCharIndex] -= 1
for i in range(minCharIndex + 1, 26):
	for j in range(0, freqs[i]):
		result.append(i)
	freqs[i] = 0
resultStr = ''.join([chr(x + 97) for x in result])
print(resultStr)


import sys

def main():
	x_range = 26
	x = dict([(key, 0) for key in range(x_range)])
	inp = input().strip().split()
	for i in range(x_range):
		x[i] = int(inp[i])
	N = 0
	for (k, v) in x.items():
		N += v
	idx1 = -1
	idx2 = -1
	mval = sys.maxsize
	midx = 0
	for i in range(x_range):
		if idx1 != -1 and idx2 == -1 and x[i]:
			idx2 = i
		if idx1 == -1 and x[i]:
			idx1 = i
		if x[i] and x[i] < mval:
			mval = x[i]
			midx = i
	S = []
	x[midx] -= 1
	S.append(chr(midx + 97))
	if idx1 == midx and idx2 != -1 and x[idx1]:
		S.append(chr(midx + 97))
		x[midx] -= 1
		m = idx2
		while x[midx] > 0:
			while m < 26 and (not x[m]):
				m += 1
			if m > 25:
				break
			while x[midx] and x[m]:
				x[midx] -= 1
				x[m] -= 1
				S.append(chr(m + 97))
				S.append(chr(midx + 97))
		for i in range(m, x_range):
			while x[i]:
				x[i] -= 1
				S.append(chr(i + 97))
	else:
		for i in range(x_range):
			while x[i]:
				x[i] -= 1
				S.append(chr(i + 97))
	result = ''.join(S)
	print(result)
main()


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


def get_next_char(I):
	L = sum(I)
	first_i = -1
	first_i = I.index(min((i for i in I if i > 0)))
	non_0 = (i for i in I if i > 0)
	first_non_0 = I.index(next(non_0))
	second_non_0 = -1
	try:
		second_non_0 = I.index(next(non_0))
	except:
		second_non_0 = -1
	I[first_i] -= 1
	L -= 1
	yield first_i
	i = -1
	while L > 0:
		i += 1
		if i >= len(I):
			return
		if I[i] == 0:
			continue
		if first_i == first_non_0 and i == first_i and (second_non_0 != -1):
			continue
		while I[i] > 0:
			if I[first_i] > 0 and first_i == first_non_0 and (second_non_0 != -1):
				L -= 1
				I[first_i] -= 1
				yield first_i
			L -= 1
			I[i] -= 1
			yield i

def kmp_str(input_str):
	I = input_str.split()
	I = list(map(int, I))
	N = sum(I)
	Chars = 'abcdefghijklmnopqrstuvwxyz'
	S = ''
	for k in get_next_char(I):
		S += Chars[k]
	return S

def get_kmp(S):
	N = len(S)
	kmp = [-1] * N
	for i in range(1, N):
		l = kmp[i - 1]
		while l > 0 and S[i] != S[l + 1]:
			l = kmp[l]
		if S[i] == S[l + 1]:
			kmp[i] = l + 1
	return [x + 1 for x in kmp]

def kmpfun():
	input_str = input()
	result = kmp_str(input_str)
	print(result)
kmpfun()


a = sorted('qwertyuioplkjhgfdsazxcvbnm')
b = [int(i) for i in input().strip().split(' ')]
c = ''
bmn = 1000000000
b4 = 0
aft = 0
for i in b:
	if i < bmn and i > 0:
		bmn = i
index_min = b.index(bmn)
for i in range(index_min):
	b4 += b[i]
for i in range(index_min + 1, len(b)):
	aft += b[i]
if b4 > 0 or bmn < 3:
	c += a[index_min]
	b[index_min] -= 1
	for i in range(len(b)):
		while b[i] > 0:
			c += a[i]
			b[i] -= 1
else:
	if aft >= bmn:
		amn = a[index_min]
		c += a[index_min]
		c += a[index_min]
		b[index_min] -= 2
		for i in range(len(b)):
			if i != index_min:
				while b[i] > 0:
					c += a[i]
					b[i] -= 1
					if b[index_min] != 0:
						c += a[index_min]
						b[index_min] -= 1
	while b[index_min] > 0:
		c += a[index_min]
		b[index_min] -= 1
print(c)


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


arr = [int(x) for x in input().split()]
freq = []
chars = 'abcdefghijklmnopqrstuvwxyz'
min_freq = ('', 0)
for i in range(26):
	if arr[i] != 0:
		freq.append([chars[i], arr[i]])
		if min_freq[1] == 0 or min_freq[1] > arr[i]:
			min_freq = (chars[i], arr[i])
result = ''
if len(freq) == 1:
	print(freq[0][0] * freq[0][1])
else:
	for i in range(len(freq)):
		if freq[i][0] == min_freq[0]:
			result += freq[i][0]
			freq[i][1] -= 1
			break
	if freq[0][0] == min_freq[0] and freq[0][1] >= 1:
		next_index = 1
		while freq[0][1] > 0:
			result += freq[0][0]
			freq[0][1] -= 1
			while next_index < len(freq):
				if freq[next_index][1] > 0:
					result += freq[next_index][0]
					freq[next_index][1] -= 1
					break
				else:
					next_index += 1
		for i in range(len(freq)):
			result += freq[i][0] * freq[i][1]
	else:
		for i in range(len(freq)):
			result += freq[i][0] * freq[i][1]
print(result)


sorted_seq = sorted(enumerate([int(i) for i in input().split()]), key=lambda x: (x[0], x[1]))
seq = list(filter(lambda x: x[1] != 0, sorted_seq))
occ_dic = {seq[i][0]: seq[i][1] for i in range(len(seq))}
freq_seq = sorted(seq, key=lambda x: (x[1], x[0]))
output = ''
output += chr(97 + freq_seq[0][0])
occ_dic[freq_seq[0][0]] -= 1
if len(seq) == 1:
	output += chr(97 + seq[0][0]) * occ_dic[seq[0][0]]
elif seq[0][0] == freq_seq[0][0]:
	output += (chr(97 + seq[0][0]) + chr(97 + seq[1][0])) * occ_dic[seq[0][0]] + chr(97 + seq[1][0]) * (occ_dic[seq[1][0]] - occ_dic[seq[0][0]])
	for i in range(2, len(seq)):
		output += chr(97 + seq[i][0]) * occ_dic[seq[i][0]]
else:
	for i in range(0, len(seq)):
		output += chr(97 + seq[i][0]) * occ_dic[seq[i][0]]
print(output)


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string

def main():
	s = list(map(int, input().strip().split(' ')))
	output = ''
	char_freqs = [(f, c) for (f, c) in zip(s, string.ascii_lowercase) if f > 0]
	min_freq = 9999999
	min_index = 0
	min_char = ''
	for (i, (freq, char)) in enumerate(char_freqs):
		if freq < min_freq:
			min_freq = freq
			min_index = i
			min_char = char
	if min_freq == 1 or min_char > char_freqs[0][1]:
		output += min_char
		char_freqs[min_index] = (min_freq - 1, min_char)
		other_chars = ''
		for (freq, char) in char_freqs:
			other_chars += char * freq
		output += other_chars
	elif min_char == char_freqs[0][1]:
		output += min_char * 2
		char_freqs.pop(min_index)
		min_freq -= 2
		other_chars = ''
		for i in range(min_freq):
			if len(char_freqs) > 0:
				output += char_freqs[0][1]
				char_freqs[0] = (char_freqs[0][0] - 1, char_freqs[0][1])
				if char_freqs[0][0] == 0:
					char_freqs[0].pop()
			output += min_char
		for (freq, char) in char_freqs:
			output += char * freq
	return output
print(main())


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import sys
letters = 'abcdefghijklmnopqrstuvwxyz'
s = [int(x) for x in input().strip().split(' ')]
total = sum(s)
output = []
l = [i for i in range(len(s)) if s[i] > 0]
m = min((s[i] for i in l))
startLetter = s.index(m)
print(letters[startLetter], end='')
s[startLetter] -= 1
b = 0
for i in l:
	if i < startLetter:
		print(s[i] * letters[i], end='')
		s[i] = 0
		b = 1
	elif (i == startLetter) & (b == 1) & (s[startLetter] > 0):
		print(s[startLetter] * letters[startLetter], end='')
		s[startLetter] = 0
	elif i > startLetter:
		dupes = min([s[startLetter], s[i]])
		print(''.join(dupes * [letters[startLetter], letters[i]]), end='')
		s[startLetter] -= dupes
		s[i] -= dupes
		if s[i] > 0:
			print(s[i] * letters[i], end='')
if s[startLetter] > 0:
	print(s[startLetter] * letters[startLetter], end='')

def dynamicKMP(s):
	total = sum(s)
	output = []
	l = [i for i in range(len(s)) if s[i] > 0]
	m = min((s[i] for i in l))
	startLetter = s.index(m)
	output.append(startLetter)
	s[startLetter] -= 1
	kmp = [-1] * total
	kmp[0] = 0
	i = 0
	while i < total:
		i += 1
		tmp = kmp[i - 1]
		temp = [-1] * len(s)
		b = 0
		if (kmp[i - 1] == 0) & (s[startLetter] == 0):
			for j in l:
				output = output + [j] * s[j]
			return output
		if (i > 3) & (output[i - 2] != output[i - 1]):
			dupes = min(s[output[i - 2]], s[output[i - 1]])
			for k in range(dupes):
				output.append(output[i - 2])
				output.append(output[i - 1])
				kmp[i] = kmp[i - 2]
				kmp[i + 1] = kmp[i - 1]
			i = i + 2 * dupes
			s[output[i - 2]] -= dupes
			s[output[i - 1]] -= dupes
			if sum(s) == 0:
				return output
		for j in l:
			if (i > 3) & (j < startLetter) & (s[j] > 0):
				for k in range(s[j]):
					output.append(j)
					kmp[i + k] = 0
				i = i + s[j]
				s[j] = 0
			if s[j] > 0:
				S = output + [int(j)]
				while (tmp > 0) & (S[i] != S[tmp]):
					tmp = kmp[tmp - 1]
				if S[i] == S[tmp]:
					temp[j] = tmp + 1
				else:
					temp[j] = 0
			if temp[j] == int(j == startLetter):
				b = 1
				output.append(j)
				s[j] -= 1
				kmp[i] = temp[j]
				break
		if b == 0:
			print(kmp)
			sys.stdout.flush()
			m = temp.index(min((k for k in temp if k >= 0)))
			output.append(m)
			kmp[i] = temp[m]
			s[m] -= 1
	return output

def KMPsub(kmp, tmp, S, i):
	temp = kmp[i - 1]
	while (temp > 0) & (S[i] != S[temp]):
		temp = kmp[temp - 1]
	if S[i] == S[temp]:
		return temp + 1
	else:
		return 0

def kmpSearch(S):
	kmp = [-1] * len(S)
	kmp[0] = 0
	for i in range(1, len(S)):
		temp = kmp[i - 1]
		while (temp > 0) & (S[i] != S[temp]):
			temp = kmp[temp - 1]
		if S[i] == S[temp]:
			kmp[i] = temp + 1
		else:
			kmp[i] = 0
	return kmp


frequencies = [int(x) for x in input().strip().split()]
least_frequent = None
(count_before, count_after) = (0, 0)
for i in range(len(frequencies)):
	if frequencies[i] > 0 and (least_frequent is None or frequencies[i] < frequencies[least_frequent]):
		count_before += count_after
		count_after = 0
		if least_frequent is not None:
			count_before += frequencies[least_frequent]
		least_frequent = i
	else:
		count_after += frequencies[i]
least_c = chr(ord('a') + least_frequent)
s = ''
s += least_c
frequencies[least_frequent] -= 1
if count_before > 0:
	for (i, f) in enumerate(frequencies):
		c = chr(ord('a') + i)
		s += f * c
else:
	for (i, f) in enumerate(frequencies):
		c = chr(ord('a') + i)
		if i < least_frequent:
			s += f * c
		elif least_frequent < i:
			j = min(frequencies[least_frequent], frequencies[i])
			s += j * (least_c + c)
			frequencies[least_frequent] -= j
			j = frequencies[i] - j
			s += j * c
	s += frequencies[least_frequent] * least_c
print(s)


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import sys
from functools import reduce

def get_table(s):
	t = [0] * len(s)
	pos = 1
	cnd = 0
	while pos < len(s):
		if s[pos] == s[cnd]:
			t[pos] = cnd + 1
			cnd += 1
			pos += 1
		elif cnd > 0:
			cnd = t[cnd + 1]
			t[pos] = 0
		else:
			t[pos] = 0
			pos += 1
	return t
n = list(map(int, input().split(' ')))
chosen = -1
chosen_count = 99999999999
first = -1
for (i, ni) in enumerate(n):
	if ni < chosen_count and ni != 0:
		chosen_count = ni
		chosen = i
	if ni > 0 and first == -1:
		first = i
print(chr(ord('a') + chosen), end='')
n[chosen] -= 1
if first == chosen:
	if n[chosen] > 0:
		print(chr(ord('a') + chosen), end='')
		n[chosen] -= 1
	for i in range(26):
		if i > chosen:
			for j in range(n[i]):
				print(chr(ord('a') + i), end='')
				n[i] -= 1
				if n[chosen] > 0:
					print(chr(ord('a') + chosen), end='')
					n[chosen] -= 1
for i in range(26):
	for j in range(n[i]):
		print(chr(ord('a') + i), end='')
		n[i] = 0


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
alpha = string.ascii_lowercase
x = [int(tmp) for tmp in input().strip().split(' ')]
min_non_zero_i = -1
min_non_zero_v = 10 ** 7
first = -1
second = -1
for i in range(len(x)):
	if 0 < x[i] < min_non_zero_v:
		min_non_zero_i = i
		min_non_zero_v = x[i]
	if 0 < x[i] and first != -1 and (second == -1):
		second = i
	if 0 < x[i] and first == -1:
		first = i
if first == min_non_zero_i and min_non_zero_v > 2:
	if second == -1:
		print(alpha[min_non_zero_i] * x[min_non_zero_i])
	else:
		print(alpha[min_non_zero_i], end='')
		print((alpha[first] + alpha[second]) * (x[min_non_zero_i] - 1), end='')
		print(alpha[second] * (x[second] - x[first] + 1), end='')
		for i in range(second + 1, len(x)):
			print(alpha[i] * x[i], end='')
		print()
else:
	print(alpha[min_non_zero_i], end='')
	x[min_non_zero_i] -= 1
	for i in range(len(x)):
		print(alpha[i] * x[i], end='')
	print()


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import sys
data = [int(x) for x in input().split(' ')]
s = ''
m_index = sys.maxsize
m = sys.maxsize
first_m = True
for i in range(len(data)):
	if data[i] != 0 and data[i] < m:
		if m != sys.maxsize:
			first_m = False
		m_index = i
		m = data[i]
if data[m_index] == sum(data):
	s += chr(97 + m_index) * data[m_index]
else:
	s += chr(97 + m_index)
	data[m_index] -= 1
	if first_m and data[m_index] > 0:
		s += chr(97 + m_index)
		data[m_index] -= 1
	for i in range(len(data)):
		if i != m_index and data[i] != 0:
			if data[m_index] > 0 and m_index < i:
				if data[m_index] < data[i]:
					s += (chr(97 + i) + chr(97 + m_index)) * data[m_index]
					s += chr(97 + i) * (data[i] - data[m_index])
					data[m_index] = 0
					data[i] -= data[m_index]
				elif data[m_index] > data[i]:
					s += (chr(97 + i) + chr(97 + m_index)) * data[i]
					data[m_index] -= data[i]
					data[i] = 0
				else:
					s += (chr(97 + i) + chr(97 + m_index)) * data[i]
					data[m_index] -= data[i]
					data[i] = 0
			else:
				s += chr(97 + i) * data[i]
				data[i] = 0
		elif not first_m:
			s += chr(97 + i) * data[i]
			data[i] = 0
print(s)


import sys
Inp = [int(m) for m in input().split()]
PosMap = [m for m in range(len(Inp)) if Inp[m] > 0]
Freq = [m for m in Inp if m > 0]
nt = sum(Freq)
MinFreq = min(Freq)
if nt == 1:
	SeqInd = [0]
elif len(PosMap) == 1:
	SeqInd = [0 for m in range(nt)]
else:
	FreqLeft = [m for m in Freq]
	for i in range(len(Freq)):
		if Freq[i] == MinFreq:
			MinFreqInd = i
			break
	SeqInd = [MinFreqInd]
	FreqLeft[MinFreqInd] += -1
	if MinFreqInd > 0 or FreqLeft[MinFreqInd] == 0:
		for i in range(len(FreqLeft)):
			for j in range(FreqLeft[i]):
				SeqInd.append(i)
	else:
		for i in range(FreqLeft[MinFreqInd]):
			SeqInd.append(MinFreqInd)
			SeqInd.append(MinFreqInd + 1)
			FreqLeft[MinFreqInd] += -1
			FreqLeft[MinFreqInd + 1] += -1
		for i in range(len(FreqLeft)):
			for j in range(FreqLeft[i]):
				SeqInd.append(i)
Str = ''
for i in SeqInd:
	Str += chr(PosMap[i] + 97)
print(Str)


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


X = list(map(int, input().split(' ')))
A = [chr(ord('a') + i) for i in range(len(X))]
(starti, minx) = (0, 10 ** 6 + 1)
for (i, x) in enumerate(X):
	if x > 0 and x < minx:
		minx = x
		starti = i
S = ''
S += A[starti]
X[starti] -= 1
raw = [(A[i], x) for (i, x) in enumerate(X) if x > 0]
rawcount = sum((r[1] for r in raw))
if len(raw) == 1:
	S += raw[0][0] * raw[0][1]
	raw[0] = (raw[0], 0)
	rawcount = 0
i = len(S)
kmp = 0
while rawcount > 0:
	for j in range(len(raw)):
		if raw[j][1] < 1:
			continue
		if kmp == 0 or S[kmp] != raw[j][0]:
			S += raw[j][0]
			raw[j] = (raw[j][0], raw[j][1] - 1)
			rawcount -= 1
			if S[kmp] == raw[j][0]:
				kmp += 1
			else:
				kmp = 0
			break
print(S)


S = [int(x) for x in input().split()]
lletres = [x for x in range(26) if S[x]]
millor = lletres[0]
for lletra in lletres:
	if S[lletra] < S[millor]:
		millor = lletra
if len(lletres) == 1:
	sol = [(millor, S[millor])]
elif millor != lletres[0]:
	sol = [(millor, 1)]
	for lletra in lletres:
		if lletra == millor:
			sol.append((lletra, S[lletra] - 1))
		else:
			sol.append((lletra, S[lletra]))
elif S[millor] <= 2:
	sol = [(x, S[x]) for x in lletres]
else:
	altres = sum([S[x] for x in lletres[1:]])
	if S[millor] - 2 <= altres:
		sol = [(millor, 2)]
		resta = S[millor] - 2
		for lletra in lletres[1:]:
			if resta >= S[lletra]:
				sol += [(lletra, 1), (millor, 1)] * S[lletra]
				resta -= S[lletra]
			elif resta > 0:
				sol += [(lletra, 1), (millor, 1)] * resta
				sol.append((lletra, S[lletra] - resta))
				resta = 0
			else:
				sol.append((lletra, S[lletra]))
print(''.join([chr(97 + l) * n for (l, n) in sol]))


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import fileinput
import sys

def KMP(word):
	if len(word) < 1:
		return 0
	kmp = [0 for i in range(len(word))]
	pos = 1
	while pos < len(word):
		ch = word[pos]
		prev = kmp[pos - 1]
		if ch == word[prev]:
			kmp[pos] = kmp[pos - 1] + 1
		else:
			kmp[pos] = 0
		pos += 1
	return kmp

def minKMP(ints):
	arr = [val for val in ints if val != 0]
	(ind, sml) = [tupl for tupl in enumerate(ints) if tupl[1] == min(arr)][0]
	offset = ord('a')
	ans = chr(offset + ind)
	ints[ind] -= 1
	state = 0
	for (idx, cnt) in enumerate(ints):
		if cnt != 0:
			if state == 0:
				if idx < ind:
					ans += chr(offset + idx) * cnt
					ints[idx] -= cnt
					state = 1
				elif idx == ind:
					ans += chr(offset + ind)
					ints[ind] -= 1
					state = 2
				else:
					ans += chr(offset + idx) * cnt
					ints[idx] -= cnt
					state = 1
			elif state == 1:
				ans += chr(offset + idx) * cnt
				ints[idx] -= cnt
			elif state == 2:
				while ints[ind] > 0:
					ans += chr(offset + idx) + chr(offset + ind)
					ints[idx] -= 1
					ints[ind] -= 1
				ans += chr(offset + idx) * ints[idx]
				ints[idx] = 0
				state = 1
	ans += chr(offset + ind) * ints[ind]
	ints[ind] = 0
	return ans
chars = None
for line in fileinput.input():
	chars = line
ints = [int(char) for char in chars.split(' ')]
print(minKMP(ints))


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import sys
import math
ar = [int(x) for x in input().strip().split(' ')]
d = {}
w = {}
c = {}
al = ord('a')
for q in ar:
	d[chr(al)] = q
	al += 1
w = sorted(d.items(), key=lambda v: v[1])
h = d.values
e = list(set(ar))
if 0 in e:
	e.remove(0)
e.sort()
f = []
for u in e:
	if u > 0:
		c[u] = []
for z in w:
	if z[1] > 0:
		c[z[1]].append(z[0])
for l in c:
	c[l].sort()
res = ''
ch = c[e[0]][0]
res += c[e[0]][0]
for xx in w:
	if xx[0] == ch:
		f += [xx[0]] * (xx[1] - 1)
	else:
		f += [xx[0]] * xx[1]
f.sort()
l = 0
if res[0] == f[0]:
	l = f.count(res[0])
suf = len(f) - l
spl = 1 + suf
f1 = f[:l]
f2 = f[l:]
b = []
for (ii, tt) in enumerate(f1):
	if len(b) < ii % spl + 1:
		b.append(0)
	b[ii % spl] += 1
(ii, tt) = (-1, 0)
for (ii, tt) in enumerate(b):
	res += f1[0] * tt
	res += ''.join(f2[ii:ii + 1])
res += ''.join(f2[ii + 1:])
print(res)


string = input()
box = [int(x) for x in string.split(' ')]
found = False
for i in range(len(box)):
	if box[i] != 0:
		if not found:
			min = box[i]
			id = i
			found = True
		elif min > box[i]:
			min = box[i]
			id = i

def pop(i):
	if box[i] > 0:
		print(chr(i + 97), end='')
		box[i] -= 1
flag = False
for i in range(id):
	if box[i] > 0:
		flag = True
if flag:
	pop(id)
	i = 0
	while i < len(box):
		if box[i] > 0:
			pop(i)
		else:
			i += 1
else:
	pop(id)
	pop(id)
	switch = False
	i = 0
	while i < len(box):
		if box[i] == 0 or i == id:
			i += 1
		elif switch == False:
			pop(i)
			switch = True
		else:
			pop(id)
			switch = False
	while box[id] > 0:
		pop(id)


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


def getString(vs):
	return ''.join((''.join([v[0] for _ in range(v[1])]) for v in sorted([[x[1], x[0]] for x in vs])))

def zipzap(us, vs):
	n = min(len(us), len(vs))
	s = ''.join((us[i] + vs[i] for i in range(n)))
	return s + us[n:] + vs[n:]
xs = list(map(int, input().split()))
ys = sorted(list(filter(lambda x: x[0] > 0, [[xs[i], chr(ord('a') + i)] for i in range(26)])))
n = sum(xs)
if n == ys[0][0]:
	print(getString(ys))
else:
	f = min([b for (a, b) in ys])
	if f != ys[0][1]:
		ys[0][0] -= 1
		print(ys[0][1] + getString(ys))
	else:
		ys[0][0] -= 1
		print(ys[0][1] + zipzap(getString(ys[:1]), getString(ys[1:])))


import sys

def findSimpleString(finalString, countArray, charArray):
	for i in range(0, len(charArray)):
		array = charArray[i] * countArray[i]
		finalString += ''.join(array)
	return finalString

def findClusterString(finalString, countArray, charArray):
	startCount = countArray.pop(0)
	startChar = charArray.pop(0)
	finalString += startChar
	startCount -= 1
	if len(countArray) > 0:
		array = [startChar, charArray[0]] * startCount
		countArray[0] -= startCount
		startCount = 0
		finalString += ''.join(array)
		finalString = findSimpleString(finalString, countArray, charArray)
	else:
		array = [startChar] * startCount
		finalString += ''.join(array)
	return finalString
inputString = sys.stdin.read()
inputArray = list(map(int, inputString.split(' ')))
flag = ''
j = 0
finalString = ''
parsedLetter = -1
found = False
countArray = []
charArray = []
for i in range(97, 97 + 26):
	if inputArray[j] > 0:
		countArray.append(inputArray[j])
		charArray.append(chr(i))
	j += 1
minPos = 0
mininmum = countArray[minPos]
mininmumChar = ''
for i in range(len(countArray)):
	if countArray[i] < mininmum:
		mininmum = countArray[i]
		minPos = i
if mininmum == 1:
	finalString += charArray[minPos]
	charArray.pop(minPos)
	countArray.pop(minPos)
	flag = 'SIMPLE'
elif mininmum > 1 and minPos == 0:
	flag = 'CLUSTER'
elif mininmum > 1 and minPos > 0:
	flag = 'SIMPLE'
	countArray[minPos] -= 1
	finalString += charArray[minPos]
if flag == 'SIMPLE':
	finalString = findSimpleString(finalString, countArray, charArray)
else:
	finalString = findClusterString(finalString, countArray, charArray)
print(finalString)


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(''.join(s))


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


def sumKMP(S):
	N = len(S)
	kmp = [0] * N
	for i in range(1, N):
		print(i)
		l = kmp[i - 1]
		while l > 0 and S[i] != S[l]:
			l = kmp[l - 1]
		kmp[i] = (0, l + 1)[S[i] == S[l]]
	return sum(kmp)
toChar = lambda x: chr(ord('a') + x[0])
toChars = lambda x: chr(ord('a') + x[0]) * x[1]
S = filter(lambda x: x[1] > 0, enumerate(map(int, input().strip().split())))
D = list(map(lambda x: [x[0], x[1]], S))
lenD = len(D)
mi = min(range(lenD), key=lambda i: (D[i][1] << 5) + D[i][0])
res = toChar(D[mi])
D[mi][1] -= 1
if D[mi][1] == 0 or len(D) == 1 or mi > 0:
	print(res + ''.join(map(toChars, D)))
else:
	while D[mi][1]:
		res += toChar(D[mi])
		res += toChar(D[mi + 1])
		D[mi][1] -= 1
		D[mi + 1][1] -= 1
	res += ''.join(map(toChars, D))
	print(res)


import string
letters = string.ascii_lowercase
X = list(map(int, input().strip().split()))
dic_val = {}
for i in range(26):
	if X[i] != 0:
		dic_val[letters[i]] = X[i]
min_value = min(dic_val.values())
min_keys = [k for k in dic_val if dic_val[k] == min_value]
f_lett = min(min_keys)
S = f_lett
dic_val[f_lett] -= 1
if dic_val[f_lett] == 0:
	dic_val.pop(f_lett, None)
while sum(dic_val.values()) > 0:
	lett = sorted(dic_val.keys())[0]
	if (len(S) > 1) & (len(dic_val) > 1):
		if S[0] == S[1] == S[-1] == lett == f_lett:
			lett = sorted(dic_val.keys())[1]
	S += lett
	dic_val[lett] -= 1
	if dic_val[lett] == 0:
		dic_val.pop(lett, None)
print(S)


import string
x = list(map(int, input().split()))
y = map(list, filter(lambda p: p[0] != 0, zip(x, string.ascii_lowercase)))
y = list(sorted(y))
c = y[0][1]
y[0][0] -= 1
if y[0][0] == 0:
	del y[0]
y = list(sorted(y, key=lambda p: p[1]))
s = [c]
while y:
	i = 0
	if len(s) >= 2 and len(y) >= 2 and (s[0] == s[1] == s[-1] == c == y[i][1]):
		i = 1
	s.append(y[i][1])
	y[i][0] -= 1
	if y[i][0] == 0:
		del y[i]
print(*s, sep='')


import sys
x = list(map(int, input().strip().split(' ')))
min_count = 10 ** 6 + 1
min_index = None
second_index = None
first = True
for (i, count) in enumerate(x):
	if count > 0:
		if not first and second_index is None:
			second_index = i
		if min_count > count:
			min_count = count
			min_index = i
		first = False
if second_index is None:
	s = chr(ord('a') + min_index) * min_count
	x[min_index] = 0
elif min_index < second_index:
	first_alphabet = chr(ord('a') + min_index)
	second_alphabet = chr(ord('a') + second_index)
	s = first_alphabet + (first_alphabet + second_alphabet) * (min_count - 1)
	remaining_count = x[second_index] - (min_count - 1)
	s += second_alphabet * remaining_count
	x[min_index] = 0
	x[second_index] = 0
else:
	s = chr(ord('a') + min_index)
	x[min_index] -= 1
for (i, count) in enumerate(x):
	if count > 0:
		alphabet = chr(ord('a') + i)
		s += alphabet * count
print(s)


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import sys

def remove(List, index):
	List[index][0] -= 1
	if List[index][0] == 0:
		del List[index]

def KMP(String):
	N = len(String)
	kmp = [0 for i in range(N)]
	for i in range(1, N):
		l = kmp[i - 1]
		while l > 0 and String[i] != String[l]:
			l = kmp[l - 1]
		if String[i] == String[l]:
			kmp[i] = l + 1
		else:
			kmp[i] = 0
	return sum(kmp)
L = input().strip().split(' ')
L = [int(x) for x in L]
Ls = []
for i in range(len(L)):
	if L[i] != 0:
		Ls.append([L[i], chr(97 + i)])
pos = 0
mini = Ls[0][0]
for i in range(len(Ls)):
	if Ls[i][0] < mini:
		mini = Ls[i][0]
		pos = i
String = Ls[pos][1]
remove(Ls, pos)
while len(Ls) != 0:
	i = 0
	if len(String) >= 2 and len(Ls) >= 2 and (String[0] == String[1] == String[-1] == Ls[i][1] == Ls[pos][1]):
		i += 1
	String += Ls[i][1]
	remove(Ls, i)
print(String)


def sortInput(arr):
	temp = []
	for i in range(len(arr)):
		if arr[i] > 0:
			temp.append((arr[i], i))
	minArr = min(temp)
	temp.remove(minArr)
	temp.insert(0, minArr)
	return temp

def putToString(s, c, i, n):
	for j in range(n):
		s[i + j] = c
	return i + n
a = 'abcdefghijklmnopqrstuvwxyz'
x = list(map(int, input().strip().split()))
sumX = sum(x)
res = ['a'] * sum(x)
x = sortInput(x)
if len(x) == 1:
	putToString(res, a[x[0][1]], 0, x[0][0])
elif x[0][1] < x[1][1]:
	res[0] = a[x[0][1]]
	i = 1
	cnt_i = i
	while cnt_i < x[0][0]:
		res[i] = a[x[0][1]]
		i += 1
		cnt_i += 1
		res[i] = a[x[1][1]]
		i += 1
	i = putToString(res, a[x[1][1]], i, x[1][0] - cnt_i + 1)
	for j in range(2, len(x)):
		i = putToString(res, a[x[j][1]], i, x[j][0])
else:
	res[0] = a[x[0][1]]
	i = 1
	not_printed = True
	for j in range(1, len(x)):
		if not_printed and x[0][1] < x[j][1]:
			i = putToString(res, a[x[0][1]], i, x[0][0] - 1)
			not_printed = False
		i = putToString(res, a[x[j][1]], i, x[j][0])
	if not_printed:
		putToString(res, a[x[0][1]], i, x[0][0] - 1)
print(*res, sep='')


import string
xs = list(map(int, input().split(' ')))
ys = map(list, filter(lambda s: s[0] != 0, zip(xs, string.ascii_lowercase)))
ys = sorted(ys)
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


al = 'abcdefghijklmnopqrstuvwxyz'
xs = list(map(int, input().split()))
ys = [[l, al[k]] for (k, l) in enumerate(xs) if l > 0]
ys.sort()
s = [ys[0][1]]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys.sort(key=lambda p: p[1])
while ys:
	i = 0
	if len(s) > 1 and len(ys) > 1 and (s[0] == s[1] == s[-1] == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')


import string
xs = list(map(int, input().split()))
ys = map(list, filter(lambda p: p[0] != 0, zip(xs, string.ascii_lowercase)))
ys = list(sorted(ys))
c = ys[0][1]
ys[0][0] -= 1
if ys[0][0] == 0:
	del ys[0]
ys = list(sorted(ys, key=lambda p: p[1]))
s = [c]
while ys:
	i = 0
	if len(s) >= 2 and len(ys) >= 2 and (s[0] == s[1] == s[-1] == c == ys[i][1]):
		i = 1
	s.append(ys[i][1])
	ys[i][0] -= 1
	if ys[i][0] == 0:
		del ys[i]
print(*s, sep='')