#include <stdio.h>
#include <stdlib.h>

#define A	5000
#define N_	(A * 3)
#define INF	0x3f3f3f3f3f3f3f3fLL

long long min(long long a, long long b) { return a < b ? a : b; }

int oo[1 + (N_ - 1) * 2], oj[1 + (N_ - 1) * 2];

int link(int o, int j) {
	static int _ = 1;

	oo[_] = o, oj[_] = j;
	return _++;
}

int count(int n, int p) {
	return n < p ? 0 : n / p + count(n / p, p);
}

int ae[N_], pp[N_], dd[N_], sz[N_], ii[A + 1], n;

void init() {
	static char composite[A + 1];
	static int primes[A + 1];
	int n_, a, b, cnt, i, j;

	for (a = 2; a <= A / a; a++) {
		if (composite[a])
			continue;
		for (b = a * a; b <= A; b += a)
			composite[b] = 1;
	}
	cnt = 0;
	for (a = 2; a <= A; a++)
		if (!composite[a])
			primes[cnt++] = a;
	n_ = 0;
	pp[n_] = -1, dd[n_] = 0;
	ii[1] = n_++;
	for (a = 2; a <= A; a++) {
		int h, d, d_;

		d = 0;
		for (h = 0; h < cnt; h++)
			d += count(a, primes[h]);
		d_ = 0;
		for (h = cnt - 1; h >= 0; h--) {
			d_ += count(a - 1, primes[h]);
			if (a % primes[h] == 0)
				break;
		}
		i = ii[a - 1], j = -1;
		while (1)
			if (dd[i] > d_)
				j = i, i = pp[i];
			else if (dd[i] == d_) {
				pp[n_] = i, dd[n_] = d, n_++;
				ii[a] = n_ - 1;
				break;
			} else {
				int k = n_++;

				pp[k] = i, dd[k] = d_;
				if (j != -1)
					pp[j] = k;
				pp[n_] = k, dd[n_] = d, n_++;
				ii[a] = n_ - 1;
				break;
			}
	}
	for (j = 1; j < n_; j++) {
		i = pp[j];
		ae[i] = link(ae[i], j), ae[j] = link(ae[j], i);
	}
}

long long dfs1(int p, int i) {
	int o;
	long long x;

	x = (long long) sz[i] * dd[i];
	for (o = ae[i]; o; o = oo[o]) {
		int j = oj[o];

		if (j != p) {
			x += dfs1(i, j);
			sz[i] += sz[j];
		}
	}
	return x;
}

long long ans;

void dfs2(int p, int i, long long x) {
	int o;

	ans = min(ans, x);
	for (o = ae[i]; o; o = oo[o]) {
		int j = oj[o];

		if (j != p) {
			int w = abs(dd[i] - dd[j]);

			dfs2(i, j, x - (long long) sz[j] * w + (long long) (n - sz[j]) * w);
		}
	}
}

