import math
def splitString(string1):
a = 0
n = 0
while a < len(string1) - 1:
if string1[a:a + 2] == ", ":
n = a
a += 1
b = [string1[:n].strip(), string1[n + 1:].strip()]
return b
def findChar(string1, char1):
a = False
b = 0
while b < len(string1):
if string1[b] == char1:
a = True
b += 1
return a
def findFunction(string1):
function = ""
if findChar(string1, ","):
function = "comma"
elif findChar(string1, "$") and not findChar(string1, "*"):
function = "money"
elif findChar(string1, "$") and findChar(string1, "*"):
function = "indent money"
elif findChar(string1, "-"):
function = "negative"
else:
function = "indent"
return function
def concatenateString(list1):
a = 0
b = ""
while a < len(list1):
b += list1[a]
a += 1
b.strip()
return b
def reverseList(list1):
a = len(list1) - 1
b = []
while a > -1:
b.append(list1[a])
a -= 1
return b
def indent(list1):
string1 = list1[0]
number1 = list1[1]
length1 = len(string1)
length2 = len(number1)
numOfAsterisks = length1 - length2
a = ""
b = 0
while b < numOfAsterisks:
a+= "*"
b += 1
b = 0
a += number1
return a
def comma(list1):
string1 = list1[0]
number1 = list1[1]
length1 = len(string1)
length2 = len(number1)
numOfAsterisks = length1 - length2 - 1
a = []
b = 0
while b < numOfAsterisks:
a.append("*")
b += 1
b = 0
while b < length2:
a.append(number1[b])
b += 1
numOfCommas = math.ceil(length2 / 3.0) - 1
b = 0
c = []
d = reverseList(a)
while b < numOfCommas:
c.append(d[3 * b])
c.append(d[3 * b + 1])
c.append(d[3 * b + 2])
c.append(",")
b += 1
while b < len(d):
try:
c.append(d[3 * b])
except:
pass
try:
c.append(d[3 * b + 1])
except:
pass
try:
c.append(d[3 * b + 2])
except:
pass
b += 1
return concatenateString(reverseList(c))
def money(list1):
return "$" + list1[1]
def indentMoney(list1):
a = "$" + list1[1]
string1 = list1[0]
number1 = list1[1]
length1 = len(string1)
length2 = len(number1)
numOfAsterisks = length1 - length2 - 2
b = ""
c = 0
while c < numOfAsterisks:
b += "*"
c += 1
b += a
return b
def negative(list1):
string1 = list1[0]
number1 = list1[1]
length1 = len(string1)
length2 = len(number1)
a = int(number1)
numOfAsterisks = length1 - length2
if a > 0:
numOfAsterisks -= 1
b = []
c = 0
while c < numOfAsterisks:
b.append("*")
c += 1
c = 0
while c < length2:
b.append(number1[c].strip("-"))
c += 1
if a < 0:
b.append("-")
elif a > 0:
b.append("*")
return concatenateString(b)
def main():
a = []
b = []
c = []
d = []
e = 0
while e < 5:
a.append(raw_input())
b.append(splitString(a[e]))
c.append(findFunction(b[e][0]))
if c[e] == "indent":
d.append(indent(b[e]))
elif c[e] == "comma":
d.append(comma(b[e]))
elif c[e] == "money":
d.append(money(b[e]))
elif c[e] == "indent money":
d.append(indentMoney(b[e]))
elif c[e] == "negative":
d.append(negative(b[e]))
print d[e]
e += 1
main()