Given a string containing uppercase alphabets and integer digits (from 0 to 9), the task is to print the alphabets in the lexicographical order followed by the sum of digits.
Example 1:
Input: S = "AC2BEW3"
Output: "ABCEW5"
Explanation: 2 + 3 = 5 and we print all
alphabets in the lexicographical order. 
Example 2:
Input: S = "ACCBA10D2EW30"
Output: "AABCCDEW6"
Explanation: 0+1+2+3 = 6 and we print all
alphabets in the lexicographical order. 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function arrangeString() which takes the string S as inputs and returns the modified string.
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(26)
Constraints:
1 ≤ |S| ≤ 10^{5}
S contains only upper case alphabets and digits.

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3

class Solution:
    def arrangeString(self, s):
        # code here

Solutions:
class Solution:

	def arrangeString(self, s):
		p1 = []
		p2 = []
		z = '1234567890'
		for i in s:
			if i in z:
				p1.append(int(i))
			else:
				p2.append(i)
		z2 = ''
		p2.sort()
		for i in p2:
			z2 += i
		zz = sum(p1)
		if zz > 0:
			x = z2 + str(zz)
		else:
			x = z2
		return x


class Solution:

	def arrangeString(self, s):
		str1 = ''
		total = 0
		for i in range(len(s)):
			if s[i].isalpha() == False:
				total = total + int(s[i])
			else:
				str1 = str1 + s[i]
		str2 = ''.join(sorted(str1))
		if total > 0:
			str2 = str2 + str(total)
		return str2


class Solution:

	def arrangeString(self, s):
		summ = 0
		arr = []
		for c in s:
			if c.isdigit():
				summ = summ + int(c)
			else:
				arr.append(c)
		arr.sort()
		s = ''
		for e in arr:
			s = s + e
		if summ > 0:
			s = s + str(summ)
		return s


class Solution:

	def arrangeString(self, s):
		k = ''
		summ = 0
		for i in s:
			if i.isalpha():
				k += i
			else:
				summ += int(i)
		k = sorted(k)
		k = ''.join(k)
		if summ > 0:
			return k + str(summ)
		return k


class Solution:

	def arrangeString(self, s):
		l = []
		s1 = ''
		s2 = 0
		for i in s:
			if i.isdigit():
				s2 += int(i)
			else:
				l.append(i)
		l.sort()
		s1 = ''.join(l)
		if s2 == 0:
			return s1
		return s1 + str(s2)


class Solution:

	def arrangeString(self, s):
		c = 0
		st = ''
		for i in s:
			try:
				x = int(i)
				c += x
			except:
				st += i
		if c == 0:
			return st
		st = ''.join(sorted(st)) + str(c)
		return st


class Solution:

	def arrangeString(self, s):
		num = 0
		st = ''
		for i in s:
			if i.isnumeric():
				num += int(i)
			else:
				st += i
		if not num:
			return ''.join(sorted(st))
		return ''.join(sorted(st)) + str(num)


class Solution:

	def arrangeString(self, s):
		c = 0
		s1 = ''
		d = '0123456789'
		for i in s:
			if i in d:
				c += int(i)
		for i in sorted(s):
			if i not in d:
				s1 += i
		if c > 0:
			return s1 + str(c)
		return s1


class Solution:

	def arrangeString(self, s):
		su = 0
		res = ''
		alpha = [0] * 26
		for i in s:
			if i.isdigit():
				su += int(i)
			else:
				alpha[ord(i) - ord('A')] += 1
		for i in range(26):
			if alpha[i]:
				res += chr(i + 65) * alpha[i]
		if su == 0:
			return res
		return res + str(su)


class Solution:

	def arrangeString(self, s):
		k = []
		add = 0
		for i in s:
			if i.isalpha():
				k.append(i)
			elif i.isdigit():
				add += int(i)
		l = sorted(k)
		if add > 0:
			m = ''.join(l) + str(add)
		else:
			m = ''.join(l)
		return m


