class Polynome:
    def __init__(self,*args):
        self.coef = [i for i in args]

    def affiche(self):
        r = str(self.coef[0]) + ' '
        for i in range( 1 , len(self.coef) ):
            if i != 1:
                end = '^' + str(i) + ' '
            else:
                end = ' '

            if self.coef[i] < 0:
                r = r + str(self.coef[i]) + 'X' + end
            elif self.coef[i] > 0:
                r = r + '+ ' + str(self.coef[i]) + 'X' + end

        print(r)

    def standardise(self , Q):
        n , m = len(self.coef) , len(Q.coef)
        if n < m:
            self.coef = self.coef + [0] * (m - n)
        else:
            Q.coef = Q.coef + [0] * (n - m)

        return self.coef , Q.coef

    def __add__(self , Q):
        P , Q = self.standardise(Q)
        return Polynome( *[ P[i] + Q[i] for i in range( len(P) ) ] )

    def __sub__(self , Q):
        P , Q = self.standardise(Q)
        return Polynome( *[ P[i] - Q[i] for i in range( len(self.coef) ) ] )

    def prodmonome(self, k):
        L = [0] * k + self.coef
        return Polynome(*L)

    def __mul__(self , Q):
        n = max( len(self.coef) , len(Q.coef) )
        if n == 1:
            return Polynome( *[ self.coef[0] * Q.coef[0] ] )

        P , Q = self.standardise(Q)
        k = n // 2
        P0 , P1 = Polynome( *P[0:k] ) , Polynome( *P[k:n] )
        Q0 , Q1 = Polynome( *Q[0:k] ) , Polynome( *Q[k:n] )

        return P0*Q0 + ((P0+P1)*(Q0+Q1)-P0*Q0-P1*Q1).prodmonome(k) + (P1*Q1).prodmonome(2*k)

P , Q = Polynome(1,2,3) , Polynome(4,5,6)
(P*Q).affiche()