int main() {
	int i;

	init();
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		int a;

		scanf("%d", &a);
		sz[ii[a > 0 ? a : 1]]++;
	}
	ans = INF;
	dfs2(-1, 0, dfs1(-1, 0));
	printf("%lld\n", ans);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(void){
  int fib[45],stock[45];
  int s,k,i,n,sum=0,num=0;
  scanf("%d %d",&s,&k);
  for(i=0;fib[i-1]<=s;i++){
    if(i<=1) fib[i]=1;
    else if(i<k&&k!=2) fib[i]=sum;
    else{
      sum-=fib[i-1-k];
      fib[i]=sum;
    }
    //printf("%d %d\n",i,fib[i]);
    sum+=fib[i];
  }
  n=i-2;
  if(fib[i-2]==s) n--;
  //printf("n:%d %d\n",n,fib[n]);
  for(i=n;i>=0;i--){
    if(fib[i]<=s){
      stock[num++]=fib[i];
      s-=fib[i];
      if(s==0) break;
    }
  }
  printf("%d\n",num);
  for(i=num-1;i>=0;i--){
    printf("%d",stock[i]);
    putchar((i>0)?' ':'\n');
  }
  //printf("%d %d\n",n,fib[(i-1)%3]);
  return 0;
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LL long long
#define uLL unsigned long long
long ms[2000000];
void print(LL *a,long size) {long i;for (i=1;i<size;i++) {printf("%lld ",a[i]);}printf("%lld\n",a[i]);}
void mergesort(LL*ds,long size)
{
	long i,j,k,s,b,e;
	for (k=1;k<=size;k=k<<1)
	{
		for (i=1;i+k<=size;i+=k<<1)
		{
			s=i;b=i+k;e=b+k-1;
			if (e>size) {e=size;}
			for (j=1;(s<i+k)&&(b<=e);j++)
			{
				if (ds[s]<=ds[b])
				{
					ms[j]=ds[s++];
				}
				else
				{
					ms[j]=ds[b++];
				}
			}
			for (b=i+k-1;b>=s;b--)
			{
				ds[e--]=ds[b];
			}
			for (b=1;b<j;b++)
			{
				ds[i+b-1]=ms[b];
			}
		}
	}
}
long gray(long a)
{
	return ((a<<1)^a)>>1;
}
inline uLL bsf64(uLL a)
{
	__asm__("bsfq %0,%0":"+r"(a));
	return a;
}
inline uLL bsr64(uLL a)
{
	__asm__("bsrq %0,%0":"+r"(a));
	return a;
}
inline LL max(LL a,LL b) {if (b>a) {a=b;}return a;}
inline LL min(LL a,LL b) {if (a>b) {a=b;}return a;}
LL ans1[1000000],ans2[1000000];
long num[1000],num2[1000];
int main()
{
//	freopen("in.in","r",stdin);
	long i,j,k,a,b,c,l,p,q,baka,r,m,n,mid;
	scanf("%ld %ld\n",&n,&m);
//	printf("%ld %ld\n",n,m);
	for (i=1;i<=n;i++)
	{
		scanf("%ld",&num[i]);
	}
	if (n>10) {q=n>>1;} {q=n;}
	*ans1=(LL)1<<q;ans1[1]=0;
	for (i=1;i<=q;i++) {num2[i]=num[i];}
	for (i=1;i<=*ans1;i++)
	{
		a=gray(i);b=gray(i-1);
		k=a^b;
		if (a&k) {ans1[i]=ans1[i-1]+num2[bsr64(k)];}
		if (b&k) {ans1[i]=ans1[i-1]+m-num2[bsr64(k)];}
		ans1[i]=ans1[i]%m;
	}
//	print(ans1,*ans1);
	//////////////////
	q=n-q;
	for (i=1;i<=q;i++) {num2[i]=num[n-i+1];}
	*ans2=(LL)1<<q;ans2[1]=0;
	for (i=1;i<=*ans2;i++)
	{
		a=gray(i);b=gray(i-1);
		k=a^b;
		if (a&k) {ans2[i]=ans2[i-1]+num2[bsr64(k)];}
			if (b&k) {ans2[i]=ans2[i-1]+m-num2[bsr64(k)];}
		ans2[i]=ans2[i]%m;
	}
	mergesort(ans1,*ans1);
	baka=0;
	for (i=1;i<=*ans2;i++)
	{
		l=1;r=*ans1;a=m-1-ans2[i];
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (ans1[mid]<a)
			{
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		if (l<=*ans1) {b=(ans2[i]+ans1[l])%m;baka=max(b,baka);}
		if (r>0) {b=(ans2[i]+ans1[r])%m;baka=max(b,baka);}
		l=1;r=*ans1;a=2*m-1-ans2[i];
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (ans1[mid]<a)
			{
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		if (l<=*ans1) {b=(ans2[i]+ans1[l])%m;baka=max(b,baka);}
		if (r>0) {b=(ans2[i]+ans1[r])%m;baka=max(b,baka);}
	}
	printf("%lld\n",baka);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define SET(a,b) memset(a,b,sizeof(a))
#define scan(n) scanf("%d",&n)
#define print(n) printf("%d\n",n)
#define scanl(n) scanf("%lld",&n)
#define printl(n) printf("%lld\n",n)

//stacks
/*void push(int n,int ar[],int i)
  {
  ar[i]=n;
  i++;
  }
  void pop(int ar[],int i)
  {
  if(i>0)
  {
  ar[i-1]=0;
  i--;
  }
  }*/

//queues
/*void qpush(int ar[],int val,int head,int tail,int range)
  {
  if(head==tail)
  {
  ar[head]=val;
  if(tail+1==range)
  tail=0;
  else
  tail++;
  }
  else
  {
  ar[tail]=val;
  if(tail+1==range)
  tail=0;
  else
  tail++;
  }
  if(tail==head)
  {
  if(head+1==range)
  head=0;
  else
  head++;
  }
  }

  void qpop(int head,int tail,int range)
  {
  if(head+1==range)
  head=0;
  else
  head++;
  }*/

//pow
/*int fun(int a,int b,int m)
  {
  if(b==0)
  return 1;
  int d,x;
  d=fun(a,b/2,m);
  x=(d*d)%m;
  if(b%2==0)
  return x;
  else
  return (x*a%m)%m;
  }
  */
//bst
/*typedef struct tree
  {
  int val;
  struct tree *l;
  struct tree *r;
  }node;
//node *head;
node *insert(int x,node *root)
{
if(root==NULL)
{
root=(node *)malloc(sizeof(node));
root->val=x;
}
else
{
if(x<=root->val)
{
if(root->l==NULL)
{
root->l=(node *)malloc(sizeof(node));
root->l->val=x;
}
else
root->l=insert(x,root->l);
}
else
{
if(root->r==NULL)
{
root->r=(node *)malloc(sizeof(node));
root->r->val=x;
}
else
{
root->r=insert(x,root->r);
}
}
}
return root;
}
node *find(int x,node *root)
{
if(root==NULL)
{
return 0;
}
else
{
if(x==root->val)
return root;
else if(x<root->val)
{
if(root->l==NULL)
{
return 0;
}
else
{
find(x,root->l);
}
}
else
{
if(root->r==NULL)
{
return 0;
}
else
{
find(x,root->r);
}
}
}
}

void inorder(node *root)
{
       if(root==NULL)
       {
              return;
       }
       if(root->l==NULL)
       {
              printf("%d",root->val);
              if(root->r==NULL)
                     return;
              else
                     inorder(root->r);
       }
       else
       {
              inorder(root->l);
              printf("%d",root->val);
              if(root->r==NULL)
                     return;
              else
                     inorder(root->r);
       }
}
void preorder(node *root)
{
       if(root==NULL)
       {
              return;
       }
       else
       {
              printf("%d",root->val);
              preorder(root->l);
              preorder(root->r);
       }
}

void postorder(node *root)
{
       if(root==NULL)
       {
              return;
       }
       else
       {
              postorder(root->l);
              postorder(root->r);
              printf("%d",root->val);
       }
}
*/
//adjacency list
/*typedef struct ll
  {
  int val;
  struct ll *next;
  }nd;

//n *ar[100001];
void insert(int a,int b)
{
if(ar[a]==NULL)
{
ar[a]=(nd *)malloc(sizeof(nd));
ar[a]->val=b;
ar[a]->next=NULL;
}
else
{
nd *temp=(nd *)malloc(sizeof(nd)),*t;
temp->val=b;
temp->next=ar[a];
ar[a]=temp;
}
}

//dfs
//int state[100001];
void dfs(int a)
{
state[a]=1;
count++;
nd *temp=ar[a];
while(temp!=NULL)
{
if(state[temp->val]!=1)
dfs(temp->val);
temp=temp->next;
}
return;
}*/

//dijkstra + heaps
/*typedef struct ll2
  {
  int val;
  int weight;
  struct ll2 *next;
  }nde;
  */
//nde *ar[500005];
//int state[500005];

/*void insert(int a,int b,int w)//insert to adjacency list
  {
  if(ar[a]==NULL)
  {
  ar[a]=(node *)malloc(sizeof(node));
  ar[a]->val=b;
  ar[a]->weight=w;
  ar[a]->next=NULL;
  }
  else
  {
  node *temp=(node *)malloc(sizeof(node)),*t;
  temp->val=b;
  temp->weight=w;
  temp->next=ar[a];
  ar[a]=temp;
  }
  }*/

//int pt[500005],d[500005];
//int heap[500005][2];
//int ptr;
/*void decpty(int val,int pos)//decrease priority
  {
  heap[pos][0]=val;
  int x=pos;
  while(x>0)
  {
  if(heap[x][0]>=heap[x/2][0])
  break;
  else
  {
  pt[heap[x][1]]=x/2;
  pt[heap[x/2][1]]=x;
  int temp=heap[x][0],t2=heap[x][1];
  heap[x][0]=heap[x/2][0];
  heap[x][1]=heap[x/2][1];
  heap[x/2][0]=temp;
  heap[x/2][1]=t2;
  x=x/2;
  }
  }
  }

  void hinsert(int val,int val2)//insert to heap
  {
  heap[ptr][0]=val;
  heap[ptr][1]=val2;
  pt[val2]=ptr;
  int x=ptr;
  ptr++;
  while(x>0)
  {
  if(heap[x][0]>=heap[x/2][0])
  break;
  else
  {
  pt[heap[x][1]]=x/2;
  pt[heap[x/2][1]]=x;
  int temp=heap[x][0],t2=heap[x][1];
  heap[x][0]=heap[x/2][0];
  heap[x][1]=heap[x/2][1];
  heap[x/2][0]=temp;
  heap[x/2][1]=t2;
  x=x/2;
  }
  }
  }

  int hdeletemin()//delete min elem from heap
  {
  int ret;
  ret=heap[1][1];
  pt[heap[1][1]]=-1;
  pt[heap[ptr-1][1]]=1;
  heap[1][0]=heap[ptr-1][0];
  heap[1][1]=heap[ptr-1][1];
  ptr--;
  int x=1;
  while(x<ptr)
  {
  if(2*x+1>=ptr)
  {
  if(2*x<ptr)
  {
  if(heap[2*x][0]<heap[x][0])
  {
  pt[heap[x][1]]=2*x;
  pt[heap[2*x][1]]=x;
  int temp=heap[x][0];
  int temp2=heap[x][1];
  heap[x][0]=heap[2*x][0];
  heap[x][1]=heap[2*x][1];
heap[2*x][0]=temp;
heap[2*x][1]=temp2;
x=2*x;
}
else
break;
}
else
break;
}
else if(heap[x][0]<=heap[2*x][0] && heap[x][0]<=heap[2*x+1][0])
       break;
       else
{
       if(heap[2*x][0]<=heap[2*x+1][0])
       {
              pt[heap[x][1]]=2*x;
              pt[heap[2*x][1]]=x;
              int temp=heap[x][0];
              int temp2=heap[x][1];
              heap[x][0]=heap[2*x][0];
              heap[x][1]=heap[2*x][1];
              heap[2*x][0]=temp;
              heap[2*x][1]=temp2;
              x=2*x;
       }
       else
       {
              pt[heap[x][1]]=2*x+1;
              pt[heap[2*x+1][1]]=x;
              int temp=heap[x][0];
              int temp2=heap[x][1];
              heap[x][0]=heap[2*x+1][0];
              heap[x][1]=heap[2*x+1][1];
              heap[2*x+1][0]=temp;
              heap[2*x+1][1]=temp2;
              x=2*x+1;
       }
}
}
return ret;
}

void dikstra(int u,int v)
{
       while(ptr!=1)
       {
              int v=hdeletemin();
              node *temp=ar[v];
              while(temp!=NULL)
              {
                     int w=temp->val;
                     if(d[v]+temp->weight < d[w])
                     {
                            d[w]=d[v]+temp->weight;
                            decpty(d[w],pt[w]);
                     }
                     temp=temp->next;
              }
       }
}*/

/*int main()
  {
  int n,m,u,v,w,i;
  scanf("%d%d",&n,&m);
  for(i=0;i<=n;i++)
  state[i]=0;
  while(m--)
  {
  scanf("%d%d%d",&u,&v,&w);
  insert(u,v,w);
  }
  scanf("%d%d",&u,&v);
  ptr=1;
  hinsert(0,u);
  d[u]=0;
  for(i=1;i<=n;i++)
  {
  if(i!=u)
  {
  hinsert(1000000000,i);
  d[i]=1000000000;
  }
  }
  dikstra(u,v);
  if(d[v]==1000000000)
  printf("NO\n");
  else
  printf("%d\n",d[v]);
  return 0;
  }*/

//kruskal + dsu

//int dsu[N];
/*int find(int x)
  {
  if(dsu[x]==x)return x;
  return dsu[x] = find(dsu[x]);
  }

  void Union(int a,int b)
  {
  if(a==b)
  return;
  dsu[a] = b;
  }

  typedef struct edge
  {
  int u,v;
  int weight;
  }edge;
  */
//edge e[N];
/*int cmp(const void *a,const void *b)
  {
  return ((edge*)a)->weight - ((edge*)b)->weight;
  }*/
/*int main()
  {
  int i;
  int n,m;
  scanf("%d %d\n",&n,&m);
  for(i=0;i<m;i++)
  scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].weight);
  for(i=1;i<=n;i++)
  dsu[i]=i;
  qsort(e,m,sizeof(edge),cmp);
  long long int sum=0;
  for(i=0;i<m;i++)
  {
  int a,b;
  if((a=find(e[i].u))!=(b=find(e[i].v)))
  {
  sum+=e[i].weight;
  Union(a,b);
  }
  }
  printf("%lld\n",sum);
  return 0;
  }*/

//max
/*int max(int a,int b)
  {
  if(a>b)
  return a;
  else
  return b;
  }
  */
//qsort

/*int cmpfunc(const void *a,const void *b)
  {
  return (*(int *)a - *(int *)b);
  }*/
//qsort(ar,n,sizeof(int),cmpfunc);

//-------------------------------------------------------------------------------------------------------------------------------------

int main()
{
       int n,m,ct,ans=0;
       scan(n);
       scan(m);
       int i,j,k,val=0;
       int dig1,dig2;
       val=(n-1)/7;
       dig1=1;
       dig2=1;
       while(val>0)
       {
              dig1++;
              val=val/7;
       }

       val=(m-1)/7;
       while(val>0)
       {
              dig2++;
              val=val/7;
       }
       val=dig1+dig2;
       if(val>7)
       {
              ans=0;
              print(ans);
              return 0;
       }
       int status[10],st2[10],cond=0;
       for(i=0;i<n;i++)
       {
              for(j=0;j<m;j++)
              {
                     cond=0;
                     int k=0;
                     for(k=0;k<10;k++)
                            status[k]=0;
                     int a,b,v1=i,v2=j;
                     for(a=0;a<dig1;a++)
                     {
                            if(status[v1%7]==1)
                            {
                                   cond=1;
                                   break;
                            }
                            else
                                   status[v1%7]=1;
                            v1=v1/7;
                     }

                     for(a=0;a<dig2;a++)
                     {
                            if(cond==1)
                                   break;
                            if(status[v2%7]==1)
                            {
                                   cond=1;
                                   break;
                            }
                            else
                                   status[v2%7]=1;
                            v2=v2/7;
                     }
                     if(cond==0)
                     {
                            ans++;
                     }
              }

       }
       print(ans);
       return 0;
}


#include<stdio.h>
long max(long x , long y){ return x>y?x:y; }
int main()
{
    long i,j,n,m,a,b,ans[4],min,f=0;
    long cint,dint;
    float c,d;
    scanf("%ld%ld%ld%ld%ld%ld",&n,&m,&i,&j,&a,&b);
    if(a>=n || b>=m)
    {
            printf("Poor Inna and pony!");
            return 0;
    }
    c=(i-1)*1.0/a;
    d=(j-1)*1.0/b;

    if(c==(long int)c && d==(long int)d)
    {
        cint=(long int)c;
        dint=(long int)d;
        if(abs(cint-dint)%2==0)
        ans[f++]=max(cint,dint);
    }

    c=(n-i)*1.0/a;
    d=(j-1)*1.0/b;

    if(c==(long int)c && d==(long int)d)
    {
        cint=(long int)c;
        dint=(long int)d;
        if((abs(cint-dint))%2==0)
        ans[f++]=max(cint,dint);
    }

    c=(i-1)*1.0/a;
    d=(m-j)*1.0/b;

    if(c==(long int)c && d==(long int)d)
    {
        cint=(long int)c;
        dint=(long int)d;
        if(abs(cint-dint)%2==0)
        ans[f++]=max(cint,dint);
    }

    c=(n-i)*1.0/a;
    d=(m-j)*1.0/b;

    if(c==(long int)c && d==(long int)d)
    {
        cint=(long int)c;
        dint=(long int)d;
        if(abs(cint-dint)%2==0)
        ans[f++]=max(cint,dint);
    }

    if(f==0)
    {
            printf("Poor Inna and pony!");
            return 0;
    }
    min=1000000;
    for(i=0;i<f;i++)
    if(min>ans[i])
    min=ans[i];

    printf("%ld",min);
    getch();
}


#include <stdio.h>

int mod_inv(int a, int p){
	int y = p-2;
	int res = 1;
	while(y!=0){
		if(y&1){
			res = ((long long)res * a)%p;
		}
		a = ((long long)a*a)%p;
		y = y>>1;
	}
	return res;
}

int main(void) {
	// your code goes here
	int n,c,i;
	scanf("%d %d",&n,&c);
	int res = c;
	int prev = c;
	int p = 1000003;
	for(i=2; i<=n ;i++){
		prev = ((((long long)(c+i-1)*prev)%p)*mod_inv(i,p))%p;
		res = (res + prev)%p;
	}
	printf("%d\n",res);
	return 0;
}


#include<stdio.h>

#define MOD 998244353
int fact[1000006], wpar[1000006<<1], n, level;

int mul(int a, int b){
  return (a*1ll*b)%MOD;
}

int powmod(int b, int p){
  int t = 1;
  while(p){
    if(p&1)t = mul(t, b);
    b = mul(b, b);
    p>>=1;
  }
  return t;
}

int ncr(int _n, int r){
  return mul(mul(fact[_n], powmod(fact[r], MOD - 2)), powmod(fact[_n - r], MOD - 2));
}

int main(){
  int i;
  scanf("%d", &n);

  fact[0] = 1;
  for(i = 1;i < 1000006;i++)fact[i] = mul(fact[i - 1], i);

  if(n == 1 || n == 2){printf("1\n");return 0;}
  if(n == 3){printf("0\n");return 0;}

  for(level = 0; (1<<level) - 1 < n;level++);
  level--;
  //  printf("level: %d\n", level);

  int half, rem;
  half = 1<<(level - 2);
  rem = n - (1<<level) + 1;

  rem -= half;

  //  printf("rem: %d, half: %d\n", rem, half);
  if(rem < 0 || rem > half){printf("0\n");return 0;}
  printf("%d\n", ncr(half, rem));

  return 0;
}


#include <stdio.h>

/* http://codeforces.com/contest/894/submission/34556698 (Dukkha) */

#define MD	1000000007

int power(int a, int b) {
	int p;

	if (b == 0)
		return 1;
	p = power(a, b / 2);
	p = (long long) p * p % MD;
	if (b % 2 == 1)
		p = (long long) p * a % MD;
	return p;
}

int main() {
	int n, m, k;

	scanf("%d%d%d", &n, &m, &k);
	printf("%d\n", k == -1 && n % 2 != m % 2 ? 0 : power(2, (long long) (n - 1) % (MD - 1) * (m - 1) % (MD - 1));
	return 0;
}


#include <stdio.h>

int main()
{
    long long unsigned int n,i,j,result=0;
    int m;
    int ss;
    scanf("%I64d",&n);
    scanf("%d",&m);
    if(m==1)
    {
        printf("%I64d",n*n);
        return 0;
    }
    for(i=1;i<=n;i++)
        for(j=1;j<=i;j++)
        {
            if( (i*i+j*j)%m==0 && i!=j) result+=2;
            if( (i*i+j*j)%m==0 && i==j) result+=1;
        }
    printf("%I64d",result);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef long long unsigned llu;
typedef unsigned u;
typedef struct S
{
	u val,ki,ka;llu sum;
	struct S *lc,*rc;
}v;
v*alloc(u ki,u ka,u val)
{
	v*x;
	x=(v*)malloc(sizeof(v));
	x->val=val;
	x->ki=ki;
	x->ka=ka;
	x->sum=(ka-ki+1)*(llu)val;
	x->lc=x->rc=NULL;
	return x;
}
llu que(v *x,u lo,u hi)
{
	printf("que %u %u\n",lo,hi);
	if(hi<x->ki||lo>x->ka)
	{
		printf("return 0\n");
		return 0;
	}
	if(lo<=x->ki&&hi>=x->ka)
	{
		printf("Return %I64u\n",x->sum);
		return x->sum;
	}
	u ll,rr;
	if(x->val)
	{
		ll=lo<x->ki?x->ki:lo;
		rr=hi>x->ka?x->ka:hi;
		if(rr<ll)
		{
			printf("return -0\n");
			return 0;
		}
		printf("ll=%u rr=%u x->val=%u\n",ll,rr,x->val);
		return(rr-ll+1)*(llu)x->val;
	}
	llu a=que(x->lc,lo,hi)+que(x->rc,lo,hi);
	printf("Retu5n %I64u\n",a);
	return a;
}
void set(v *x,u lo,u hi,u val)
{
	if(hi<x->ki||lo>x->ka)return;
	u m;
	if(x->val)
	{
		if(val<=x->val)return;
		if(lo<=x->ki&&hi>=x->ka)
		{
			x->val=val;
			x->sum=val*(llu)(x->ka-x->ki+1);
			return;
		}
		m=(x->ki+x->ka)>>1;
		if(!x->lc)x->lc=alloc(x->ki,m,val);
		if(!x->rc)x->rc=alloc(m+1,x->ka,val);
		x->val=0;
	}
	set(x->lc,lo,hi,val);
	set(x->rc,lo,hi,val);
	if(x->lc->val&&x->lc->val==x->rc->val)
	{
		x->val=x->lc->val;
		x->sum=x->val*(llu)(x->ka-x->ki+1);
	}
	else x->sum=x->lc->sum+x->rc->sum;
	return;
}
v *p;
u A[222222],F[222222];
int main()
{
	u n,i,j,k,x;llu r=0llu;
	scanf("%u",&n);
	p=alloc(1,n,1);
	for(i=0;++i<=n;A[i]=x)
	{
		scanf("%u",&x);
		for(j=1;j*j<=x;++j)if(x%j==0)
		{
			if(!F[j])F[j]=i;
			if(!F[k=x/j])F[k]=i;
		}
	}
	for(i=n;i;--i)
	{
		for(x=A[i],j=1;j*j<=x;++j)if(x%j==0)
		{
			if(F[j]&&F[j]<i)
			{
				printf("set %u %u %u\n",F[j],i-1,j);
				set(p,F[j],i-1,j);
			}
			if(F[k=x/j]&&F[k]<i)
			{
				printf("set %u %u %u\n",F[k],i-1,k);
				set(p,F[k],i-1,k);
			}
		}
		r+=que(p,1,i-1);
		printf("i=%u r=%I64u\n",i,r);
	}
	printf("%I64u\n",r);
	return 0;
}


#include <stdio.h>
#define oo 1000000000
#define gmin(a,b) ((a)>(b)?(b):(a))
long getans=0,w[10000]={0},h[10000]={0},n,min,total=0,hash[40000000]={0},z[2000000]={0},an[200000]={0};
void work(long k,long tot)
{
    long i,o,j;
    if(k<=n)
    {
        if(k>min)
            return ;
        for(i=1;i<=tot;i++)
        {
            w[i]-=k;
            o=min;
            h[k]=i;
            if(w[i] && w[i]<min)
                min=w[i];
            if(w[i]==0)
            {
                min=oo;
                for(j=1;j<=tot;j++)
                    if(w[j]<min && w[j])
                        min=w[j];
            }
            work(k+1,tot);
            if(getans)
                return;
            h[k]=0;
            min=o;
            w[i]+=k;
        }
    }
    else
        getans=1;
}
void dfs(long onp,long k,long tot,long count)
{
    long i;
    if(k<tot)
    {
        for(i=onp+1;i<=total && count-z[i]>=0;i++)
        {
            an[k]=z[i];
            dfs(i+1,k+1,tot,count-z[i]);
            if(getans)
                return ;
        }
    }
    else
    {
        if(hash[count]==0)
        {
            for(i=1;i<tot;i++)
                w[i]=an[i];
            w[k]=count;
            min=gmin(count,w[1]);
            work(1,tot);
        }
    }
}
int main()
{
    long i,top,j,ans;
    scanf("%ld\n",&n);
    top=(1+n)*n/2;
    for(i=2;i<=top;i++)
    {
        if(hash[i]==0)
            z[++total]=i;
        for(j=2;j<=total && j*i<=top;j++)
        {
            hash[j*i]=1;
            if(i%j==0)
                break;
        }
    }
    for(ans=1;;ans++)
    {
        dfs(0,1,ans,top);
        if(getans)
        {
            printf("%ld\n",ans);
            for(i=1;i<=n;i++)
                printf("%ld ",h[i]);
            return 0;
        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MAX 102
#define LIM 303
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

bool visited[MAX][303][LIM][2];
int n, t, counter[1010], ar[MAX], dp[MAX][303][LIM][2];

int F(int i, int l, int r, int flag){
    if (i > n){
        if (r == t || r == LIM){
            if (!flag) return (counter[l] * (t - r));
            else return 0;
        }
        else return F(0, l, r + 1, flag);
    }
    if (visited[i][l][r][flag]) return dp[i][l][r][flag];

    int x, res = F(i + 1, l, r, flag);
    if (ar[i] >= l){
        x = 1 + F(i + 1, ar[i], r, flag);
        if (x > res) res = x;
    }
    if (!flag && t > LIM){
        x = F(i, l, r, 1) + (counter[l] * (t - LIM));
        if (x > res) res = x;
    }

    visited[i][l][r][flag] = true;
    return (dp[i][l][r][flag] = res);
}

int main(){
    int i, j, k;

    while (scanf("%d %d", &n, &t) != EOF){
        if (!n) break;

        clr(counter);
        for (i = 1; i <= n; i++){
            scanf("%d", &ar[i]);
            counter[ar[i]]++;
        }

        clr(visited);
        int res = F(1, 0, 1, 0);
        printf("%d\n", res);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
long long int fact(long int x){
    if(x==1)
        return 1;
    long long int ans,d;
    ans= x*fact(x-1);
    d= pow(10,9)+7;
    return ans%d;
}
long long int power(long int x){
    long int i;
    long long int ans=1,d;
    d= pow(10,9)+7;
    for(i=0;i<x;i++){
        ans=(ans*2) %d;
    }
    return ans%d;
}

int main ()
{
    long int n;
    long long int ans,d;
    scanf("%ld",&n);
    d= pow(10,9)+7;
    ans= (fact(n)-power(n-1))%d;
    printf("%lld",ans);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define M	4167669	/* (23 choose 7) * 17 */
#define C	16
#define K	2000000000
#define T	7

void print(int k) {
	if (k == 0)
		return;
	print(k / C);
	printf("%c", k % C < 10 ? k % C + '0' : k % C - 10 + 'a');
}

int add(int a, int b) { return (long long) a + b < K ? a + b : K; }

int choose[C + T][C + T];

void init() {
	int n, r;

	choose[0][0] = 1;
	for (n = 1; n < C + T; n++) {
		choose[n][0] = 1;
		for (r = 1; r <= n; r++)
			choose[n][r] = choose[n - 1][r - 1] + choose[n - 1][r];
	}
}

int dp[M], m;

void branch(int *aa, int h) {
	int a, len, j;

	if (h == C) {
		for (len = 0; len <= C; len++) {
			if (len == 0)
				dp[m] = 1;
			else
				for (h = 0; h < C; h++) {
					if (aa[h] == 0)
						continue;
					if (h == 0 || aa[h - 1] != aa[h]) {
						a = aa[h] - 1;
						j = m / (C + 1) - choose[C - h - 1 + T - a][T - a];
						if (h < C - 1)
							j += choose[C - h - 2 + T - a][T - a];
						j = j * (C + 1) + len - 1;
					}
					dp[m] = add(dp[m], dp[j]);
				}
			m++;
		}
		return;
	}
	for (a = h == 0 ? 0 : aa[h - 1]; a <= T; a++) {
		aa[h] = a;
		branch(aa, h + 1);
	}
}

int idx(int *aa, int len) {
	int h, a, sum;

	sum = 0;
	for (h = 0; h < C; h++)
		for (a = h == 0 ? 0 : aa[h - 1]; a < aa[h]; a++)
			sum += choose[C - h - 1 + T - a][T - a];
	return sum * (C + 1) + len;
}

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int main() {
	static int aa[C], bb[C];
	int k, t, h, i, len, first;

	scanf("%d%d", &k, &t);
	if (t >= 8) {
		print(k);
		printf("\n");
		return 0;
	}
	init();
	branch(aa, 0);
	for (h = 0; h < C; h++)
		aa[h] = t;
	for (len = 1; ; len++) {
		int cnt = dp[idx(aa, len)];

		aa[0]--; cnt -= dp[idx(aa, len - 1)]; aa[0]++;
		if (k <= cnt)
			break;
		k -= cnt;
	}
	first = 1;
	while (len-- > 0) {
		for (h = first ? 1 : 0; h < C; h++) {
			memcpy(bb, aa, C * sizeof *aa);
			if (bb[h] == 0)
				continue;
			bb[h]--;
			qsort(bb, C, sizeof *bb, compare);
			if (k > dp[i = idx(bb, len)]) {
				k -= dp[i];
				bb[h]++;
			} else {
				printf("%c", h < 10 ? h + '0' : h - 10 + 'a');
				aa[h]--;
				break;
			}
		}
		first = 0;
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
long long int fib[55];
void fibo(int n)
{
	if(n==53)
		return;
	fib[n]=fib[n-1]+fib[n-2];
	fibo(n+1);
}
void func(int k,int r,int n)
{
	if(n==0)
		return;
	if(k<=fib[n])
	{
		printf("%d ",1+r);
		func(k,r+1,n-1);
	}
	else
	{
		printf("%d %d ",2+r,1+r);
		func(k-fib[n],r+2,n-2);
	}
}
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	fib[1]=1;
	fib[2]=1;
	fibo(3);
	func(k,0,n);
	printf("\n");
	return 0;
}


#include<stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	printf("%d 2\n1 2",2*n+1);
	return 0;
}


#include <stdio.h>

int main() {
  int k,i,a,j;
  int t[k];
  int max ;
  printf("donner un k : ");
  scanf("%d",&k);
  for ( i = 0; i < k; i++) {
    printf("donner r %d  : ",i);
    scanf("%d",&t[i]);
  }
  max= t[0];
  for ( j = 1; j < k; j++) {
    if (max<t[j]) {
      max=t[j];
    }
  }
  a=max-25;
  if (a<0)
    printf("0");
  else
    printf("%d",a);
  return 0;
}


#include<stdio.h>
#include<string.h>

char a[50][5], b[50][5];
char dict[50000][10];
int ans=0;

int dfs(char str[], int q, int n)
{
	int i,j,k;

	//printf("%s\n", str);

	if(strlen(str)==n)
	{
		int flag=0;
		for(i=0;i<ans;i++)
		{
			if(strcmp(dict[i], str)==0)
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
		{
			strcpy(dict[ans], str);
			ans++;
		}
		return(0);
	}

	//for(j=0;j<strlen(str);j++)
	//{
		for(i=0;i<q;i++)
		{
			if(str[0] == b[i][0])
			{
				char send[50];
				int m=0;
				for(k=0;k<0;k++)
				{
					send[m]=str[k];
					m++;
				}
				send[m]=a[i][0];
				send[m+1]=a[i][1];
				m+=2;
				for(k=0+1;k<strlen(str);k++)
				{
					send[m]=str[k];
					m++;
				}
				dfs(send,q,n);
			}
		}
	//}
	return(0);
}

int main(void)
{
	int n,q,i,j;
	scanf("%d %d", &n, &q);

	for(i=0;i<q;i++)
		scanf("%s %s", a[i], b[i]);

	char str[1000];
	str[0]='a';
	str[1]='\0';

	dfs(str, q, n);

	printf("%d\n", ans);

	return(0);
}


#include <stdio.h>
#include <string.h>

#define N	100000

int md;

long long power(long long a, int k) {
	long long p = 1;

	while (k) {
		if (k & 1)
			p = p * a % md;
		a = a * a % md;
		k >>= 1;
	}
	return p;
}

int vv[N + 1], ff[N + 1], gg[N + 1];

void init() {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= N; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - md % i] * (md / i + 1) % md;
		ff[i] = (long long) ff[i - 1] * i % md;
		gg[i] = (long long) gg[i - 1] * vv[i] % md;
	}
}

int choose(int n, int k) {
	return k < 0 || k > n ? 0 : (long long) ff[n] * gg[k] % md * gg[n - k] % md;
}

int aa[N], cnt;

void brute(int i, int n) {
	if (i == n) {
		int b, c, d, i, j;

		for (b = 0; b < 1 << n; b++) {
			c = (1 << n) - 1;
			for (i = 0; i < n; i++)
				if ((b & 1 << i) != 0) {
					if ((c & 1 << aa[i]) == 0)
						goto out;
					c &= ~(1 << aa[i]);
				}
			for (i = 0; i < n; i++)
				if ((c & 1 << i) != 0 && (c & 1 << aa[i]) != 0)
					goto out;
			c = 0;
			for (i = 0; i < n; i++) {
				if ((c & 1 << i) != 0)
					continue;
				j = i, d = 0;
				while (((c | d) & 1 << j) == 0)
					d |= 1 << j, j = aa[j];
				if ((c & 1 << j) != 0) {
					c |= d;
					continue;
				}
				c |= d, d = 0;
				while ((d & 1 << j) == 0)
					d |= 1 << j, j = aa[j];
				if ((b & d) == d)
					goto out;
			}
			cnt++;
out:;
		}
		return;
	}
	for (aa[i] = 0; aa[i] < n; aa[i]++)
		if (aa[i] != i)
			brute(i + 1, n);
}

int slow(int n) {
	int k, l, ans;

	ans = 0;
	for (k = 1; k <= n; k++)
		for (l = k; l + k <= n; l++)
			ans = (ans + (long long) choose(n, l + k)
					* ff[l + k] % md
					* gg[k] % md
					* choose(l - 1, k - 1) % md
					* power(n - 1, k) % md
					* power(l, n - l - k)) % md;
	return ans;
}

int main() {
	int n, n1;

	scanf("%d%d", &n1, &md), init();
	for (n = n1; n <= n1; n++) {
#if 0
		cnt = 0, brute(0, n);
		printf("%d\n", cnt);
#else
		printf("%d\n", slow(n));
#endif
	}
	return 0;
}


/*
ID: Sfiction
OJ: CF128 Div2
PROB: D
*/
#include <stdio.h>
int main()
{
    double a,b,m,vx,vy,vz;
    double x,z,t;
    scanf("%lf%lf%lf",&a,&b,&m);
    scanf("%lf%lf%lf",&vx,&vy,&vz);
    t=-m/vy;
    x=a/2+t*vx;
    z=t*vz;
    while (x<0||x>a)
        if (x>a) x=2*a-x;
        else x=-x;
    while (z<0||z>b)
        if (z>b) z=2*b-z;
        else z=-z;
    printf("%.10lf %.10lf",x,z);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define ll long long

ll solve(ll a, ll b) {
    ll i,k = 0;
    int* factors = malloc(sizeof(int)*1000*1000);
    //record the smaller factors of a
    for (i = 1; i*i <= a; i++) {
        if (a%i == 0) {
            factors[k++] = i;
            // printf("factor of a:%lli\n", i);
        }
    }
    //for each smaller factor of a+b
    ll answer = 2*(a+b+1);
    for (i = 1; i*i <= a+b; i++) {
        if ((a+b)%i == 0) {
            // printf("factor of a+b:%lli\n", i);
            //binary search a factor of a that is smaller than or equal to i
            int found = 0;
            ll hi = k;
            ll lo = 1;
            ll middle = 0;
            while (!found) {
                middle = (lo + hi)/2;
                if (middle == lo || middle == hi) {
                    break;
                } else if (factors[middle] < i) {
                    lo = middle;
                } else if (factors[middle] > i) {
                    hi = middle;
                } else { // middle = i
                    found = 1;
                    break;
                }
            }
            // printf("i found %lli for a, %lli for a+b\n", factors[middle],i);
            // printf("a/fact=%lli <= a+b/i=%lli?\n",a/factors[middle],(a+b)/i);
            if (a/factors[middle] <= (a+b)/i) {
                if (answer > 2*(i + (a+b)/i)) {
                    answer = 2*(i + (a+b)/i);
                    // printf("NEW answer: %lli\n", answer);
                }
            }
        }
    }
    return answer;
}

int main(int argc, char* argv[]) {
    ll a,b = 0;
    scanf("%lli %lli",&a,&b);
    // printf("%lli + %lli = %lli\n", a, b, a+b);
    ll answer_a = solve(a,b);
    ll answer_b = solve(b,a);
    if (answer_a < answer_b) {
        printf("%lli\n", answer_a);
    } else {
        printf("%lli\n", answer_b);

    }
    return 0;
}


#include <stdio.h>
#include <math.h>

int winning(int n, int k);
int expmod(int a, int b, int m);
const int mod = 1000000007;

int main () {
  int t;
  int n;
  int k;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    scanf("%d %d", &n, &k);
    printf("%d\n", winning(n, k));
  }
}

int winning (int n, int k) {
  if (k == 0) {
    return 1;
  }
  if (n % 2 == 0) {
    long long int result = expmod(2, n*(k-1), mod) + (expmod(2, n-1, mod)-1)*winning(n, k-1);
    return result % mod;
  }
  else {
    long long int result = (expmod(2, n-1, mod)+1)*winning(n, k-1);
    return result % mod;
  }
}

int expmod(int a, int b, int m)
{
	int res = 1;
	a = a % m;

	if (a == 0) return 0;

	while (b > 0)
	{
		if (b & 1)
			res = (res*a) % m;

		b = b>>1;
		a = (a*a) % m;
	}
	return res;
}


#include <stdio.h>
int f(int k)
{
    return ((min(k,25)+k)mod(2+k%3) > 0)? 1: 0;
}
int main()
{
    for (int _ = 21; _ <= 50; ++ _)
        printf("%d\n", f(_));
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#define mod 1000000007

#ifdef __cplusplus
extern "C" {
#endif
__attribute__((always_inline, optimize(3)))
__inline__ void add(int *x, int y) {
	(*x += y) >= mod && (*x -= mod);
}
__attribute__((always_inline, optimize(3)))
__inline__ int mul(int x, int y) {
	return (long long)x * y - (long long)x * y / mod * mod;
}
__attribute__((always_inline, optimize(3)))
__inline__ int f(int n, int x, int y) {
	int tmp = 1 << x;
	y && (tmp *= 3);
	return n / tmp;
}
#ifdef __cplusplus
}
#endif
int main() {
	int n, p = 0; scanf("%d", &n);
	static int dp[1000005][21][2] = { };
	while ((1 << p) <= n) ++ p; dp[1][-- p][0] = 1;
	if ((3 << p - 1) <= n) dp[1][p - 1][1] = 1;
	for (int i = 1; i < n; ++ i)
		for (int x = 0; x <= p; ++ x)
			for (int y = 0; y < 2; ++ y) {
				add(dp[i + 1][x] + y, mul(dp[i][x][y], f(n, x, y) - i));
				x && (add(dp[i + 1][x - 1] + y, mul(dp[i][x][y], f(n, x - 1, y) - f(n, x, y))), 0);
				y && (add(dp[i + 1][x] + y - 1, mul(dp[i][x][y], f(n, x, y - 1) - f(n, x, y))), 0);
			}
	printf("%d\n", dp[n][0][0]);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 105;

int used[maxn];
int l[maxn];
int a[maxn];

int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++) cin >> l[i];
    for(int i = 1; i < m; i++) {
        int delta = l[i] - l[i-1];
        if(delta <= 0) {
            delta = n + delta;
        }
        if(l[i-1] != used[delta] && used[delta] != 0) {
            cout << "-1" << endl;
            return 0;
        }
        a[l[i-1]] = delta;
        used[delta] = l[i-1];
    }
    if(a[1] == 0) {
        for(int i = 1; i < maxn; i++) {
            if(!used[i]) {
                a[1] = i;
                used[i] = true;
                break;
            }
        }
    }
    cout << a[1];
    for(int i = 2; i <= n; i++) {
        if(a[i] == 0) {
            for(int j = 1; j < maxn; j++) {
                if(!used[j]) {
                    a[i] = j;
                    used[j] = true;
                    break;
                }
            }
        }
        cout << " " << a[i];
    }
    cout << endl;
    return 0;
}


#include<stdio.h>
#include<string.h>
#define ll long long

int max(int x, int y) {
	if(x > y) {
		return x;
	}
	return y;
}

int n, k;
char s[200];
int dp[200][200];
int poo(int ind, int rem) {
	if(rem < 0) {
		return 0;
	}
	if(ind == n) {
		return (rem == 0);
	}
	if(dp[ind][rem] != -1) {
		return dp[ind][rem];
	}
	if(rem == 0 && s[ind] != 'N') {
		return dp[ind][rem] = 1;
	}
	int ret = 0;
	if(s[ind] == 'Y') {
		ret = poo(ind+1, k);
	} else if(s[ind] == 'N') {
		ret = poo(ind+1, rem-1);
	} else {
		ret = poo(ind+1, rem-1) | poo(ind+1, k);
	}
	return dp[ind][rem] = ret;
}

int main() {
	for(int i=0;i<200;i++) {
		for(int j=0;j<200;j++) {
			dp[i][j] = -1;
		}
	}
	scanf("%d%d", &n, &k);
	scanf("%s", s);

	int ct = 0;
	for(int i=0;i<n;i++) {
		if(s[i] == 'N') {
			ct ++;
		} else {
			if(ct > k) {
				printf("NO\n");
				return 0;
			}
			ct = 0;
		}
	}
	if(ct > k) {
		printf("NO");
		return 0;
	}

	ll ret = poo(0, k);
	if(ret) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}
}


/* upsolve with Dukkha */
#include <stdio.h>

#define N	2000
#define MD	998244353

int ch[1 + N][1 + N];

void init(int n) {
	int i, j;

	ch[0][0] = 1;
	for (i = 1; i <= n; i++) {
		ch[i][0] = 1;
		for (j = 1; j <= i; j++)
			ch[i][j] = (ch[i - 1][j] + ch[i - 1][j - 1]) % MD;
	}
}

long long power(int a, int k) {
	long long p;

	if (k == 0)
		return 1;
	p = power(a, k / 2);
	p = p * p % MD;
	if (k % 2)
		p = p * a % MD;
	return p;
}

int main() {
	static long long pp[1 + N + N], qq[1 + N + N], aa[1 + N + N];
	int n, k, l, i, j;
	long long inv2, a;

	scanf("%d%d%d", &n, &k, &l);
	init(n);
	pp[n] = power(2, n);
	for (i = 0; i < n; i++)
		for (j = n + n; j > 0; j--)
			pp[j] = (pp[j] - pp[j - 1]) % MD;
	for (j = 0; j <= n + n; j++)
		aa[j] = pp[j];
	inv2 = (MD + 1) / 2;
	for (i = 1; i <= n - k; i++) {
		/* qq := pp / p, where p = 2x (1 - x) */
		/* divide by 2x */
		for (j = 1; j < n + n; j++)
			qq[j] = pp[j + 1] * inv2 % MD;
		qq[n + n] = 0;
		/* divide by 1 - x is multiply by 1 + x + x^2 + x^3 + ... */
		for (j = 1; j <= n + n; j++)
			qq[j] = (qq[j] + qq[j - 1]) % MD;
		/* pp := pp * (1 - p) / p = pp / p - pp = qq - pp */
		for (j = 0; j <= n + n; j++)
			pp[j] = (qq[j] - pp[j]) % MD;
		a = ch[n][i];
		for (j = 0; j <= n + n; j++)
			aa[j] = (aa[j] + a * pp[j]) % MD;
	}
	/* integrate x^i to x^{i + 1} / (i + 1) */
	a = 0;
	for (i = 0; i <= n + n; i++)
		a = (a + aa[i] * power(i + 1, MD - 2)) % MD;
	a = (a * l % MD + MD) % MD;
	printf("%lld\n", a);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MAX 5010
#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

char S[MAX], T[MAX];
short next[MAX][MAX];
bool visited[MAX][MAX];
int n, m, dp[MAX][MAX];

int F(int i, int j){
    if (i >= n || j >= m) return 0;
    if (visited[i][j]) return dp[i][j];

    unsigned int res = 0;
    if (next[i][j] != -1){
        res = res + F(i + 1, next[i][j] + 1) + 1;
        if (res >= MOD) res -= MOD;
        res = res + F(i, next[i][j] + 1);
        if (res >= MOD) res -= MOD;
    }

    visited[i][j] = true;
    return (dp[i][j] = res);
}

int main(){
    int i, j, k;

    while (scanf("%s %s", S, T) != EOF){
        clr(visited);
        n = strlen(S), m = strlen(T);
        for (i = 0; i < n; i++){
            for (j = m - 1; j >= 0; j--){
                next[i][j] = -1;
                if (S[i] == T[j]) next[i][j] = j;
                else if ((j + 1) != m) next[i][j] = next[i][j + 1];
            }
        }

        long long res = 0;
        for (i = 0; i < n; i++){
            for (j = 0; j < m; j++){
                if (S[i] == T[j]){
                    res = res + F(i + 1, j + 1) + 1;
                }
            }
        }
        printf("%lld\n", res % MOD);
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define size 100
int max(int a,int b)
{
	if(a>b)
	  return a;
	else
	  return b;
}
int partition(int a[],int l,int u)
{
	int v,i,j,temp;
	v=a[l];
	i=l;
	j=u+1;

	do
	{
		do
			i++;

		while(a[i]<v&&i<=u);

		do
			j--;
		while(v<a[j]);

		if(i<j)
		{
			temp=a[i];
			a[i]=a[j];
			a[j]=temp;
		}
	}while(i<j);

	a[l]=a[j];
	a[j]=v;

	return(j);
}
void quick_sort(int a[],int l,int u)
{
	int j;
	if(l<u)
	{
		j=partition(a,l,u);
		quick_sort(a,l,j-1);
		quick_sort(a,j+1,u);
	}
}
main()
{
	int n,m,i,j;
	scanf("%d %d",&n,&m);
	int a[size+1];
	for(i=0;i<n;++i)
	{
		scanf("%d",&a[i]);
	}
quick_sort(a,0,n-1);
i=0;
j=n-1;
while(i<j)
{
	int temp=a[i];
	a[i]=a[j];
	a[j]=temp;
	i++;
	j--;
}
for(i=1;i<=n;++i)
{
	int sum=0;
	for(j=0;j<n;++j)
	{
		sum+=(max(0,a[j]-j/i));
	}
	if(sum>=m)
	{
		printf("%d",i);
		exit(0);
	}
}
printf("-1");
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;
ll MIN =  1111111111111111111;
ll MAX = -1111111111111111111;
ll max = -1111111111111111111;

void merge(ll arr[], ll l, ll m, ll r)
{
    ll i, j, k;
    ll n1 = m - l + 1;
    ll n2 =  r - m;

    /* create temp arrays */
    ll L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back llo arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(ll arr[], ll l, ll r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        ll m = l+(r-l)/2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

int main(ll argc, char const *argv[])
{
    ll T;
 //   scanf("%lld",&T);
    T = 1;
   // printf("%lld %lld %lld",MIN,MAX,max);
    for (ll tqw = 0; tqw < T; tqw++)
    {
        ll x,y,l,r ;
        scanf("%lld %lld %lld %lld",&x,&y,&l,&r);
        ll o = l;
        ll xcountl =  -1;
        while(o)
        {
            xcountl++;
            o = o/x ;
        }

        ll p = r;
        ll xcountr = 0;
        while(p)
        {
            xcountr++;
            p = p/x;
        }
        ll e = r;
        ll ycountr = 0;
        while(e)
        {
            ycountr++;
            e = e/y;
        }
        ll qw = l;
        ll ycountl = -1;
        while(qw)
        {
            ycountl++;
            qw = qw/y;
        }

    //    printf("%lld %lld\n",xcountl,xcountr);

        ll totalcount = 0;
        ll A[1000000];
        ll idx = 0;
        for(ll s=xcountl;s<xcountr;s++)
        {
            ll u = 0;
            while(power(y,u)+power(x,s)<l)
            {
                u++;
            }
            while(power(y,u)+power(x,s)<=r)
            {
                A[idx] = power(y,u)+power(x,s) ;
                if(A[idx]>MAX)
                MAX = A[idx] ;
                if(A[idx]<MIN)
                MIN = A[idx] ;
                idx++;
                totalcount++;
                u++;
            }
        }
        for(ll s=ycountl;s<ycountr;s++)
        {
            ll u = 0;
            while(power(x,u)+power(y,s)<l)
            {
                u++;
            }
            while(power(x,u)+power(y,s)<=r&&u<xcountl)
            {
                A[idx] = power(x,u)+power(y,s) ;
                if(A[idx]>MAX)
                MAX = A[idx] ;
                if(A[idx]<MIN)
                MIN = A[idx] ;
                idx++;
                totalcount++;
                u++;
            }
        }
      /*  for(ll g=0;g<idx;g++)
        printf("|%lld|",A[g]);

*/
 //       printf("\n|%lld %lld|",MIN,MAX);
        mergeSort(A,0,idx-1);
    //          for(ll g=0;g<idx;g++)
 //       printf("|%lld|",A[g]);

       // printf("\n|%lld %lld|",MIN,MAX);
        for(ll sd = 1;sd<idx;sd++)
        {
            if(A[sd]-A[sd-1]-1>max)
            max = A[sd]-A[sd-1]-1 ;
          //  if(max<0)max=0;
        }
        ll finalanswer = 0;
        ll left = MIN-l;
        if(left<0)left = 0;
        ll right = r-MAX;
        if(right<0)right = 0;
      /*  printf("l %lld r %lld %lld|",left,right,max);*/
        if(left>right)
        {
            if(left>max)
            {
                finalanswer = left;
            }
            else
            {
                finalanswer = max ;
            }
        }
        else
        {
            if(right>max)
            {
                finalanswer = right;
            }
            else
            {
                finalanswer = max ;
            }
        }
        //  printf("<%lld>",totalcount);
        if(totalcount==0)
        {
            finalanswer = r-l+1 ;
        }
        if(l==1)
        {
        if(r-l+1-totalcount==0)
        printf("0\n");
        else
        {printf("%lld\n",finalanswer);}
        }

        else{
        if(r-l+1-totalcount==0)
        printf("0\n");
        else
        { printf("%lld\n",finalanswer);}
        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main(void)
{
    char num[101];
    char str[101];

    gets(num);
    gets(str);

    int in[10], out[10];

    memset(in, 0, sizeof(in));
    memset(out, 0, sizeof(out));

    for(int i = 0; num[i] != 0; ++i)
    {
        if(num[i] == '9') in[6]++;
        else if(num[i] == '5') in[2]++;
        else in[num[i] - '0']++;
    }
    for(int i = 0; str[i] != 0; ++i)
    {
        if(str[i] == '9') out[6]++;
        else if(str[i] == '5') out[2]++;
        else out[str[i] - '0']++;
    }

    for(int i = 0; i < 10; ++i)
        if(in[i] != 0)
            out[i] /= in[i];
        else out[i] = 0;

    int min = 0;
    while(out[min] == 0) min++;

    if(min < 9)
    for(int i = 0; i < 10; ++i)
        if(out[i] != 0)
            min = out[i] < out[min] ? i : min;

    printf("%d", out[min]);
    return 0;
}


#include<stdio.h>
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	long long int fact[2500006];
	long long int i;
	fact[0] = 1;
	for (i = 1; i < 2500006; i++)
		fact[i] = fact[i - 1] * i % m;
	long long int ans = 0;
	for (i = 0; i < n; i++)
		ans = (ans + (n - i) * fact[i + 1] % m * fact[n - i] % m) % m;
	printf("%lld\n", ans);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define MX 1000000

int len;
char in[100];
int res;

void solve(int depth, int st, int sum){
  int i,j,k;

  if(depth==3){
    if(st!=len) return;
    if(res < sum) res = sum;
    return;
  }

  k = 0;
  REP(i,st,len){
    k = k * 10 + (in[i] - '0');
    if(k > MX) break;
    solve(depth+1, i+1, sum+k);
    if(in[st]=='0') break;
  }
}

int main(){
  int i,j,k;

  scanf("%s",in);
  len = strlen(in);

  res = -1;
  solve(0,0,0);

  printf("%d\n",res);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>

long long int k,i,j,max,min,S;

int main()
{
    int n,m,x,y;

    scanf("%d%d%lld%d%d",&n,&m,&k,&x,&y);

    if(n*m > k)
    {
           max = 1;
           min = 0;
           if((x-1)*m+y <= k)S = 1;
           else S = 0;
    }
    else if(n <= 2)
    {
         min = k/(m*n);
         max = (k%(m*n) == 0)?min:min + 1;

         if(max == min)S = max;
         else
         {
             if(n == 1)
             {
                  if(k%m >= y)S = max;
                  else S = min;
             }
             else
             {
                 j = k%(m*n);
                 if(j > m)
                 {
                            if(x == 2 && j-m >= y)S = max;
                            else S = min;
                 }
                 else
                 {
                     if(x == 1 && j >= y)S = max;
                     else S = min;
                 }
             }
         }
    }
    else
    {
        i = k/(m*(2*n-2));
        j = k%(m*(2*n-2));
        max = i*2;
        min = i;
        if(j == 0)
        {
             if(x == 1 || x == n)S = min;
             else S = max;
        }
        else
        {
            if(j <= m)
            {
                 if(x == 1)
                 {
                      if(y > j)S = min;
                      else S = min+1;
                 }
                 else if(x == n)S = min;
                 else S = max;
            }
            else if(j <= m*(n-1))
            {
                 max++;
                 if(x == 1)S = min+1;
                 else if(x == n)S = min;
                 else
                 {
                      if((x-1)*m+y <= j)S = max;
                      else S = max-1;
                 }
            }
            else if(j <= m*n)
            {
                 max++;
                 if(j == m*n)min++;
                 if(x == 1)S = i+1;
                 else if(x == n)
                 {
                      if(y <= j%m || j%m == 0)S = i+1;
                      else S = i;
                 }
                 else S = max;
            }
            else
            {
                max+=2;
                min++;
                if(x == 1)S = i+1;
                else if(x == n)S = i+1;
                else
                {
                    S = i*2+1;
                    j-=m*n;
                    if(j%m == 0)
                    {
                           if(x + j/m > (n-2))S++;
                    }
                    else
                    {
                        if(x + j/m > (n-1))S++;
                        else if(x + j/m == (n-1))
                        {
                             if(j%m >= y||j%m == 0)S++;
                        }
                    }
                }
            }
        }
    }

    printf("%lld %lld %lld\n",max,min,S);
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>

char pre[1010][100000];

char *strrev(char *s)
{
    char *real,*forward,temp;
    real=s;
    forward=s;
    while(*s)
        s++;
    while(forward<s)
    {
        temp = *(--s);
        *s = *forward;
        *forward++ = temp;
    }
    return real;
}

int main()
{
    int n,a,i,j,k,l,q,div,rem,rem1,div1,len1,len2,len3,num=0,p=0,count=0,plug=0,flag=0,found=0,keep;
    char arr[100000]="2",*brr,*crr,*drr;
    for(i=3; i<=1005; i++)
    {
        brr=calloc(100000,1);
        crr=calloc(100000,1);
        drr=calloc(100000,1);
        num=0,p=0,count=0,plug=0,flag=0,found=0;
        div=i;
        num=0,p=0;
        if(i<=9)
        {
            while(div)
            {
                rem=div%10;
                div=div/10;
                len1=strlen(arr);
                for(j=0; j<len1; j++)
                {
                    num=num+rem*(arr[j]-'0');
                    brr[p++]=(num%10)+'0';
                    num=num/10;
                }
                brr[p++]=num+'0';
                brr[p]='\0';
            }
        }
        else
        {
            count=1;
            plug=0;
            while(div)
            {
                p=0;
                rem=div%10;
                div=div/10;
                if(plug==0)
                {
                    len1=strlen(arr);
                    for(j=0; j<len1; j++)
                    {
                        num=num+rem*(arr[j]-'0');
                        brr[p++]=(num%10)+'0';
                        num=num/10;
                    }
                    if(num!=0)
                        brr[p++]=(num+'0');
                    else
                        brr[p++]='\0';
                    plug=1;
                }
                else
                {
                    len1=strlen(arr);
                    num=0;
                    for(j=0; j<len1; j++)
                    {
                        num=num+rem*(arr[j]-'0');
                        crr[p++]=(num%10)+'0';
                        num=num/10;
                    }
                    if(num!=0)
                        crr[p++]=(num+'0');
                    else
                        crr[p++]='\0';
                    flag=1;
                }
                if(flag==1)
                {
                q=l=count;
                len3=strlen(brr);
                rem1=div1=0;
                for(l; l<len3; l++)
                {
                    keep=((brr[l]-'0')+(crr[l-q]-'0'))+div1;
                    rem1=keep%10;
                    brr[l]=(rem1)+'0';
                    div1=keep/10;
                }
                len3=strlen(crr);
                for(l; l<=len3;  l++)
                    brr[l]=((crr[l-1]-'0')+div1)+'0';
                if(len3<l)
                    brr[l]=(div1+'0');
                count++;
                }
            }
            flag=0;
        }
        strcpy(arr,brr);
        strcpy(drr,brr);
        len2=strlen(drr);
        for(k=len2-1; k>=0; k--)
        {
            if(drr[k]!='0')
            {
                drr[k+1]='\0';
                break;
            }
        }
        strcpy(pre[i],strrev(drr));
    }
    while(scanf("%d",&n)==1)
    {
        if(n==0 || n==1)
            printf("1\n");
        else if(n==2)
            printf("2\n");
        else
            printf("%s\n",pre[n]);
    }
    return 0;
}


typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;
typedef signed long int __int64_t;
typedef unsigned long int __uint64_t;
typedef long int __quad_t;
typedef unsigned long int __u_quad_t;
typedef long int __intmax_t;
typedef unsigned long int __uintmax_t;
typedef unsigned long int __dev_t;
typedef unsigned int __uid_t;
typedef unsigned int __gid_t;
typedef unsigned long int __ino_t;
typedef unsigned long int __ino64_t;
typedef unsigned int __mode_t;
typedef unsigned long int __nlink_t;
typedef long int __off_t;
typedef long int __off64_t;
typedef int __pid_t;
typedef struct { int __val[2]; } __fsid_t;
typedef long int __clock_t;
typedef unsigned long int __rlim_t;
typedef unsigned long int __rlim64_t;
typedef unsigned int __id_t;
typedef long int __time_t;
typedef unsigned int __useconds_t;
typedef long int __suseconds_t;
typedef int __daddr_t;
typedef int __key_t;
typedef int __clockid_t;
typedef void * __timer_t;
typedef long int __blksize_t;
typedef long int __blkcnt_t;
typedef long int __blkcnt64_t;
typedef unsigned long int __fsblkcnt_t;
typedef unsigned long int __fsblkcnt64_t;
typedef unsigned long int __fsfilcnt_t;
typedef unsigned long int __fsfilcnt64_t;
typedef long int __fsword_t;
typedef long int __ssize_t;
typedef long int __syscall_slong_t;
typedef unsigned long int __syscall_ulong_t;
typedef __off64_t __loff_t;
typedef char *__caddr_t;
typedef long int __intptr_t;
typedef unsigned int __socklen_t;
typedef int __sig_atomic_t;
typedef __int8_t int8_t;
typedef __int16_t int16_t;
typedef __int32_t int32_t;
typedef __int64_t int64_t;
typedef __uint8_t uint8_t;
typedef __uint16_t uint16_t;
typedef __uint32_t uint32_t;
typedef __uint64_t uint64_t;
typedef signed char int_least8_t;
typedef short int int_least16_t;
typedef int int_least32_t;
typedef long int int_least64_t;
typedef unsigned char uint_least8_t;
typedef unsigned short int uint_least16_t;
typedef unsigned int uint_least32_t;
typedef unsigned long int uint_least64_t;
typedef signed char int_fast8_t;
typedef long int int_fast16_t;
typedef long int int_fast32_t;
typedef long int int_fast64_t;
typedef unsigned char uint_fast8_t;
typedef unsigned long int uint_fast16_t;
typedef unsigned long int uint_fast32_t;
typedef unsigned long int uint_fast64_t;
typedef long int intptr_t;
typedef unsigned long int uintptr_t;
typedef __intmax_t intmax_t;
typedef __uintmax_t uintmax_t;
typedef int __gwchar_t;

typedef struct
  {
    long int quot;
    long int rem;
  } imaxdiv_t;
extern intmax_t imaxabs (intmax_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
extern imaxdiv_t imaxdiv (intmax_t __numer, intmax_t __denom)
      __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
extern intmax_t strtoimax (const char *__restrict __nptr,
      char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ , __leaf__));
extern uintmax_t strtoumax (const char *__restrict __nptr,
       char ** __restrict __endptr, int __base) __attribute__ ((__nothrow__ , __leaf__));
extern intmax_t wcstoimax (const __gwchar_t *__restrict __nptr,
      __gwchar_t **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__ , __leaf__));
extern uintmax_t wcstoumax (const __gwchar_t *__restrict __nptr,
       __gwchar_t ** __restrict __endptr, int __base)
     __attribute__ ((__nothrow__ , __leaf__));

typedef long unsigned int size_t;
struct _IO_FILE;
typedef struct _IO_FILE __FILE;
struct _IO_FILE;
typedef struct _IO_FILE FILE;
typedef struct
{
  int __count;
  union
  {
    unsigned int __wch;
    char __wchb[4];
  } __value;
} __mbstate_t;
typedef struct
{
  __off_t __pos;
  __mbstate_t __state;
} _G_fpos_t;
typedef struct
{
  __off64_t __pos;
  __mbstate_t __state;
} _G_fpos64_t;
typedef __builtin_va_list __gnuc_va_list;
struct _IO_jump_t; struct _IO_FILE;
typedef void _IO_lock_t;
struct _IO_marker {
  struct _IO_marker *_next;
  struct _IO_FILE *_sbuf;
  int _pos;
};
enum __codecvt_result
{
  __codecvt_ok,
  __codecvt_partial,
  __codecvt_error,
  __codecvt_noconv
};
struct _IO_FILE {
  int _flags;
  char* _IO_read_ptr;
  char* _IO_read_end;
  char* _IO_read_base;
  char* _IO_write_base;
  char* _IO_write_ptr;
  char* _IO_write_end;
  char* _IO_buf_base;
  char* _IO_buf_end;
  char *_IO_save_base;
  char *_IO_backup_base;
  char *_IO_save_end;
  struct _IO_marker *_markers;
  struct _IO_FILE *_chain;
  int _fileno;
  int _flags2;
  __off_t _old_offset;
  unsigned short _cur_column;
  signed char _vtable_offset;
  char _shortbuf[1];
  _IO_lock_t *_lock;
  __off64_t _offset;
  void *__pad1;
  void *__pad2;
  void *__pad3;
  void *__pad4;
  size_t __pad5;
  int _mode;
  char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
};
typedef struct _IO_FILE _IO_FILE;
struct _IO_FILE_plus;
extern struct _IO_FILE_plus _IO_2_1_stdin_;
extern struct _IO_FILE_plus _IO_2_1_stdout_;
extern struct _IO_FILE_plus _IO_2_1_stderr_;
typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
typedef __ssize_t __io_write_fn (void *__cookie, const char *__buf,
     size_t __n);
typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w);
typedef int __io_close_fn (void *__cookie);
extern int __underflow (_IO_FILE *);
extern int __uflow (_IO_FILE *);
extern int __overflow (_IO_FILE *, int);
extern int _IO_getc (_IO_FILE *__fp);
extern int _IO_putc (int __c, _IO_FILE *__fp);
extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__ , __leaf__));
extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__ , __leaf__));
extern int _IO_peekc_locked (_IO_FILE *__fp);
extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
   __gnuc_va_list, int *__restrict);
extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
    __gnuc_va_list);
extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t);
extern size_t _IO_sgetn (_IO_FILE *, void *, size_t);
extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int);
extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int);
extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__));
typedef __gnuc_va_list va_list;
typedef __off_t off_t;
typedef __ssize_t ssize_t;
typedef _G_fpos_t fpos_t;
extern struct _IO_FILE *stdin;
extern struct _IO_FILE *stdout;
extern struct _IO_FILE *stderr;
extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__));
extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__));
extern int renameat (int __oldfd, const char *__old, int __newfd,
       const char *__new) __attribute__ ((__nothrow__ , __leaf__));
extern FILE *tmpfile (void) ;
extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ;
extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ;
extern char *tempnam (const char *__dir, const char *__pfx)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ;
extern int fclose (FILE *__stream);
extern int fflush (FILE *__stream);
extern int fflush_unlocked (FILE *__stream);
extern FILE *fopen (const char *__restrict __filename,
      const char *__restrict __modes) ;
extern FILE *freopen (const char *__restrict __filename,
        const char *__restrict __modes,
        FILE *__restrict __stream) ;
extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ;
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
  __attribute__ ((__nothrow__ , __leaf__)) ;
extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__));
extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
      int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__));
extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
         size_t __size) __attribute__ ((__nothrow__ , __leaf__));
extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int fprintf (FILE *__restrict __stream,
      const char *__restrict __format, ...);
extern int printf (const char *__restrict __format, ...);
extern int sprintf (char *__restrict __s,
      const char *__restrict __format, ...) __attribute__ ((__nothrow__));
extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
       __gnuc_va_list __arg);
extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
extern int vsprintf (char *__restrict __s, const char *__restrict __format,
       __gnuc_va_list __arg) __attribute__ ((__nothrow__));
extern int snprintf (char *__restrict __s, size_t __maxlen,
       const char *__restrict __format, ...)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4)));
extern int vsnprintf (char *__restrict __s, size_t __maxlen,
        const char *__restrict __format, __gnuc_va_list __arg)
     __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0)));
extern int vdprintf (int __fd, const char *__restrict __fmt,
       __gnuc_va_list __arg)
     __attribute__ ((__format__ (__printf__, 2, 0)));
extern int dprintf (int __fd, const char *__restrict __fmt, ...)
     __attribute__ ((__format__ (__printf__, 2, 3)));
extern int fscanf (FILE *__restrict __stream,
     const char *__restrict __format, ...) ;
extern int scanf (const char *__restrict __format, ...) ;
extern int sscanf (const char *__restrict __s,
     const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__));
extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf") ;
extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf") ;
extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__));
extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
      __gnuc_va_list __arg)
     __attribute__ ((__format__ (__scanf__, 2, 0))) ;
extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
     __attribute__ ((__format__ (__scanf__, 1, 0))) ;
extern int vsscanf (const char *__restrict __s,
      const char *__restrict __format, __gnuc_va_list __arg)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0)));
extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf")
     __attribute__ ((__format__ (__scanf__, 2, 0))) ;
extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf")
     __attribute__ ((__format__ (__scanf__, 1, 0))) ;
extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__))
     __attribute__ ((__format__ (__scanf__, 2, 0)));
extern int fgetc (FILE *__stream);
extern int getc (FILE *__stream);
extern int getchar (void);
extern int getc_unlocked (FILE *__stream);
extern int getchar_unlocked (void);
extern int fgetc_unlocked (FILE *__stream);
extern int fputc (int __c, FILE *__stream);
extern int putc (int __c, FILE *__stream);
extern int putchar (int __c);
extern int fputc_unlocked (int __c, FILE *__stream);
extern int putc_unlocked (int __c, FILE *__stream);
extern int putchar_unlocked (int __c);
extern int getw (FILE *__stream);
extern int putw (int __w, FILE *__stream);
extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
     ;