class Solution:

	def arrangeString(self, s):
		strings = ''
		values = []
		for each in s:
			if each.isnumeric():
				values.append(int(each))
			else:
				strings += each
		string = ''.join(sorted(strings))
		if len(values) != 0:
			return '{}{}'.format(string, sum(values))
		else:
			return string


class Solution:

	def arrangeString(self, s):
		sum = 0
		alpha = []
		for i in s:
			if i.isalpha():
				alpha.append(i)
			else:
				sum += int(i)
		alpha.sort()
		word = ''.join(alpha)
		if sum == 0:
			return word
		else:
			return word + str(sum)


class Solution:

	def arrangeString(self, s):
		su = 0
		l = []
		if len(s) == 1:
			return s
		for i in s:
			if i.isdigit():
				su += int(i)
			else:
				l.append(i)
		l = sorted(l)
		return ''.join(l) + str(su)


class Solution:

	def arrangeString(self, s):
		ch = ''
		somme = 0
		for i in s:
			if i.isalpha():
				ch += i
			else:
				somme += int(i)
		s = str(somme)
		sorted_word = ''.join(sorted(ch))
		if s == '0':
			return sorted_word
		return sorted_word + s


class Solution:

	def arrangeString(self, s):
		r = ''
		l = 0
		for i in s:
			if i.isalpha() == True:
				r = r + i
			else:
				l = l + int(i)
		if l == 0:
			return ''.join(sorted(r))
		elif len(s) == 1:
			return s[0]
		st = ''.join(sorted(r)) + str(l)
		return st


class Solution:

	def arrangeString(self, s):
		l = []
		a = []
		for i in s:
			if i.isdigit():
				l.append(int(i))
			else:
				a.append(i)
		a = sorted(a)
		if len(l) != 0:
			a.append(sum(l))
		x = ''
		for i in a:
			x += str(i)
		return x


class Solution:

	def arrangeString(self, s):
		ans = ''
		c = -1
		s = list(s)
		s.sort()
		for i in s:
			if i.isdigit():
				if c == -1:
					c = 0
				c += int(i)
			else:
				ans += i
		if c != -1:
			ans += str(c)
		return ans


class Solution:

	def arrangeString(self, s):
		a = sorted(s)
		s1 = ''
		sum = 0
		for i in a:
			if i.isalpha():
				s1 += i
			else:
				sum += int(i)
		if sum != 0:
			s1 += str(sum)
		return s1


class Solution:

	def arrangeString(self, s):
		a = ''
		b = ''
		for i in range(len(s)):
			if s[i].isalpha():
				a += s[i]
			else:
				b += s[i]
		ls = sorted(a)
		ans = ''.join(ls)
		if len(b) != 0:
			sum = 0
			for j in range(len(b)):
				sum += int(b[j])
			return ans + str(sum)
		else:
			return ans


class Solution:

	def arrangeString(self, s):
		l = []
		c = 0
		for i in s:
			if i.isdigit():
				c += int(i)
			elif i.isalpha():
				l.append(i)
		l.sort()
		if c != 0:
			l.append(str(c))
			return ''.join(l)
		else:
			return ''.join(l)


class Solution:

	def arrangeString(self, s):
		a = '0123456789'
		b = ''
		c = ''
		sum = 0
		for i in range(len(s)):
			if s[i] in a:
				b += s[i]
			else:
				c += s[i]
		d = ''.join(sorted(c))
		for j in range(len(b)):
			sum += int(b[j])
		if sum == 0:
			return d
		d += str(sum)
		return d


class Solution:

	def arrangeString(self, s):
		num = 0
		s2 = ''
		for i in s:
			if i.isalpha():
				s2 += i
			else:
				num += int(i)
		s2 = ''.join(sorted(s2))
		if num > 0:
			return s2 + str(num)
		else:
			return s2


class Solution:

	def arrangeString(self, s):
		a = ''
		b = 0
		d = ''
		for i in s:
			if i.isalpha():
				a += i
			else:
				b += int(i)
		c = sorted(a)
		for i in c:
			d += i
		if b > 0:
			d += str(b)
		return d


