import java. util. Scanner;
public class LinkListTest {
Node head, tail;
public LinkListTest ( ) {
head= new Node ( ) ; tail= head;
Create ( ) ;
Create ( ) ;
Print ( ) ;
}
void Create ( ) {
Scanner sc= new Scanner ( System. in ) ;
int n= sc. nextInt ( ) ;
for ( int i = 0 ; i < n; i++ ) {
int cof= sc. nextInt ( ) ;
int exp= sc. nextInt ( ) ;
Node p= new Node ( ) ;
p. cof = cof;
p. exp = exp;
SortedLint ( p) ;
}
}
void SortedLint ( Node p) {
Node temp = head;
Node tempNext = temp. next;
while ( tempNext != null && tempNext. exp < p. exp) {
temp = tempNext;
tempNext = tempNext. next;
}
if ( tempNext == null ) {
Insert ( temp, p) ;
} else if ( tempNext. exp > p. exp) {
Insert ( temp, p) ;
} else {
tempNext. cof += p. cof;
}
}
void Insert ( Node e, Node p) {
p. next = e. next;
e. next = p;
}
void Print ( ) {
Node p= head. next;
while ( p!= null ) {
System. out. print ( p. cof+ "x^" + p. exp+ "+" ) ;
p= p. next;
}
}
public static void main ( String[ ] args) {
LinkListTest list= new LinkListTest ( ) ;
}
class Node {
int cof;
int exp;
Node next;
}
}