extern __ssize_t __getdelim (char **__restrict __lineptr,
          size_t *__restrict __n, int __delimiter,
          FILE *__restrict __stream) ;
extern __ssize_t getdelim (char **__restrict __lineptr,
        size_t *__restrict __n, int __delimiter,
        FILE *__restrict __stream) ;
extern __ssize_t getline (char **__restrict __lineptr,
       size_t *__restrict __n,
       FILE *__restrict __stream) ;
extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
extern int puts (const char *__s);
extern int ungetc (int __c, FILE *__stream);
extern size_t fread (void *__restrict __ptr, size_t __size,
       size_t __n, FILE *__restrict __stream) ;
extern size_t fwrite (const void *__restrict __ptr, size_t __size,
        size_t __n, FILE *__restrict __s);
extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
         size_t __n, FILE *__restrict __stream) ;
extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
          size_t __n, FILE *__restrict __stream);
extern int fseek (FILE *__stream, long int __off, int __whence);
extern long int ftell (FILE *__stream) ;
extern void rewind (FILE *__stream);
extern int fseeko (FILE *__stream, __off_t __off, int __whence);
extern __off_t ftello (FILE *__stream) ;
extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
extern int fsetpos (FILE *__stream, const fpos_t *__pos);
extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void perror (const char *__s);
extern int sys_nerr;
extern const char *const sys_errlist[];
extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern FILE *popen (const char *__command, const char *__modes) ;
extern int pclose (FILE *__stream);
extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__));
extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));