class Solution:

	def arrangeString(self, s):
		z = 0
		f = ''
		for i in s:
			if i.isnumeric():
				z += int(i)
			else:
				f += i
		f = sorted(f)
		f = ''.join(f)
		if z:
			f = f + str(z)
			return f
		else:
			return f


class Solution:

	def arrangeString(self, s):
		res = ''
		num = 0
		for i in range(len(s)):
			if ord(s[i]) < 65:
				a = ord(s[i]) - 48
				num += a
			else:
				res += s[i]
		res = ''.join(sorted(res))
		if num == 0:
			return res
		return res + str(num)


class Solution:

	def arrangeString(self, s):
		char = []
		num = 0
		st = ''
		for ch in s:
			if ch.isdigit():
				num += int(ch)
			else:
				char.append(ch)
		char.sort()
		st = ''.join(char)
		if num == 0:
			return st
		return st + str(num)


class Solution:

	def arrangeString(self, s):
		if len(s) == 1:
			return s
		x = ''
		y = 0
		for i in s:
			if i.isalpha():
				x += i
			elif i.isdigit():
				y += int(i)
		x = sorted(x)
		x = ''.join(x)
		x = x + str(y)
		return x


class Solution:

	def arrangeString(self, s):
		x = 0
		y = ''
		for i in s:
			if i.isalpha():
				y = y + i
			else:
				x += int(i)
		z = [str(i) for i in y]
		z.sort()
		if len(s) > 1:
			z.append(str(x))
		z = ''.join(z)
		return z


class Solution:

	def arrangeString(self, s):
		r = []
		a = 0
		for i in s:
			if i >= 'A' and i <= 'Z':
				r.append(i)
			elif i >= '0' and i <= '9':
				a += int(i)
		r.sort()
		r = ''.join(r)
		if a == 0:
			return r
		else:
			return r + str(a)


class Solution:

	def arrangeString(self, s):
		a = []
		c = 0
		for i in range(len(s)):
			if s[i].isnumeric():
				c += int(s[i])
			else:
				a.append(s[i])
		a.sort()
		if c == 0:
			c = ''
		return ''.join(a) + str(c)


class Solution:

	def arrangeString(self, s):
		l = []
		sum1 = 0
		for i in s:
			if i.isdigit() == True:
				sum1 += int(i)
		for i in s:
			if i.isalpha() == True:
				l.append(i)
		l.sort()
		str1 = ''.join(l)
		if sum1 == 0:
			return str1
		else:
			return str1 + str(sum1)


class Solution:

	def arrangeString(self, s):
		out = []
		num = 0
		for i in range(len(s)):
			if s[i].isalpha():
				out.append(s[i])
			else:
				num += int(s[i])
		out.sort()
		if num == 0:
			num = ''
		return ''.join(out) + str(num)


class Solution:

	def arrangeString(self, s):
		lst = []
		num = 0
		for x in s:
			if x.isalpha():
				lst += x
			else:
				num += int(x)
		lst.sort()
		if num == 0:
			return ''.join(lst)
		else:
			return ''.join(lst) + str(num)


class Solution:

	def arrangeString(self, s):
		(al, di) = ('', 0)
		for x in s:
			if x.isdigit():
				di += int(x)
			else:
				al += x
		if not di:
			di = ''
		return ''.join(sorted(al)) + str(di)


class Solution:

	def arrangeString(self, s):
		lst = []
		ls = []
		arr = list(s)
		l = len(arr)
		for i in range(l):
			if 65 <= ord(arr[i]) <= 122:
				lst.append(arr[i])
			else:
				ls.append(int(arr[i]))
		S = sum(ls)
		lst.sort()
		a = ''
		for i in lst:
			a = a + i
		if len(ls) == 0:
			return a
		else:
			return a + str(S)


