#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Node
{
int data;
struct Node *next;
struct Node *pior;
}Link;
void Init(Link **L)
{
*L=(Link *)malloc(sizeof(Link));
if(*L==NULL)exit(1);
(*L)->data=0;
(*L)->next=*L;
(*L)->pior=*L;
}
void Insert(Link *L,int x)
{
Link *t=(Link *)malloc(sizeof(Link));
if(t==NULL)exit(1);
t->next=L->next;
L->next=t;
t->pior=L;
if(t->next!=L)t->next->pior=t;
t->data=x;
}
void add(Link *L1,Link *L2,Link *L3)
{
Link *p1=L1->next,*p2=L2->next;
int x=0,f=0;
while(p1!=L1)
{
x=p1->data+p2->data+f;
if(x>=10000)
{
x=x-10000;
f=1;
}
else f=0;
Insert(L3,x);
p1=p1->next;
p2=p2->next;
}
while(p1!=L1)
{
x=p1->data+f;
if(x>=10000)
{
x-=10000;
f=0;
}
Insert(L3,x);
p1=p1->next;
}
if(f)
Insert(L3,f);
}