#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
typedef struct ring
{
char a;
struct ring *flink;
struct ring *slink;
} ring;
ring* sring = NULL;
ring* hring = NULL; /* the first node */
ring* ering = NULL; /* the end node */
void ring_pushback( ring* r, int n )
{
static int i = 0;
if ( i == 0 )
{
sring = r;
++i;
hring = r;
}
else
{
sring->slink = r;
r->flink = sring;
sring = r;
/* the end node */
if ( i == n - 1 )
{
sring->slink = hring;
hring->flink = sring;
ering = sring;
}
++i;
}
}
int main( void )
{
/*ofstream fout( "beads.out" );
ifstream fin( "beads.in" );*/
int n, i;
char temp;
cin >> n;
for ( i = 0; i < n; ++i )
{
cin >> temp;
//ring* bread = (ring*)malloc( sizeof( ring ) );
ring* bread = new ring;
bread->a = temp;
bread->flink = NULL;
bread->slink = NULL;
ring_pushback( bread, n );
}
ring* p = NULL;
ring* q = NULL;
p = hring;
do
{
cout << p->a << endl;
q = p;
p = p->slink;
delete q;
}while( p != hring );
}