big-p-and-math-15

Big P is fairly good in mathematics.
His teacher has asked him to add two numbers.
Now , Big P has a problem that he sometimes writes a '6' as a '5' and vice versa.
Given two numbers, A and B, calculate the minimum and the maximum sum Big P could possibly get. 

Input:
The first and only line of input contains positive integers A and B . 

Output:
In single line of output, print two space separated integers, minimum and maximum sum Big P could get. 

Constraints:

1 ≤ A,B ≤ 1000000

SAMPLE INPUT
11 25

SAMPLE OUTPUT
36 37

Source: hackerearth | Difficulty: EASY
Tags: Fundamentals


Solutions:
x=input()
maxs=""
mins=""
for i in range(len(x)):
	if(x[i]=='6'):
		mins=mins+'5'
		maxs=maxs+'6'
	elif(x[i]=='5'):
		mins=mins+'5'
		maxs=maxs+'6'
	else:
		mins=mins+x[i]
		maxs=maxs+x[i]
arr1=list(map(int,mins.strip().split(' ')))
arr2=list(map(int,maxs.strip().split(' ')))
sumx=[]
sumx.append(sum(arr1))
sumx.append(sum(arr2))
print(sumx[0], sumx[1])


a,b=input().split()
a,b=int(a),int (b)
value=0
value2=0
minus=0
minus2=0
pos=0
dupa=a
dupb=b
import math
while(dupa>0):
	if(dupa%10==5):
	 value=value+math.pow(10,pos)
	if(dupa%10==6):
	 minus=minus+math.pow(10,pos)
	pos=pos+1
	dupa=dupa/10
pos=0
while(dupb>0):
	if(dupb%10==5):
	 value2=value2+math.pow(10,pos)
	if(dupb%10==6):
	 minus2=minus2+math.pow(10,pos)
	pos=pos+1
	dupb=dupb/10
print(int(a+b-minus-minus2), end=' ')
print(int(a+b+value+value2))


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'

#Note - Biggest sum will come from the number with maximum number of 6s and closer the 6 to higher powers of 10 bigger the number
#  Lowest sum will come number with maximum number of 5s and closer the 5 is to power of 10 lower the number wrt the 6 counterpart.
# import time;

values=input().strip().split(" ");    #"Enter the two values , num1 and num2:"

#start_time=time.time();
num1=str(values[0]);
num2=str(values[1]);

highestNum1=num1.replace('5','6'); # replace 5 with 6
highestNum2=num2.replace('5','6');

lowestNum1=num1.replace('6','5');
lowestNum2=num2.replace('6','5');

print(int(lowestNum1)+int(lowestNum2), int(highestNum1)+int(highestNum2));

# print "Elapsed Time:", time.time()-start_time;


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
A,B=list(map(str,input().split()))
listA=list(A)
listB=list(B)
for i in range(0,len(listA)):
	if listA[i]=="6":
		listA[i]="5"
for i in range(0,len(listB)):
	if listB[i]=="6":
		listB[i]="5"
minsum= int("".join(listA))+int("".join(listB))
listA=list(A)
listB=list(B)
for i in range(0,len(listA)):
	if listA[i]=="5":
		listA[i]="6"
for i in range(0,len(listB)):
	if listB[i]=="5":
		listB[i]="6"
maxsum= int("".join(listA))+int("".join(listB))
print(minsum, maxsum)





def digits(a):
	dig = [];
	while(a > 0):
		dig.append(a%10);
		a=a/10;
	return dig;

def max_min(digits):
	max_a =0;
	min_a=0;
	i = 0;
	while(i < len(digits) ):
		if(digits[i] == 5):
			max_a = max_a + 6*(10**i);
			min_a = min_a + 5*(10**i);
			
		elif(digits[i] == 6):
			min_a = min_a + 5*(10**i);
			max_a = max_a + 6*(10**i);

		else:
			max_a = max_a + digits[i]*(10**i);
			min_a = min_a + digits[i]*(10**i);
		i = i+1;
	return (min_a,max_a);
	

