#include <cstdlib>
#include <iostream>
#include <sstream>
using namespace std;
class List{
    public:
        class Node{
            public:
                int data;
                Node *next;
        };
        List();
        List(const List&);
        ~List();
       // List& operator=(const List&);   
        bool empty() const;
        void insert(int data,int pos);
        void erase(int pos);
       
        void traverse();
  //      Node* linearSearch(int data);
        void display();
        Node* first;
        Node* temp;
    private:
        
        int mySize;
};
List::~List(){
    Node* temp;
    Node* record;
    record=first;
    while(record->next!=NULL){
        temp=record;
        record=record->next;
        delete temp;
    }
     delete record;
}
List::List():mySize(0),first(NULL){
}
List::List(const List& list){
    Node *temp;
    temp=list.first;
    int i=0;
    while(temp->next!=NULL){
        this->insert(temp->data,i);
        ++i;
        temp=temp->next;
    }
    this->insert(temp->data,i);
}
void List::traverse(){
    Node * ptr;
    ptr=first;
    while(1){
        if(ptr->next==NULL){
            cout<<ptr->data;
            break;
        }    
        else
            cout<<ptr->data<<" ";
        ptr=ptr->next;
    }

}
/*Node* List::linearSearch(int data){
    Node* temp;
    temp=first;
    while(1){
        if(temp->data==data)
            return temp;
        else 
            temp=temp->next;
    }
}*/
bool List::empty()const{
    if(mySize==0)
        return true;
    else 
        return false;
}
void List::insert(int data,int pos){
    Node* ptr;
    Node* temp;
    Node* newnode;
    newnode=new Node;
    if(first==NULL){
        first=newnode;
        newnode->next=NULL;
        newnode->data=data;
        ++mySize;
    }
    else{
        if(pos==0){

            newnode->next=first;
            newnode->data=data;
            first=newnode;
            ++mySize;
        }
        else if(pos>0&&pos<mySize){
            ptr=first;
            for(int i=0;i<pos-1;)
                ptr=ptr->next;
            temp=ptr->next;
            ptr->next=newnode;
            newnode->next=temp;
            newnode->data=data;
            ++mySize;        
        }
        else if(pos==mySize){
            ptr=first;         
            while(ptr->next!=NULL)
                ptr=ptr->next;
            ptr->next=newnode;
            newnode->next=NULL;

            newnode->data=data;
            ++mySize;    
        }
    }
}
void List::erase(int pos){
    Node* preptr;
    Node* deptr;
    preptr=first;
    for(int i=0;i<pos-2;i++)
        preptr=preptr->next;
    deptr=preptr->next;
    preptr->next=deptr->next;
    --mySize;
    delete deptr;
}    
int main(int argc, char *argv[])
{
    
    char  temp[10000];
    while(cin.getline(temp,10000)){
        List constant,x,answer;
        int number,tempans=0,countofcons=0,countofx=0,countofans=0,X,tempx=1;
        stringstream num(temp);
        while(num>>number){
            constant.insert(number,countofcons);
            ++countofcons;
        }
        cin.getline(temp,10000);
        stringstream num1(temp);
        while(num1>>X){
            x.insert(X,countofx);
            ++countofx;
        }
        x.temp=x.first;
        for(int j=0;j<countofx;++j){
            tempx=1,tempans=0;
            for(int i=0;i<countofcons-1;++i)
                tempx=x.temp->data*tempx;
            constant.temp=constant.first;
            while(constant.temp->next!=NULL){
                tempans=tempans+constant.temp->data*tempx;
                constant.temp=constant.temp->next;
                tempx=tempx/x.temp->data;
            }
            tempans=tempans+constant.temp->data;
            constant.temp=constant.temp->next;
            x.temp=x.temp->next;
            answer.insert(tempans,countofans);
            ++countofans;
        }
        answer.traverse();
        cout<<endl;
    }
    return EXIT_SUCCESS;
}