typedef int wchar_t;

typedef enum
{
  P_ALL,
  P_PID,
  P_PGID
} idtype_t;
typedef struct
  {
    int quot;
    int rem;
  } div_t;
typedef struct
  {
    long int quot;
    long int rem;
  } ldiv_t;
__extension__ typedef struct
  {
    long long int quot;
    long long int rem;
  } lldiv_t;
extern size_t __ctype_get_mb_cur_max (void) __attribute__ ((__nothrow__ , __leaf__)) ;
extern double atof (const char *__nptr)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;
extern int atoi (const char *__nptr)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;
extern long int atol (const char *__nptr)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;
__extension__ extern long long int atoll (const char *__nptr)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;
extern double strtod (const char *__restrict __nptr,
        char **__restrict __endptr)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern float strtof (const char *__restrict __nptr,
       char **__restrict __endptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern long double strtold (const char *__restrict __nptr,
       char **__restrict __endptr)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern long int strtol (const char *__restrict __nptr,
   char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern unsigned long int strtoul (const char *__restrict __nptr,
      char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
__extension__
extern long long int strtoq (const char *__restrict __nptr,
        char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
__extension__
extern unsigned long long int strtouq (const char *__restrict __nptr,
           char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
__extension__
extern long long int strtoll (const char *__restrict __nptr,
         char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
__extension__
extern unsigned long long int strtoull (const char *__restrict __nptr,
     char **__restrict __endptr, int __base)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern char *l64a (long int __n) __attribute__ ((__nothrow__ , __leaf__)) ;
extern long int a64l (const char *__s)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ;

typedef __u_char u_char;
typedef __u_short u_short;
typedef __u_int u_int;
typedef __u_long u_long;
typedef __quad_t quad_t;
typedef __u_quad_t u_quad_t;
typedef __fsid_t fsid_t;
typedef __loff_t loff_t;
typedef __ino_t ino_t;
typedef __dev_t dev_t;
typedef __gid_t gid_t;
typedef __mode_t mode_t;
typedef __nlink_t nlink_t;
typedef __uid_t uid_t;
typedef __pid_t pid_t;
typedef __id_t id_t;
typedef __daddr_t daddr_t;
typedef __caddr_t caddr_t;
typedef __key_t key_t;
typedef __clock_t clock_t;
typedef __clockid_t clockid_t;
typedef __time_t time_t;
typedef __timer_t timer_t;
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__)));
typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__)));
typedef int register_t __attribute__ ((__mode__ (__word__)));
static __inline unsigned int
__bswap_32 (unsigned int __bsx)
{
  return __builtin_bswap32 (__bsx);
}
static __inline __uint64_t
__bswap_64 (__uint64_t __bsx)
{
  return __builtin_bswap64 (__bsx);
}
static __inline __uint16_t
__uint16_identity (__uint16_t __x)
{
  return __x;
}
static __inline __uint32_t
__uint32_identity (__uint32_t __x)
{
  return __x;
}
static __inline __uint64_t
__uint64_identity (__uint64_t __x)
{
  return __x;
}
typedef struct
{
  unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
} __sigset_t;
typedef __sigset_t sigset_t;
struct timeval
{
  __time_t tv_sec;
  __suseconds_t tv_usec;
};
struct timespec
{
  __time_t tv_sec;
  __syscall_slong_t tv_nsec;
};
typedef __suseconds_t suseconds_t;
typedef long int __fd_mask;
typedef struct
  {
    __fd_mask __fds_bits[1024 / (8 * (int) sizeof (__fd_mask))];
  } fd_set;