class Solution:

	def arrangeString(self, s):
		if len(s) == 1:
			return s
		alpha = []
		digit = []
		for i in range(len(s)):
			if s[i].isalpha():
				alpha.append(s[i])
			else:
				digit.append(int(s[i]))
		alpha.sort()
		new_list = ''.join(alpha)
		return new_list + str(sum(digit))


class Solution:

	def arrangeString(self, s):
		s1 = ''
		s2 = ''
		for i in s:
			if i.isdigit():
				s2 += i
			else:
				s1 += i
		a = 0
		li = list(s1)
		li.sort()
		c = ''
		for i in li:
			c += i
		for i in s2:
			a += int(i)
		if len(s2) == 0:
			b = c
		else:
			b = c + str(a)
		return b


class Solution:

	def arrangeString(self, s):
		a = s
		b = ''
		c = 0
		for i in a:
			if i.isdigit():
				c += int(i)
			else:
				b += i
		x = sorted(b)
		m = ''.join(x)
		if c == 0:
			return m
		else:
			z = m + str(c)
			return z


class Solution:

	def arrangeString(self, s):
		count = []
		characters = sorted([*s], reverse=True)
		while characters[-1].isdigit():
			count.append(int(characters.pop()))
		characters.reverse()
		if count:
			characters.append(str(sum(count)))
		return ''.join(characters)


class Solution:

	def arrangeString(self, s):
		count = []
		characters = sorted([*s])
		while characters[0].isdigit():
			count.append(int(characters.pop(0)))
		if count:
			characters.append(str(sum(count)))
		return ''.join(characters)


class Solution:

	def arrangeString(self, s):
		s = sorted(s)
		sum = 0
		string = ''.join(s)
		answer_string = ''
		for i in string:
			if i.isalpha():
				answer_string += i
			else:
				sum += int(i)
		if sum != 0:
			answer_string += str(sum)
		return answer_string


class Solution:

	def arrangeString(self, s):
		s1 = ''
		a = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		s = list(s)
		l = []
		sum1 = 0
		for i in s:
			if i not in a:
				s1 = s1 + i
			else:
				l.append(i)
				sum1 = sum1 + int(i)
		s1 = list(s1)
		s1.sort()
		s1 = ''.join(s1)
		if sum1 > 0:
			s1 = s1 + str(sum1)
		return s1


class Solution:

	def arrangeString(self, s):
		x = list(s)
		x.sort()
		c = ''
		y = 0
		for i in x:
			if i.isdigit():
				y += int(i)
			else:
				c += i
		if y > 0:
			return c + str(y)
		else:
			return c


class Solution:

	def arrangeString(self, s):
		k = 0
		r = ''.join(sorted(s))
		for i in r:
			if i.isalpha():
				m = r.index(i)
				break
			k += int(i)
		if k > 0:
			return r[m:] + str(k)
		return r[m:]


class Solution:

	def arrangeString(self, s):
		num = list()
		alpha = list()
		for ele in s:
			if ele.isnumeric():
				num.append(int(ele))
			else:
				alpha.append(ele)
		res = str()
		alpha.sort()
		for i in alpha:
			res += i
		if num:
			res += str(sum(num))
		return res


class Solution:

	def arrangeString(self, s):
		a = sorted(s)
		arr = []
		new = ''
		for i in a:
			if i.isdigit():
				inn = int(i)
				arr.append(inn)
			elif i.isalpha():
				new += i
		if len(arr) == 0:
			return new
		else:
			return new + str(sum(arr))


class Solution:

	def arrangeString(self, s):
		sum = 0
		number = False
		new_s = ''
		for i in s:
			if i.isdigit():
				number = True
				sum += int(i)
			else:
				new_s += i
		list_s = sorted(new_s)
		sort_s = ''.join(list_s)
		if number:
			return sort_s + str(sum)
		return sort_s


class Solution:

	def arrangeString(self, s):
		st = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		sum = 0
		new = ''
		for i in s:
			if i in st:
				new += i
			else:
				sum += int(i)
		new = list(new)
		new.sort()
		if sum == 0:
			return ''.join(new)
		else:
			return ''.join(new) + str(sum)