def msum(a,b):
	(mxa,mna) = max_min(digits(a));
	(mxb,mnb) = max_min(digits(b));
	return (mxa+mxb,mna+mnb);

	
(a,b) = list(map(int,input().split()));
(mx,mn) = msum(a,b);
print(mx,mn);


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
input = input()
arr = input.split()
a = arr[0]
b = arr[1]
if '5' in a:
	amax = a.replace('5','6')
else:
	amax = a
if '5' in b:
	bmax = b.replace('5','6')
else:
	bmax = b
smax = int(amax)+int(bmax)
if '6' in a:
	amin = a.replace('6','5')
else:
	amin = a
if '6' in b:
	bmin = b.replace('6','5')
else:
	bmin = b
smin = int(amin)+int(bmin)
print(smin,smax)


a,b=list(map(str,input().split()))
x=int(a.replace('5','6'))
y=int(b.replace('5','6'))

u=int(a.replace('6','5'))
v=int(b.replace('6','5'))

print(u+v,x+y)


mylist=[n for n in input().split(" ")]
ma=0
mi=0
for n in mylist:
	if n.find("5")+n.find("6")==-2:
		ma+=int(n)
		mi+=int(n)
	else:
		if (n.find("5")!=-1) and (n.find("6")!=-1):
			if int(n)>0:
				ma+=int(n.replace("5","6"))
				mi+=int(n.replace("6","5"))
			else:
				ma+=int(n.replace("6","5"))
				mi+=int(n.replace("5","6"))
		else:
			if n.find("5")!=-1:
				if int(n)>0:
					ma+=int(n.replace("5","6"))
					mi+=int(n)
				else:
					ma+=int(n)
					mi+=int(n.replace("5","6"))
			if n.find("6")!=-1:
				if int(n)>0:
					mi+=int(n.replace("6","5"))
					ma+=int(n)
				else:
					mi+=int(n)
					ma+=int(n.replace("6","5")) 
print(str(mi)+" "+str(ma))


a, b = input().split()

newA = ''
newB = ''
for num in a:
	if num == '6':
		newA += '5'
	else:
		newA += num

for num in b:
	if num == '6':
		newB += '5'
	else:
		newB += num

minSum = int(newA) + int(newB)

newA = ''
newB = ''

for num in a:
	if num == '5':
		newA += '6'
	else:
		newA += num
		
for num in b:
	if num == '5':
		newB += '6'
	else:
		newB += num

maxSum = int(newA) + int(newB)

print(minSum, maxSum)


test = list(map(str,input().split()))
a = test[0]
b = test[1]
maxSum = 0
minSum = 0
if '5' in a:
	c = a.replace('5','6')
else:
	c = a
if '5' in b:
	d = b.replace('5','6')
else:
	d = b
if '6' in a:
	e = a.replace('6','5')
else:
	e = a
if '6' in b:
	f = b.replace('6','5')
else:
	f = b
maxSum = int(c) + int(d)
minSum = int(e) + int(f)
print(minSum,maxSum)


dat=input().split()
a=list(dat[0])
b=list(dat[1])
x=list(dat[0])
y=list(dat[1])
n=len(a)
m=len(b)
p=len(x)
q=len(y)

for i in range(0,n):
    
	if (a[i]=='5'):
		a[i]='6'

for j in range(0,m):
	
	if (b[j]=='5'):
		b[j]='6'

maxa = ''.join(a)
maxb = ''.join(b)
ma=int(maxa)+int(maxb)

for k in range(0,p):
	
	if (x[k]=='6'):
		x[k]='5'
for l in range(0,q):
	
	if (y[l]=='6'):
		y[l]='5'
 
minx = ''.join(x)
miny = ''.join(y)
mi=int(minx)+int(miny)
print(mi,ma)


ab = input().split(' ')
a_values = []
b_values = []
sums = []
a_values.append(int(ab[0]))
b_values.append(int(ab[1]))
a_values.append(int(ab[0].replace('5', '6')))
a_values.append(int(ab[0].replace('6', '5')))
b_values.append(int(ab[1].replace('5', '6')))
b_values.append(int(ab[1].replace('6', '5')))

