//#include<stdio.h>
//int deck[10000005]={}, top1=5000000, top2=5000001;
//void c1(int x)
//{
// top1++;
// deck[top1]=x;
// return;
//}
//void c2(int x)
//{
// top2--;
// deck[top2]=x;
//}
//void c3()
//{
// if (top1<top2)
// {
// printf("-1\n");
// }
// else
// {
// top1--;
// printf("%d\n", deck[top1+1]);
// }
//}
//void c4()
//{
// if (top2>top1)
// {
// printf("-1\n");
// }
// else
// {
// top2++;
// printf("%d\n", deck[top2-1]);
// }
//}
//void c5()
//{
// printf("%d\n", top1-top2+1);
//}
//void c6()
//{
// if (top1<top2)
// {
// printf("1\n");
// }
// else
// {
// printf("0\n");
// }
//}
//void c7()
//{
// if (top1<top2)
// {
// printf("-1\n");
// }
// else
// {
// printf("%d\n", deck[top1]);
// }
//}
//void c8()
//{
// if (top1<top2)
// {
// printf("-1\n");
// }
// else
// {
// printf("%d\n", deck[top2]);
// }
//}
//int main()
//{
// int n, k;
// scanf("%d", &n);
// for(int i=1;i<=n;i++)
// {
// scanf("%d", &k);
// if (k==1)
// {
// scanf("%d", &k);
// c1(k);
// }
// else if (k==2)
// {
// scanf("%d", &k);
// c2(k);
// }
// else if (k==3)
// {
// c3();
// }
// else if (k==4)
// {
// c4();
// }
// else if (k==5)
// {
// c5();
// }
// else if (k==6)
// {
// c6();
// }
// else if (k==7)
// {
// c7();
// }
// else if (k==8)
// {
// c8();
// }
// }
// return 0;
//}
//#include<stdio.h>
//int x=1, arr[1005]={},cnt=0, n,temp,c=0;
//void f(int a)
//{
// if (c>=n)
// {
// return;
// }
// if (arr[x]==0)
// {
// if (x==0)
// {
// x = n;
// f(a);
// if (c>=n)
// {
// return;
// }
// }
// else if(x==n+1)
// {
// x=1;
// f(a);
// if (c>=n)
// {
// return;
// }
// }
// else
// {
// if (a>0)
// {
// x++;
// }
// else
// {
// x--;
// }
// f(a);
// if (c>=n)
// {
// return;
// }
// }
// }
// if (cnt==a)
// {
// c++;
// printf("%d ", x);
// cnt = 0;
// temp = arr[x];
// arr[x]=0;
// if (temp>0)
// {
// x++;
// cnt++;
// }
// else
// {
// x--;
// cnt--;
// }
// f(temp);
// return;
// }
// else
// {
// if (a>0)
// {
// cnt++;
// x++;
// }
// else
// {
// cnt--;
// x--;
// }
// f(a);
// }
//}
//int main()
//{
// int i;
// scanf("%d", &n);
// for(i=1;i<=n;i++)
// {
// scanf("%d", &arr[i]);
// }
// f(0);
// return 0;
//}