#include<bits/stdc++.h>
using namespace std;
struct node
{
int zhishu;
int xishu;
struct node *next;
};
void Attach(int c,int e,node *pRear)
{
node *p;
p=(node *)malloc(sizeof(node));
p->zhishu=e;
p->xishu=c;
p->next=NULL;
pRear->next=p;
}
node* Read()
{
int N;
cin>>N;
node *P,*Rear;
P=(node *)malloc(sizeof(node));
P->next=NULL;
Rear=P;
for(int i=0;i<N;i++)
{
int a,b;
cin>>a>>b;
if(a==0&&b==0)
break;
Attach(a,b,Rear);
}
node *T;
T=P;
P=P->next;
free(T);
return P;
}
int compare(int a,int b)
{
if(a>b)
return 1;
else if(a==b)
return 0;
else
return -1;
}
node* Add(node *a,node *b)
{
node *t1,*t2,*p,*q,*Rear;
p=(node *)malloc(sizeof(node));
p->next=NULL;
Rear=p;
t1=a;
t2=b;
int sum=0;
while(t1&&t2)
{
switch(compare(t1->zhishu,t2->zhishu))
{
case 1:
Attach(t1->xishu,t2->zhishu,p);
t1=t1->next;
break;
case 0:
sum=t1->xishu+t2->xishu;
if(sum)
Attach(sum,t1->zhishu,p);
t1=t1->next;
t2=t2->next;
break;
case -1:
Attach(t2->xishu,t2->zhishu,p);
t2=t2->next;
break;
}
}
for(;t1;t1=t1->next)
Attach(t1->xishu,t1->zhishu,Rear);
for(;t2;t2=t2->next)
Attach(t2->xishu,t2->zhishu,Rear);
Rear->next=NULL;
node *front1;
front1 =Rear;
Rear=Rear->next;
free(front1);
return front1;
}
int main()
{
return 0;
}