i = 0
while i < len(a_values):
	j = 0
	while j < len(b_values):
		sums.append(a_values[i] + b_values[j])
		j += 1
	i += 1

print(str(min(sums)) + " " + str(max(sums)))



a,b=list(map(int,input().split()))
c=int(a)
d=int(b)
print(int(str(a).replace('6','5'))+int(str(b).replace('6','5')),int(str(c).replace('5','6'))+int(str(d).replace('5','6')))


a,b = list(map(int,input().split()))
aa = list(map(int,str(a)))
bb = list(map(int,str(b)))

mina = aa
minb = bb
maxa = aa
maxb = bb

for i in range(0,len(mina)):
	if mina[i] == 6:
		mina[i] = 5
for i in range(0,len(minb)):
	if minb[i] == 6:
		minb[i] = 5

c = int(''.join(map(str,mina))) + int(''.join(map(str,minb)))
print(str(c), end=' ')

for i in range(0,len(maxa)):
	if maxa[i] == 5:
		maxa[i] = 6
for i in range(0,len(maxb)):
	if maxb[i] == 5:
		maxb[i] = 6
d = int(''.join(map(str,maxa))) + int(''.join(map(str,maxb)))

print(str(d))
		


import re
A,B=input().split()
p=re.compile('5')
q=re.compile('6')
mA=p.sub('6',A)
mB=p.sub('6',B)
mxA=q.sub('5',A)
mxB=q.sub('5',B)
summx=int(mxA)+int(mxB)
sumn=int(mA)+int(mB)
print(summx,sumn);



mylist=[n for n in input().split(" ")]
ma=0
mi=0
for n in mylist:
	if n.find("5")+n.find("6")==-2:
		ma+=int(n)
		mi+=int(n)
	else:
		if (n.find("5")!=-1) and (n.find("6")!=-1):
			if int(n)>0:
				ma+=int(n.replace("5","6"))
				mi+=int(n.replace("6","5"))
			else:
				ma+=int(n.replace("6","5"))
				mi+=int(n.replace("5","6"))
		else:
			if n.find("5")!=-1:
				if int(n)>0:
					ma+=int(n.replace("5","6"))
					mi+=int(n)
				else:
					ma+=int(n)
					mi+=int(n.replace("5","6"))
			if n.find("6")!=-1:
				if int(n)>0:
					mi+=int(n.replace("6","5"))
					ma+=int(n)
				else:
					mi+=int(n)
					ma+=int(n.replace("6","5")) 
print(str(mi)+" "+str(ma))


S = input()

a, b = sum(map(int, S.replace('6','5').split())), sum(map(int, S.replace('5','6').split()))

A , B = (a, b) if a<b else (b, a)

print(A, B)




from sys import stdin
def max_sum(a, b):
	if '5' in a:
		a = a.replace('5', '6')
	if '5' in b:
		b = b.replace('5', '6')
	# print("max:")
	# print(a, b)
	return int(a) + int(b)

def min_sum(a, b):
	if '6' in a:
		a=a.replace('6', '5')
	if '6' in b:
		b=b.replace('6', '5')
	# print("min:")
	# print(a, b)
	return int(a) + int(b)

def main():
	lines = stdin.readline()
	lines = lines.split(' ')
	lines[1] = lines[1].replace('\n', '')
	a = lines[0]
	b = lines[1]
	print(min_sum(a, b), end=' ')
	print(max_sum(a, b))
		
if __name__ == '__main__':
	main()


Num=input()
FirstNum=Num.replace('6','5')
FirstNum=[int(i) for i in FirstNum.split()]
SecondNum=Num.replace('5','6')
SecondNum=[int(j) for j in SecondNum.split()]
FirstOp=int(FirstNum[0])+int(FirstNum[1])
SecondOp=int(SecondNum[0])+int(SecondNum[1])
print(FirstOp, end=' ')
print(SecondOp)


a,b = list(map(int,input().split()))
aa = list(map(int,str(a)))
bb = list(map(int,str(b)))

mina = aa
minb = bb
maxa = aa
maxb = bb