typedef __fd_mask fd_mask;

extern int select (int __nfds, fd_set *__restrict __readfds,
     fd_set *__restrict __writefds,
     fd_set *__restrict __exceptfds,
     struct timeval *__restrict __timeout);
extern int pselect (int __nfds, fd_set *__restrict __readfds,
      fd_set *__restrict __writefds,
      fd_set *__restrict __exceptfds,
      const struct timespec *__restrict __timeout,
      const __sigset_t *__restrict __sigmask);

extern unsigned int gnu_dev_major (__dev_t __dev) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
extern unsigned int gnu_dev_minor (__dev_t __dev) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
extern __dev_t gnu_dev_makedev (unsigned int __major, unsigned int __minor) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));

typedef __blksize_t blksize_t;
typedef __blkcnt_t blkcnt_t;
typedef __fsblkcnt_t fsblkcnt_t;
typedef __fsfilcnt_t fsfilcnt_t;
struct __pthread_rwlock_arch_t
{
  unsigned int __readers;
  unsigned int __writers;
  unsigned int __wrphase_futex;
  unsigned int __writers_futex;
  unsigned int __pad3;
  unsigned int __pad4;
  int __cur_writer;
  int __shared;
  signed char __rwelision;
  unsigned char __pad1[7];
  unsigned long int __pad2;
  unsigned int __flags;
};
typedef struct __pthread_internal_list
{
  struct __pthread_internal_list *__prev;
  struct __pthread_internal_list *__next;
} __pthread_list_t;
struct __pthread_mutex_s
{
  int __lock ;
  unsigned int __count;
  int __owner;
  unsigned int __nusers;
  int __kind;

  short __spins; short __elision;
  __pthread_list_t __list;

};
struct __pthread_cond_s
{
  __extension__ union
  {
    __extension__ unsigned long long int __wseq;
    struct
    {
      unsigned int __low;
      unsigned int __high;
    } __wseq32;
  };
  __extension__ union
  {
    __extension__ unsigned long long int __g1_start;
    struct
    {
      unsigned int __low;
      unsigned int __high;
    } __g1_start32;
  };
  unsigned int __g_refs[2] ;
  unsigned int __g_size[2];
  unsigned int __g1_orig_size;
  unsigned int __wrefs;
  unsigned int __g_signals[2];
};
typedef unsigned long int pthread_t;
typedef union
{
  char __size[4];
  int __align;
} pthread_mutexattr_t;
typedef union
{
  char __size[4];
  int __align;
} pthread_condattr_t;
typedef unsigned int pthread_key_t;
typedef int pthread_once_t;
union pthread_attr_t
{
  char __size[56];
  long int __align;
};
typedef union pthread_attr_t pthread_attr_t;
typedef union
{
  struct __pthread_mutex_s __data;
  char __size[40];
  long int __align;
} pthread_mutex_t;
typedef union
{
  struct __pthread_cond_s __data;
  char __size[48];
  __extension__ long long int __align;
} pthread_cond_t;
typedef union
{
  struct __pthread_rwlock_arch_t __data;
  char __size[56];
  long int __align;
} pthread_rwlock_t;
typedef union
{
  char __size[8];
  long int __align;
} pthread_rwlockattr_t;
typedef volatile int pthread_spinlock_t;
typedef union
{
  char __size[32];
  long int __align;
} pthread_barrier_t;
typedef union
{
  char __size[4];
  int __align;
} pthread_barrierattr_t;

extern long int random (void) __attribute__ ((__nothrow__ , __leaf__));
extern void srandom (unsigned int __seed) __attribute__ ((__nothrow__ , __leaf__));
extern char *initstate (unsigned int __seed, char *__statebuf,
   size_t __statelen) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2)));
extern char *setstate (char *__statebuf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
struct random_data
  {
    int32_t *fptr;
    int32_t *rptr;
    int32_t *state;
    int rand_type;
    int rand_deg;
    int rand_sep;
    int32_t *end_ptr;
  };
extern int random_r (struct random_data *__restrict __buf,
       int32_t *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int srandom_r (unsigned int __seed, struct random_data *__buf)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2)));
extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
   size_t __statelen,
   struct random_data *__restrict __buf)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 4)));
extern int setstate_r (char *__restrict __statebuf,
         struct random_data *__restrict __buf)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int rand (void) __attribute__ ((__nothrow__ , __leaf__));
extern void srand (unsigned int __seed) __attribute__ ((__nothrow__ , __leaf__));
extern int rand_r (unsigned int *__seed) __attribute__ ((__nothrow__ , __leaf__));
extern double drand48 (void) __attribute__ ((__nothrow__ , __leaf__));
extern double erand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern long int lrand48 (void) __attribute__ ((__nothrow__ , __leaf__));
extern long int nrand48 (unsigned short int __xsubi[3])
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern long int mrand48 (void) __attribute__ ((__nothrow__ , __leaf__));
extern long int jrand48 (unsigned short int __xsubi[3])
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern void srand48 (long int __seedval) __attribute__ ((__nothrow__ , __leaf__));
extern unsigned short int *seed48 (unsigned short int __seed16v[3])
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern void lcong48 (unsigned short int __param[7]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
struct drand48_data
  {
    unsigned short int __x[3];
    unsigned short int __old_x[3];
    unsigned short int __c;
    unsigned short int __init;
    __extension__ unsigned long long int __a;
  };
extern int drand48_r (struct drand48_data *__restrict __buffer,
        double *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int erand48_r (unsigned short int __xsubi[3],
        struct drand48_data *__restrict __buffer,
        double *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int lrand48_r (struct drand48_data *__restrict __buffer,
        long int *__restrict __result)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int nrand48_r (unsigned short int __xsubi[3],
        struct drand48_data *__restrict __buffer,
        long int *__restrict __result)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int mrand48_r (struct drand48_data *__restrict __buffer,
        long int *__restrict __result)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int jrand48_r (unsigned short int __xsubi[3],
        struct drand48_data *__restrict __buffer,
        long int *__restrict __result)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2)));
extern int seed48_r (unsigned short int __seed16v[3],
       struct drand48_data *__buffer) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int lcong48_r (unsigned short int __param[7],
        struct drand48_data *__buffer)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern void *malloc (size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ;
extern void *calloc (size_t __nmemb, size_t __size)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ;
extern void *realloc (void *__ptr, size_t __size)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__));
extern void free (void *__ptr) __attribute__ ((__nothrow__ , __leaf__));