class Solution:

	def arrangeString(self, s):
		num = []
		arr = []
		for i in s:
			if i.isdigit():
				num.append(int(i))
			else:
				arr.append(i)
		x = sum(num)
		x = [x]
		arr.sort()
		if x != [0]:
			arr.extend(x)
		return ''.join(map(str, arr))


class Solution:

	def arrangeString(self, s):
		digits = []
		alpha = []
		for i in s:
			if i.isdigit():
				digits.append(int(i))
			else:
				alpha.append(i)
		alpha.sort()
		if not digits:
			return ''.join(alpha)
		alpha.append(str(sum(digits)))
		return ''.join(alpha)


class Solution:

	def arrangeString(self, s):
		s = tuple(s)
		int_list = []
		characters = ''
		for char in s:
			if char.isdigit():
				int_list.append(int(char))
			else:
				characters += char
		sum_of_int_list = sum(int_list)
		characters = sorted(characters)
		if sum_of_int_list > 0:
			sorted_list = characters + [str(sum_of_int_list)]
		elif sum_of_int_list == 0:
			sorted_list = characters
		output = ''
		for i in sorted_list:
			output += i
		return output


class Solution:

	def arrangeString(self, s):
		alp = []
		dig = 0
		for x in s:
			if x.isalpha():
				alp.append(x)
			elif x.isdigit():
				dig += int(x)
		if dig == 0:
			dig = ''
		return ''.join(sorted(alp) + [str(dig)])


class Solution:

	def arrangeString(self, s):
		v = 0
		j = ''
		for i in s:
			if ord(i) in range(48, 59):
				v += int(i)
			elif ord(i) in range(65, 91):
				j += i
		v = str(v)
		j = sorted(j)
		j = ''.join(j)
		if v == '0':
			return j
		elif v != '0':
			return j + v


class Solution:

	def arrangeString(self, s):
		if len(s) == 1:
			return str(s)
		l = []
		s1 = 0
		for i in s:
			if i.isupper():
				l.append(i)
			else:
				s1 = s1 + int(i)
		l.sort()
		return ''.join(l) + str(s1)


class Solution:

	def arrangeString(self, s):
		total = 0
		a = ''
		for i in s:
			if i.isdigit():
				total = total + int(i)
			else:
				a = a + i
		if total != 0:
			y = ''.join(sorted(a)) + str(total)
			return y
		return ''.join(sorted(a))


class Solution:

	def arrangeString(self, s):
		a = ''
		b = ''
		for i in s:
			if i.isdigit():
				a += i
			if i.isalpha():
				b += i
		b = ''.join(sorted(b))
		c = 0
		for i in a:
			c += int(i)
		if c != 0:
			return b + str(c)
		return b


class Solution:

	def arrangeString(self, s):
		lis = []
		sum = 0
		for i in s:
			if i.isalpha():
				lis.append(i)
			else:
				sum += int(i)
		lis2 = sorted(lis, key=lambda x: ord(x))
		string = ''.join(lis2)
		if sum == 0:
			return string
		else:
			return string + str(sum)


class Solution:

	def arrangeString(self, s):
		s1 = []
		s2 = []
		s3 = ''
		s4 = ''
		c = 0
		for i in s:
			if i >= '0' and i <= '9':
				s1.append(i)
			else:
				s2.append(i)
		for i in s1:
			c = c + int(i)
		s2.sort()
		if c > 0:
			s2.append(str(c))
		for i in s2:
			s3 = s3 + i
		return s3


class Solution:

	def arrangeString(self, s):
		if len(s) == 1:
			return s
		l = []
		for i in range(len(s)):
			l.append(s[i])
		l.sort()
		a = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		x = []
		y = []
		for i in l:
			if i in a:
				x.append(i)
			else:
				y.append(i)
		sum = 0
		for i in x:
			sum += int(i)
		res = ''.join(y) + str(sum)
		return res


