class Solution(object):
def multiply(self, num1, num2):
"""
:type num1: str
:type num2: str
:rtype: str
"""
resv=[]
p1=((len(num1)+3)/4)*4
p2=((len(num2)+3)/4)*4
for a in xrange(0, len(num1), 4):
for b in xrange(0, len(num2), 4):
if len(num1)-a-4<0:
av=int(num1[0:len(num1)-a])
else:
av=int(num1[len(num1)-a-4:len(num1)-a])
if len(num2)-b-4<0:
bv=int(num2[0:len(num2)-b])
else:
bv=int(num2[len(num2)-b-4:len(num2)-b])
mv=av*bv
#print av,bv
if (a+b)/4>=len(resv):
resv.append(mv)
else:
resv[(a+b)/4]+=mv
addv=0
for i,v in enumerate(resv):
v+=addv
addv=v/10000
resv[i]=v%10000
res=""
if addv>0:
res+=str(addv)
resv.reverse()
for v in resv:
if len(res)>0:
res+="%04d"%(v)
else:
if v==0: continue
res+=str(v)
if len(res)==0:
res="0"
return res