for i in range(0,len(mina)):
	if mina[i] == 6:
		mina[i] = 5
for i in range(0,len(minb)):
	if minb[i] == 6:
		minb[i] = 5

c = int(''.join(map(str,mina))) + int(''.join(map(str,minb)))
print(str(c), end=' ')

for i in range(0,len(maxa)):
	if maxa[i] == 5:
		maxa[i] = 6
for i in range(0,len(maxb)):
	if maxb[i] == 5:
		maxb[i] = 6
d = int(''.join(map(str,maxa))) + int(''.join(map(str,maxb)))

print(str(d))
		


a, b = tuple(input().split())

minimum = str(int(a.replace('6', '5')) + int(b.replace('6', '5')))
maximum = str(int(a.replace('5', '6')) + int(b.replace('5', '6')))

print((minimum + ' ' + maximum))



a, b = tuple(input().split())

minimum = str(int(a.replace('6', '5')) + int(b.replace('6', '5')))
maximum = str(int(a.replace('5', '6')) + int(b.replace('5', '6')))

print((minimum + ' ' + maximum))



import math
a,b=list(map(str,input().split()))
a1=''
a2=''
b1=''
b2=''
for ch in a:
	if ch=='6':
		a1=a1+'5'
	else:
		a1=a1+ch
	if ch=='5':
		a2=a2+'6'
	else:
		a2=a2+ch
for ch in b:
	if ch=='6':
		b1=b1+'5'
	else:
		b1=b1+ch
	if ch=='5':
		b2=b2+'6'
	else:
		b2=b2+ch
print(str(int(a1)+int(b1))+" "+str(int(a2)+int(b2)))


def max6(n):
	num=0
	flag=0
	if(n%10==0):
		n=n+1
		flag=1
	while n>0:
		if(n%10==5):
			num=num*10+6
		else:
			num=num*10+n%10
		n=n/10
	
	num=int(str(num)[::-1])
	if (flag==1):
		return num-1
	return num
	
def min5(n):
	num=0
	flag=0
	if(n%10==0):
		n=n+1
		flag=1
	while n>0:
		if n%10==6:
			num=num*10+5
		else:
			num=num*10+n%10
		n=n/10
	
	num=int(str(num)[::-1])
	if(flag==1):
		return num-1
	return num
	

n,m=(int(x) for x in input().split())
print(min5(n)+min5(m),max6(n)+max6(m))



s = input()
l = s.split()
A = int(l[0])
B = int(l[1])
A1 = 0
B1 = 0
A2 = 0
B2 = 0
t = 1
while A!=0 or B!=0 :
	rA = A%10;
	rB = B%10;
	if rA == 5:
		rA = 6;
	if rB == 5:
		rB = 6;
	A1 = A1 + rA*t;
	B1 = B1 + rB*t;
	rA = A%10;
	rB = B%10;
	if rA == 6:
		rA = 5;
	if rB == 6:
		rB = 5;
	A2 = A2 + rA*t;
	B2 = B2 + rB*t;

	A=A//10;
	B=B//10;
	t=t*10;

s = str(A2+B2)+" "+str(A1+B1)
print(s)


x=input().split()
a=x[0]
b=x[1]
p=int(a.replace('5','6'))
q=int(a.replace('6','5'))
s=int(b.replace('5','6'))
t=int(b.replace('6','5'))
print(min(p+s,p+t,q+s,q+t) ,max(p+s,p+t,q+s,q+t))



'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import sys
line = sys.stdin.readline()

temp1 = (line.replace('6','5')).split()
temp2 = (line.replace('5','6')).split()

print((str(int(temp1[0])+int(temp1[1]))+' '+str(int(temp2[0])+int(temp2[1]))))


import re
def max_sum(a, b):
	# for max sum convert each 5 to 6
	a=re.sub('5', '6',a)
	b=re.sub('5', '6', b)
	return int(a)+int(b)

def min_sum(a, b):
	# 6==>5
	a=re.sub('6', '5',a)
	b=re.sub('6', '5', b)
	return int(a)+int(b)

a,b = input().split()
print(min_sum(a, b), max_sum(a, b))