class Solution:

	def arrangeString(self, s):
		s = list(s)
		s.sort()
		st = []
		num = 0
		for e in s:
			try:
				if int(e):
					num += int(e)
			except:
				st.append(e)
		st = ''.join(st)
		if len(st) == 1:
			return st
		else:
			return st + str(num)


class Solution:

	def arrangeString(self, s):
		l = list()
		st = ''
		sum = 0
		for i in s:
			if i.isdigit():
				sum += int(i)
			else:
				l.append(i)
		l.sort()
		st = ''.join(l)
		if sum == 0:
			return st
		return st + str(sum)


class Solution:

	def arrangeString(self, s):
		x = ''
		for i in s:
			if i.isalpha():
				x += i
		x = sorted(x)
		y = 0
		for i in s:
			if i.isdigit():
				y += int(i)
		if y != 0:
			x += str(y)
		z = ''
		for i in x:
			z += i
		return z


class Solution:

	def arrangeString(self, s):
		c = 0
		a = ''
		l = []
		for i in range(len(s)):
			if s[i].isdigit():
				c += int(s[i])
			else:
				a += s[i]
		l = list(a)
		l.sort()
		a = ''.join(l)
		if c != 0:
			a = a + str(c)
		return a


class Solution:

	def arrangeString(self, s):
		if len(s) == 1:
			return s
		num = []
		ans = []
		for i in s:
			if i in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
				num.append(int(i))
			else:
				ans += i
		ans.sort()
		ans.append(str(sum(num)))
		return ''.join(ans)


class Solution:

	def arrangeString(self, s):
		if len(s) == 1:
			return s
		a = sorted(s)
		c = 0
		sum = 0
		for i in range(len(a)):
			if a[i].isalpha():
				c = i
				break
			elif a[i].isdigit():
				sum += int(a[i])
		b = a[c:]
		b.append(str(sum))
		return ''.join(b)


class Solution:

	def arrangeString(self, s):
		sum = 0
		str1 = ''
		for i in s:
			if i.isdigit():
				sum = sum + int(i)
		k = str(sum)
		for i in s:
			if i.isalpha():
				str1 = str1 + i
		p = str1
		str2 = ''.join(sorted(str1))
		if sum == 0:
			return str2
		else:
			return str2 + k


class Solution:

	def arrangeString(self, s):
		arr = list(s)
		alp = []
		num = []
		for i in arr:
			if 64 < ord(i) < 91 or 96 < ord(i) < 123:
				alp.append(i)
			else:
				num.append(int(i))
		if num == []:
			return ''.join(sorted(alp))
		else:
			return ''.join(sorted(alp)) + str(sum(num))


class Solution:

	def arrangeString(self, s):
		ans = ''
		sum_1 = 0
		l = []
		for letter in s:
			if letter.isdigit():
				sum_1 = sum_1 + int(letter)
			else:
				l.append(letter)
		l.sort()
		if sum_1 == 0:
			return ''.join(l)
		return ''.join(l) + str(sum_1)


class Solution:

	def arrangeString(self, s):
		s = sorted(s)
		n = len(s)
		t = 0
		for i in range(n):
			if s[i].isdigit():
				t += int(s[i])
			else:
				break
		if t == 0:
			t = ''
		ans = ''.join(s[i:]) + str(t)
		return ans


class Solution:

	def arrangeString(self, s):
		b = []
		s1 = 0
		d = ''
		for i in s:
			if i.isnumeric():
				s1 += int(i)
			else:
				b.append(i)
		b.sort()
		for i in b:
			d += i
		if s1 == 0:
			return d
		else:
			d = d + str(s1)
			return d


class Solution:

	def arrangeString(self, s):
		v = ''
		x = []
		y = []
		k = 0
		a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
		p = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		for i in range(0, len(s)):
			if s[i] in a:
				x.append(s[i])
			else:
				y.append(s[i])
		for i in range(0, len(y)):
			k = k + int(y[i])
		x.sort()
		for i in range(0, len(x)):
			v = v + x[i]
		if len(y) == 0:
			return v
		else:
			return v + str(k)