extern void *alloca (size_t __size) __attribute__ ((__nothrow__ , __leaf__));

extern void *valloc (size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ;
extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ;
extern void *aligned_alloc (size_t __alignment, size_t __size)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__alloc_size__ (2))) ;
extern void abort (void) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__));
extern int atexit (void (*__func) (void)) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int at_quick_exit (void (*__func) (void)) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern void exit (int __status) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__));
extern void quick_exit (int __status) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__));
extern void _Exit (int __status) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__));
extern char *getenv (const char *__name) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ;
extern int putenv (char *__string) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int setenv (const char *__name, const char *__value, int __replace)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2)));
extern int unsetenv (const char *__name) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int clearenv (void) __attribute__ ((__nothrow__ , __leaf__));
extern char *mktemp (char *__template) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1))) ;
extern int mkstemps (char *__template, int __suffixlen) __attribute__ ((__nonnull__ (1))) ;
extern char *mkdtemp (char *__template) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ;
extern int system (const char *__command) ;
extern char *realpath (const char *__restrict __name,
         char *__restrict __resolved) __attribute__ ((__nothrow__ , __leaf__)) ;
typedef int (*__compar_fn_t) (const void *, const void *);
extern void *bsearch (const void *__key, const void *__base,
        size_t __nmemb, size_t __size, __compar_fn_t __compar)
     __attribute__ ((__nonnull__ (1, 2, 5))) ;
extern void qsort (void *__base, size_t __nmemb, size_t __size,
     __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
extern int abs (int __x) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ;
extern long int labs (long int __x) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ;
__extension__ extern long long int llabs (long long int __x)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ;
extern div_t div (int __numer, int __denom)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ;
extern ldiv_t ldiv (long int __numer, long int __denom)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ;
__extension__ extern lldiv_t lldiv (long long int __numer,
        long long int __denom)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ;
extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
     int *__restrict __sign) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))) ;
extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
     int *__restrict __sign) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))) ;
extern char *gcvt (double __value, int __ndigit, char *__buf)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))) ;
extern char *qecvt (long double __value, int __ndigit,
      int *__restrict __decpt, int *__restrict __sign)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))) ;
extern char *qfcvt (long double __value, int __ndigit,
      int *__restrict __decpt, int *__restrict __sign)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))) ;
extern char *qgcvt (long double __value, int __ndigit, char *__buf)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))) ;
extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
     int *__restrict __sign, char *__restrict __buf,
     size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4, 5)));
extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
     int *__restrict __sign, char *__restrict __buf,
     size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4, 5)));
extern int qecvt_r (long double __value, int __ndigit,
      int *__restrict __decpt, int *__restrict __sign,
      char *__restrict __buf, size_t __len)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4, 5)));
extern int qfcvt_r (long double __value, int __ndigit,
      int *__restrict __decpt, int *__restrict __sign,
      char *__restrict __buf, size_t __len)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4, 5)));
extern int mblen (const char *__s, size_t __n) __attribute__ ((__nothrow__ , __leaf__));
extern int mbtowc (wchar_t *__restrict __pwc,
     const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__ , __leaf__));
extern int wctomb (char *__s, wchar_t __wchar) __attribute__ ((__nothrow__ , __leaf__));
extern size_t mbstowcs (wchar_t *__restrict __pwcs,
   const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__ , __leaf__));
extern size_t wcstombs (char *__restrict __s,
   const wchar_t *__restrict __pwcs, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__));
extern int rpmatch (const char *__response) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ;
extern int getsubopt (char **__restrict __optionp,
        char *const *__restrict __tokens,
        char **__restrict __valuep)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2, 3))) ;
extern int getloadavg (double __loadavg[], int __nelem)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));

extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
       size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern void *memmove (void *__dest, const void *__src, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern void *memccpy (void *__restrict __dest, const void *__restrict __src,
        int __c, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern void *memset (void *__s, int __c, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern int memcmp (const void *__s1, const void *__s2, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern void *memchr (const void *__s, int __c, size_t __n)
      __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strncpy (char *__restrict __dest,
        const char *__restrict __src, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strcat (char *__restrict __dest, const char *__restrict __src)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strncat (char *__restrict __dest, const char *__restrict __src,
        size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern int strcmp (const char *__s1, const char *__s2)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern int strncmp (const char *__s1, const char *__s2, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern int strcoll (const char *__s1, const char *__s2)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern size_t strxfrm (char *__restrict __dest,
         const char *__restrict __src, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2)));
struct __locale_struct
{
  struct __locale_data *__locales[13];
  const unsigned short int *__ctype_b;
  const int *__ctype_tolower;
  const int *__ctype_toupper;
  const char *__names[13];
};
typedef struct __locale_struct *__locale_t;
typedef __locale_t locale_t;
extern int strcoll_l (const char *__s1, const char *__s2, locale_t __l)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3)));
extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n,
    locale_t __l) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 4)));
extern char *strdup (const char *__s)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1)));
extern char *strndup (const char *__string, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1)));
extern char *strchr (const char *__s, int __c)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern char *strrchr (const char *__s, int __c)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern size_t strcspn (const char *__s, const char *__reject)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern size_t strspn (const char *__s, const char *__accept)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strpbrk (const char *__s, const char *__accept)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strstr (const char *__haystack, const char *__needle)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strtok (char *__restrict __s, const char *__restrict __delim)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2)));
extern char *__strtok_r (char *__restrict __s,
    const char *__restrict __delim,
    char **__restrict __save_ptr)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3)));
extern char *strtok_r (char *__restrict __s, const char *__restrict __delim,
         char **__restrict __save_ptr)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3)));
extern size_t strlen (const char *__s)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern size_t strnlen (const char *__string, size_t __maxlen)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern char *strerror (int __errnum) __attribute__ ((__nothrow__ , __leaf__));
extern int strerror_r (int __errnum, char *__buf, size_t __buflen) __asm__ ("" "__xpg_strerror_r") __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2)));
extern char *strerror_l (int __errnum, locale_t __l) __attribute__ ((__nothrow__ , __leaf__));

extern int bcmp (const void *__s1, const void *__s2, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern void bcopy (const void *__src, void *__dest, size_t __n)
  __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern void bzero (void *__s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern char *index (const char *__s, int __c)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern char *rindex (const char *__s, int __c)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
extern int ffs (int __i) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
extern int ffsl (long int __l) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
__extension__ extern int ffsll (long long int __ll)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
extern int strcasecmp (const char *__s1, const char *__s2)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern int strcasecmp_l (const char *__s1, const char *__s2, locale_t __loc)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3)));
extern int strncasecmp_l (const char *__s1, const char *__s2,
     size_t __n, locale_t __loc)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 4)));

extern void explicit_bzero (void *__s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
extern char *strsep (char **__restrict __stringp,
       const char *__restrict __delim)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *strsignal (int __sig) __attribute__ ((__nothrow__ , __leaf__));
extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *stpcpy (char *__restrict __dest, const char *__restrict __src)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *__stpncpy (char *__restrict __dest,
   const char *__restrict __src, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));
extern char *stpncpy (char *__restrict __dest,
        const char *__restrict __src, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2)));

static struct cmc_alloc_node
{
    void *(*malloc)(size_t);
    void *(*calloc)(size_t, size_t);
    void *(*realloc)(void *, size_t);
    void (*free)(void *);
} cmc_alloc_node_default = { malloc, calloc, realloc, free };
struct cmc_callbacks
{
    void (*create)(void);
    void (*read)(void);
    void (*update)(void);
    void (*delete)(void);
    void (*resize)(void);
};
enum cmc_flags
{
    CMC_FLAG_OK = 0,
    CMC_FLAG_ALLOC = 1,
    CMC_FLAG_EMPTY = 2,
    CMC_FLAG_NOT_FOUND = 3,
    CMC_FLAG_INVALID = 4,
    CMC_FLAG_RANGE = 5,
    CMC_FLAG_DUPLICATE = 6,
    CMC_FLAG_ERROR = 7,
    CMC_FLAG_THREAD = 8,
    CMC_FLAG_MUTEX = 9
};
__attribute__((__unused__)) static const char *cmc_flags_to_str[10] = { "OK", "ALLOC", "EMPTY", "NOT_FOUND", "INVALID",
                                                       "RANGE", "DUPLICATE", "ERROR", "THREAD", "MUTEX" };
struct fragment {
 long len;
 long b;
};
static inline int fragment_compare(struct fragment f1, struct fragment f2) {
 if (f1.len < f2.len) {
  return -1;
 } else if (f1.len > f2.len) {
  return 1;
 }
 return f1.b - f2.b;
}
C_MACRO_COLLECTIONS_ALL(CMC, TREESET, (ls, lset, , , long))
C_MACRO_COLLECTIONS_ALL(CMC, TREESET, (fs, fset, , , struct fragment));
C_MACRO_COLLECTIONS_ALL(CMC, TREEMAP, (tm, treemap, , long, long))
long moves(struct lset *piles, struct fset *fragments) {
 long max_pile, min_pile;
 ls_max(piles, &max_pile);
 ls_min(piles, &min_pile);
 struct fragment max_frag;
 fs_max(fragments, &max_frag);
 return max_pile - min_pile - max_frag.len;
}
static struct lset_node* lset_impl_get_node(struct lset * _set_, long value) {
    struct lset_node *scan = _set_->root;
    while (scan != ((void *)0)) {
        if (_set_->f_val->cmp(scan->value, value) > 0)
            scan = scan->left;
        else if (_set_->f_val->cmp(scan->value, value) < 0)
            scan = scan->right;
        else
            return scan;
    }
    return ((void *)0);
}
static struct lset_node* lset_impl_get_node_gte(struct lset_node *nd, long value) {
 if (nd == ((void *)0) || nd->value == value) {
  return nd;
 }
 if (nd->value < value) {
  return lset_impl_get_node_gte(nd->right, value);
 }
 struct lset_node *nd_gte = lset_impl_get_node_gte(nd->left, value);
 if (nd_gte) {
  return nd_gte;
 }
 return nd;
}
static struct lset_node* lset_impl_tree_min(struct lset_node* nd) {
 if (nd->left != ((void *)0)) {
  return lset_impl_tree_min(nd->left);
 }
 return nd;
}
static struct lset_node* lset_impl_tree_max(struct lset_node* nd) {
 if (nd->right != ((void *)0)) {
  return lset_impl_tree_max(nd->right);
 }
 return nd;
}
static struct lset_node* lset_impl_tree_predecessor(struct lset_node* nd) {
 if (nd->left != ((void *)0)) {
  return lset_impl_tree_max(nd->left);
 }
 struct lset_node* par = nd->parent;
 while (par != ((void *)0) && nd == par->left) {
  nd = par;
  par = par->parent;
 }
 return par;
}
static struct lset_node* lset_impl_tree_successor(struct lset_node* nd) {
 if (nd->right != ((void *)0)) {
  return lset_impl_tree_min(nd->right);
 }
 struct lset_node* par = nd->parent;
 while (par != ((void *)0) && nd == par->right) {
  nd = par;
  par = par->right;
 }
 return par;
}
int main() {
 struct lset *piles = ls_new(&(struct lset_fval){
  .cmp = cmc_i64_cmp
 });
 int n, q;
 scanf("%d%d", &n, &q);
 for (int i = 0; i < n; ++i) {
  long pile;
  scanf("%ld", &pile);
  ls_insert(piles, pile);
 }
 struct fset *fragments = fs_new(&(struct fset_fval){
  .cmp = fragment_compare
 });
 {
  long b, e;
  struct lset_iter it = ls_iter_start(piles);
  for (;!ls_iter_at_end(&it); ls_iter_next(&it)) {
   if (ls_iter_at_start(&it)) {
    b = ls_iter_value(&it);
   } else {
    e = ls_iter_value(&it);
    fs_insert(fragments, (struct fragment){e - b, b});
    b = e;
   }
  }
 }
 printf("%ld\n", moves(piles, fragments));
 for (int i = 0; i < q; ++i) {
  long t, x;
  scanf("%ld%ld", &t, &x);
  if (t == 0) {
  }
 }
 return 0;
}