wGcd a []=[]
wGcd [] a=[]
wGcd la@(a:as) lb@(b:bs)
  |elem a lb =a:wGcd as lb
  |elem b la =b:wGcd as bs
  |otherwise =wGcd as bs
 
sort []=[]
sort (x:xs)=
  let s=[a|a<-xs,a<=x]
       l=[a|a<-xs,a>x]
  in sort s++[x]++l
 
output n a=do
  if(n==1) then putStr$sort a
              else do 
                b<-getLine
                output (n-1) (wGcd a b)
 
main=do
  n<-readLn
  a<-getLine
  output n a