class Solution:

	def arrangeString(self, s):
		S = []
		k = 0
		X = ''
		for i in s:
			if i.isalpha() == 1:
				S.append(i)
			else:
				k += int(i)
		S = sorted(S)
		X = ''.join(S)
		if k != 0:
			X += str(k)
			return X
		return X


class Solution:

	def arrangeString(self, s):
		l1 = []
		l2 = []
		for i in s:
			if i.isnumeric():
				l1.append(int(i))
			else:
				l2.append(i)
		l2.sort()
		if sum(l1) == 0:
			pass
		else:
			l2.append(str(sum(l1)))
		return ''.join(l2)


class Solution:

	def arrangeString(self, s):
		res1 = []
		res2 = []
		su = -1
		c = ''
		for i in s:
			if i.isalpha():
				res1.append(i)
			if i.isnumeric():
				res2.append(int(i))
		res1.sort()
		if len(res2) > 0:
			su = sum(res2)
		for i in res1:
			c += i
		if su >= 0:
			c += str(su)
		return c


class Solution:

	def arrangeString(self, s):
		s1 = sorted(s)
		s2 = ''
		s3 = ''
		l = []
		for i in s1:
			if i.isalpha():
				s2 = s2 + i
			elif i.isdigit():
				l.append(int(i))
		m = sum(l)
		if m > 0:
			s3 = s3 + str(m)
		return s2 + s3


class Solution:

	def arrangeString(self, s):
		alphabets = {}
		sum = 0
		result = ''
		digitsAdded = False
		for char in s:
			if char.isnumeric():
				sum += int(char)
				digitsAdded = True
			elif char.isupper():
				if char not in alphabets:
					alphabets[char] = 1
				else:
					alphabets[char] += 1
		upperAlpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
		for letter in upperAlpha:
			if letter in alphabets:
				for i in range(alphabets[letter]):
					result += letter
		if digitsAdded:
			result += str(sum)
		return result


class Solution:

	def arrangeString(self, s):
		s = sorted(s)
		d = ''
		count = 0
		for i in s:
			if i.isalpha():
				d = d + i
			else:
				i = int(i)
				count = count + i
		count = str(count)
		if count != '0':
			d = d + count
			return d
		else:
			return d


class Solution:

	def arrangeString(self, s):
		l = []
		su = 0
		k = 0
		for i in s:
			if i.isdigit():
				su = su + int(i)
				k += 1
			else:
				l.append(i)
		l.sort()
		s1 = ''.join(l)
		if k != 0:
			s1 = s1 + str(su)
		else:
			pass
		return s1


class Solution:

	def arrangeString(self, s):
		l = [x for x in s]
		l.sort()
		s1 = ''
		c = 0
		p = 0
		for x in l:
			if x.isdigit():
				c += int(x)
				p = 1
			else:
				s1 += x
		if p == 0:
			return s1
		s1 += str(c)
		return s1


class Solution:

	def arrangeString(self, s):
		t = 0
		a = ''
		b = ''
		for i in range(len(s)):
			if s[i].isdigit():
				t += int(s[i])
			else:
				a += s[i]
		a = sorted(a)
		if len(a) == 1:
			return s
		for i in a:
			b += i
		b += str(t)
		if len(b) == 1:
			return b
		return b


class Solution:

	def arrangeString(self, s):
		ss = 0
		r = ''
		for i in s:
			if i.isdigit():
				ss += int(i)
			else:
				r += i
		r = ''.join(sorted(r)) + (str(ss) if ss else '')
		return r


class Solution:

	def arrangeString(self, s):
		d = []
		b = []
		for i in s:
			try:
				a = int(i)
				d.append(a)
			except:
				b.append(i)
		b.sort()
		if sum(d) == 0:
			q = ''.join(b)
		else:
			q = ''.join(b) + str(sum(d))
		return q