#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int a[1000],b[1000],c[10],time=0,num=0;
void func(int m)
{
    if(c[m])
    {
        time++;
        c[m]--;
    }
    else if(m==9)return;
    else func(m+1);
}
void fund(int m)
{
    if(c[m])
    {
        c[m]--;
    }
    else if(m==9)num++;
    else fund(m+1);
}
main()
{
    memset(c,0,sizeof(c));
    int n,i,x,y;
    scanf("%d%d%d",&n,&x,&y);
    for(i=n-1;i>=0;i--)
    {
        a[i]=x%10;
        x=x/10;
        b[i]=y%10;
        y=y/10;
    }
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0; i<n; i++)
    {
        if(a[i]<9)func(a[i]+1);
        else func(a[i]);
    }
    memset(c,0,sizeof(c));
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0;i<n;i++)fund(a[i]);
    printf("%d\n%d",num,time);
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int a[1010],b[1010],c[10],i,time=0,num=0;
void func(int m,int i)
{
    if(a[i]<9&&c[m])
    {
        time++;
        c[m]--;
    }
    else if(a[i]==9||m==9)return;
    else func(m+1,i);
}
void fund(int m)
{
    if(c[m])
    {
        c[m]--;
    }
    else if(m==9)num++;
    else fund(m+1);
}
main()
{
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    for(i=n-1;i>=0;i--)
    {
        a[i]=x%10;
        x=x/10;
        b[i]=y%10;
        y=y/10;
    }
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0; i<n; i++)func(a[i]+1,i);
    memset(c,0,sizeof(c));
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0;i<n;i++)fund(a[i]);
    printf("%d\n%d",num,time);
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int a[1000],b[1000],c[10],i,time=0,num=0;
void func(int m,int i)
{
    if(a[i]<9&&c[m])
    {
        time++;
        c[m]--;
    }
    else if(a[i]==9||m==9)return;
    else func(m+1,i);
}
void fund(int m)
{
    if(c[m])
    {
        c[m]--;
    }
    else if(m==9)num++;
    else fund(m+1);
}
main()
{
    memset(c,0,sizeof(c));
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    for(i=n-1;i>=0;i--)
    {
        a[i]=x%10;
        x=x/10;
        b[i]=y%10;
        y=y/10;
    }
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0; i<n; i++)func(a[i]+1,i);
    memset(c,0,sizeof(c));
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0;i<n;i++)fund(a[i]);
    printf("%d\n%d",num,time);
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int a[1000],b[1000],c[10],time=0,num=0;
void func(int m)
{
    if(c[m])
    {
        time++;
        c[m]--;
    }
    else if(m==9)return;
    else func(m+1);
}
void fund(int m)
{
    if(c[m])
    {
        c[m]--;
    }
    else if(m==9)num++;
    else fund(m+1);
}
main()
{
    memset(c,0,sizeof(c));
    int n,i,x,y;
    scanf("%d%d%d",&n,&x,&y);
    for(i=n-1;i>=0;i--)
    {
        a[i]=x%10;
        x=x/10;
        b[i]=y%10;
        y=y/10;
    }
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0; i<n; i++)func(a[i]+1);
    memset(c,0,sizeof(c));
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0;i<n;i++)fund(a[i]);
    printf("%d\n%d",num,time);
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int a[1000],b[1000],c[10],i,time=0,num=0;
void func(int m,int i)
{
    if(a[i]<9&&c[m])
    {
        time++;
        c[m]--;
    }
    else if(a[i]==9)return;
    else func(m+1,i);
}
void fund(int m)
{
    if(c[m])
    {
        c[m]--;
    }
    else if(m==9)num++;
    else fund(m+1);
}
main()
{
    memset(c,0,sizeof(c));
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    for(i=n-1;i>=0;i--)
    {
        a[i]=x%10;
        x=x/10;
        b[i]=y%10;
        y=y/10;
    }
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0; i<n; i++)func(a[i]+1,i);
    memset(c,0,sizeof(c));
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0;i<n;i++)fund(a[i]);
    printf("%d\n%d",num,time);
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int a[1010],b[1010],c[10],i,time=0,num=0;
void func(int m,int i)
{
    if(a[i]<9&&c[m])
    {
        time++;
        c[m]--;
    }
    else if(a[i]==9||m==9)return;
    else func(m+1,i);
}
void fund(int m)
{
    if(c[m])
    {
        c[m]--;
    }
    else if(m==9)num++;
    else fund(m+1);
}
main()
{
    memset(c,0,sizeof(c));
    int n;
    char x[1001],y[1001];
    scanf("%d\n%s\n%s",&n,&x,&y);
    for(i=0;i<n;i++)
    {
        a[i]=x[i]-'0';
        b[i]=y[i]-'0';
    }
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0; i<n; i++)func(a[i]+1,i);
    memset(c,0,sizeof(c));
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0;i<n;i++)fund(a[i]);
    printf("%d\n%d",num,time);
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int a[1000],b[1000],c[10],i,time=0,num=0;
void func(int m)
{
    if(m!=9&&c[m])
    {
        time++;
        c[m]--;
    }
    else if(m==9)return;
    else func(m+1);
}
void fund(int m)
{
    if(c[m])
    {
        c[m]--;
    }
    else if(m==9)num++;
    else fund(m+1);
}
main()
{
    memset(c,0,sizeof(c));
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    for(i=n-1;i>=0;i--)
    {
        a[i]=x%10;
        x=x/10;
        b[i]=y%10;
        y=y/10;
    }
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0; i<n; i++)
    {
        if(a[i]<9)func(a[i]+1);
        else func(a[i]);
    }
    memset(c,0,sizeof(c));
    for(i=0; i<n; i++)c[b[i]]++;
    for(i=0;i<n;i++)fund(a[i]);
    printf("%d\n%d",num,time);
}


/*
   Sachin Chandani
   IIIT Hyderabad
 */

#include<stdio.h>
#include<limits.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
typedef long long int ll;
#define INF INT_MAX
int min(int a,int b);
void swap(int *a,int *b);
void swap(int *a,int *b)
{
	int temp=*a;
	*a=*b;
	*b=temp;
}
int cmp(const void *a,const void *b)
{
	return(*(int*)a-*(int*)b);

}
int min(int a,int b)
{
	return(a>b?b:a);
}

int main()
{
	int n;
	scanf("%d",&n);
	char s1[1005],s2[1005];
	int  I[1005],II[1005],III[1005],IV[1005];
	scanf("%s%s",s1,s2);
	for(int i=0;i<n;i+=1)
	{
		I[i]=III[i]=s1[i]-'0';
		II[i]=IV[i]=s2[i]-'0';
	}
	qsort(I,n,sizeof(int),cmp);
	qsort(II,n,sizeof(int),cmp);
	qsort(III,n,sizeof(int),cmp);
	qsort(IV,n,sizeof(int),cmp);
	int ans1=0,ans2=0;
	for(int i=0;i<n;i++)
	{
		bool flag=false;
		for(int j=0;j<n;j+=1)
		{
			if(II[j]>=I[i]){flag=true;II[j]=-INT_MAX;break;}
		}
		if(flag==false) ans1++;
	}
	printf("%d\n",ans1);
	for(int i=0;i<n;i++)
	{
		bool flag=false;
		for(int j=0;j<n;j++)
		{
			if(IV[j]>III[i]){flag=true;IV[j]=-INT_MAX;break;}
		}
		if(flag==true) ans2++;
	}
	printf("%d\n",ans2);

	return 0;
}


#include <stdio.h>

void printarray ( char arr[] , int n){

	int i;

	for ( i = 0 ; i < n ; i++) printf("%c", arr[i]);

	printf("\n");
}

void min_mor( int n , char sher[] , char mor[]){

	int i , j , ans = 0;

	for ( i = 0 ; i < n ; i++){

		for ( j = 0 ; j < n ; j++) {

			if( mor[j] != 'A' && ( mor[j] - '0' >= sher[i] - '0') ){
				ans++;

				int k = j;

				// printf("%d\n", k);

				mor[k ] = 'A';

				// printf(" for %c# ", sher[i] );
				// printarray( mor , n );

				break;
			}

		}

		if( j == n ) {
			int k = 0;
			while (mor[k] == 'A'){
				k++;
			}

			mor[ k ] = 'A';

			// printf(" for %c# lost ", sher[i] );
			// printarray( mor , n );
		}

	}

	// printf("%d\n", ans);
	printf("%d\n", n - ans);
}

void max_sher( int n , char sher[] , char mor[]){

	int i , j , ans = 0;

	for ( i = 0 ; i < n ; i++){

		for ( j = 0 ; j < n ; j++) {

			if( mor[j] != 'A' && ( mor[j] - '0' > sher[i] - '0') ){
				ans++;

				int k = j;

				// printf("%d\n", k);

				mor[k ] = 'A';

				// printf(" for %c# ", sher[i] );
				// printarray( mor , n );

				break;
			}

		}

		if( j == n ) {
			int k = 0;
			while (mor[k] == 'A'){
				k++;
			}

			mor[ k ] = 'A';

			// printf(" for %c# lost ", sher[i] );
			// printarray( mor , n );
		}

	}

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

}

void merge( char arr[], int l, int m, int r ) {

    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    char L[n1], R[n2];

    for (i = 0; i < n1; i++)    L[i] = arr[l + i];

    for (j = 0; j < n2; j++)    R[j] = arr[m + 1+ j];

    i = 0;
    j = 0;
    k = l;

    while (i < n1 && j < n2) {

        if (L[i] - '0' <= R[j] - '0'){

            arr[k] = L[i];
            i++;
        }
        else{

            arr[k] = R[j];
            j++;
        }

        k++;
    }

    while (i < n1){

        arr[k] = L[i];

        i++;
        k++;
    }

    while (j < n2) {

        arr[k] = R[j];
        j++;
        k++;
    }
}

void sort(char arr[], int l, int r)
{
   if (l < r)
   {
      int m = l+(r-l)/2; //Same as (l+r)/2 but avoids overflow for large l & h
      sort(arr, l, m);
      sort(arr, m+1, r);
      merge(arr, l, m, r);
   }
}

int main(){

	int n;

	scanf("%d" , &n );

	char sher[n], mor[n];

	int i;

	scanf("%s", sher);

	scanf("%s", mor);

	sort ( mor , 0 , n - 1 );

	printarray ( mor , n);

	char mor2[n];

	for ( i = 0 ; i < n ; i++) mor2[i] = mor[i];

	min_mor ( n , sher , mor );

	max_sher ( n , sher , mor2 );

	return 0;

}


#include <stdio.h>

void printarray ( char arr[] , int n){

	int i;

	for ( i = 0 ; i < n ; i++) printf("%c", arr[i]);

	printf("\n");
}

void min_mor( int n , char sher[] , char mor[]){

	int i , j , ans = 0;

	for ( i = 0 ; i < n ; i++){

		for ( j = 0 ; j < n ; j++) {

			if( mor[j] != 'A' && ( mor[j] - '0' >= sher[i] - '0') ){
				ans++;

				int k = j;

				// printf("%d\n", k);

				mor[k ] = 'A';

				// printf(" for %c# ", sher[i] );
				// printarray( mor , n );

				break;
			}

		}

		if( j == n ) {
			int k = 0;
			while (mor[k] == 'A'){
				k++;
			}

			mor[ k ] = 'A';

			// printf(" for %c# lost ", sher[i] );
			// printarray( mor , n );
		}

	}

	// printf("%d\n", ans);
	printf("%d\n", n - ans);
}

void max_sher( int n , char sher[] , char mor[]){

	int i , j , ans = 0;

	for ( i = 0 ; i < n ; i++){

		for ( j = 0 ; j < n ; j++) {

			if( mor[j] != 'A' && ( mor[j] - '0' > sher[i] - '0') ){
				ans++;

				int k = j;

				// printf("%d\n", k);

				mor[k ] = 'A';

				// printf(" for %c# ", sher[i] );
				// printarray( mor , n );

				break;
			}

		}

		if( j == n ) {
			int k = 0;
			while (mor[k] == 'A'){
				k++;
			}

			mor[ k ] = 'A';

			// printf(" for %c# lost ", sher[i] );
			// printarray( mor , n );
		}

	}

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

}

void merge( char arr[], int l, int m, int r ) {

    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    char L[n1], R[n2];

    for (i = 0; i < n1; i++)    L[i] = arr[l + i];

    for (j = 0; j < n2; j++)    R[j] = arr[m + 1+ j];

    i = 0;
    j = 0;
    k = l;

    while (i < n1 && j < n2) {

        if (L[i] - '0' <= R[j] - '0'){

            arr[k] = L[i];
            i++;
        }
        else{

            arr[k] = R[j];
            j++;
        }

        k++;
    }

    while (i < n1){

        arr[k] = L[i];

        i++;
        k++;
    }

    while (j < n2) {

        arr[k] = R[j];
        j++;
        k++;
    }
}

void sort(char arr[], int l, int r)
{
   if (l < r)
   {
      int m = l+(r-l)/2; //Same as (l+r)/2 but avoids overflow for large l & h
      sort(arr, l, m);
      sort(arr, m+1, r);
      merge(arr, l, m, r);
   }
}

int main(){

	int n;

	scanf("%d" , &n );

	char sher[n], mor[n];

	int i;

	scanf("%s", sher);

	scanf("%s", mor);

	sort ( mor , 0 , n - 1 );

	// printarray ( mor , n);

	char mor2[n];

	for ( i = 0 ; i < n ; i++) mor2[i] = mor[i];

	min_mor ( n , sher , mor );

	max_sher ( n , sher , mor2 );

	return 0;

}


#include<stdio.h>
#include<stdlib.h>
int cmp(void const *a,void const *b){
	return *(int*)a-*(int*)b;
}
main(){
	int i,j,k;
	int l,a[2000],b[2000];
	int min,max;
	char s1[2000],s2[2000];
	while(scanf("%d\n",&l)!=EOF){
		gets(s1);gets(s2);
		for(i=0;i<l;i++){
			a[i]=s1[i]-'0';
			b[i]=s2[i]-'0';
		}
		qsort(a,l,sizeof(int),cmp);
		qsort(b,l,sizeof(int),cmp);
		max=0;min=0;
		for(i=0,k=0;i<l;i++){
			for(j=k;j<l;j++){
				if(b[j]>a[i]){
					k=j;
					max++;
					break;
				}
			}
		}
		for(k=l-1,i=l-1;i>=0;i--){
			for(j=k;j>=0;j--){
				if(a[j]<=b[i]){
					k=j;
					min++;
					break;
				}
			}
		}
		min=l-min;
		printf("%d\n%d\n",min,max);
	}
}


#include<stdio.h>
#include<stdlib.h>
int cmp(void const *a,void const *b){
	return *(int*)a-*(int*)b;
}
main(){
	int i,j,k;
	int l,a[2000],b[2000];
	int min,max;
	char s1[2000],s2[2000];
	while(scanf("%d\n",&l)!=EOF){
		gets(s1);gets(s2);
		for(i=0;i<l;i++){
			a[i]=s1[i]-'0';
			b[i]=s2[i]-'0';
		}
		qsort(a,l,sizeof(int),cmp);
		qsort(b,l,sizeof(int),cmp);
		max=0;min=0;
		for(i=0,k=0;i<l;i++){
			for(j=k;j<l;j++){
				if(b[j]>a[i]){
					k=j+1;
					max++;
					break;
				}
			}
		}
		for(k=l-1,i=l-1;i>=0;i--){
			for(j=k;j>=0;j--){
				if(a[i]<=b[j]){
					k=j-1;
					min++;
					break;
				}
			}
		}
		min=l-min;
		printf("%d\n%d\n",min,max);
	}
}


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

int n,s[2][1010];
char str[1010];
void sort(int *a);

int main(void)
{
    //freopen("card.in","r",stdin);
    //freopen("card.out","w",stdout);
    scanf("%d",&n);
    int i,j;
    scanf("%s",str);
    for(i=0;str[i];i++)
        s[0][i+1]=str[i]-'0';
    scanf("%s",str);
    for(i=0;str[i];i++)
        s[1][i+1]=str[i]-'0';
    sort(s[0]);  sort(s[1]);
    int ans=0;
    for(i=1,j=1;i<=n;i++)
    {
        while( j<=n && s[1][j]<s[0][i] ) j++;
        if(j>n) ans++;
        else j++;
    }
    printf("%d\n",ans);
    ans=0;
    for(i=1,j=1;i<=n;i++)
    {
        while( j<=n && s[1][j]<=s[0][i] ) j++;
        if(j>n) break;
        ans++;  j++;
    }
    printf("%d\n",ans);
    return 0;
}

void sort(int *a)
{
    int i,j,t;
    for(i=1;i<=n-1;i++)
        for(j=n;j>i;j--)
            if(a[j]<a[j-1])
            {
                t=a[j];  a[j]=a[j-1];  a[j-1]=t;
            }
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
int main()
{
    char a[1010],b[1010];
    int n,i,k,j,cnt,p;
    char temp;
    bool v[1010],u[1010];
    while(~scanf("%d",&n))
    {
        k=0,cnt=0;
        memset(v,0,sizeof(v));
        memset(u,0,sizeof(u));
        scanf("%s%s",a,b);
        for(i=0; i<n-1; i++)
            for(j=i+1; j<n; j++)
                if(a[i]>a[j])
                {
                    temp=a[i];
                    a[i]=a[j];
                    a[j]=temp;
                }
        for(i=0; i<n-1; i++)
            for(j=i+1; j<n; j++)
                if(b[i]>b[j])
                {
                    temp=b[i];
                    b[i]=b[j];
                    b[j]=temp;
                }
        for(i=0; i<n; i++)
            if(b[i]>a[k])
            {
                cnt++;
                k++;
            }
        p=n;
        for(i=n-1; i>=0; i--)
        {
            for(j=0; j<p; j++)
            {
                if(a[i]<=b[j]&&v[j]==0)
                {
                    v[j]=1;
                    break;
                }
            }
            if(j!=p)
                p--;
        }
        printf("%d\n%d\n",p,cnt);
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
int main()
{
    char a[1010],b[1010];
    int n,i,k,j,cnt,p;
    char temp;
    bool v[1010],u[1010];
    while(~scanf("%d",&n))
    {
        k=0,cnt=0;
        memset(v,0,sizeof(v));
        memset(u,0,sizeof(u));
        scanf("%s%s",a,b);
        for(i=0; i<n-1; i++)
            for(j=i+1; j<n; j++)
                if(a[i]>a[j])
                {
                    temp=a[i];
                    a[i]=a[j];
                    a[j]=temp;
                }
        for(i=0; i<n-1; i++)
            for(j=i+1; j<n; j++)
                if(b[i]>b[j])
                {
                    temp=b[i];
                    b[i]=b[j];
                    b[j]=temp;
                }
        for(i=0; i<n; i++)
            if(b[i]>a[k])
            {
                cnt++;
                k++;
            }
        p=n;
        for(i=n-1; i>=0; i--)
        {
            for(j=0; j<n; j++)
            {
                if(a[i]<=b[j]&&v[j]==0)
                {
                    v[j]=1;
                    break;
                }
            }
            if(j!=n)
                p--;
        }
        printf("%d\n%d\n",p,cnt);
    }
    return 0;
}


//Date:06-03-17

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<float.h>
#include<math.h>
#include<inttypes.h>
#include<assert.h>
#include<ctype.h>
#include<limits.h>
#include<time.h>
#define ll long long
#define For(i,n)	for(i=0;i<n;i++)
#define rep(i ,a ,b)	for(i=(a);i<=(b);i++)
#define mset(a ,value)	memset(a ,value ,sizeof(a))
#define s(a)	scanf("%d" ,&a);
#define ls(a)	scanf("%ld" ,&a)
#define reg(i)	register int i
#define infinite INT_MAX
#define MAX 1001
#define NIL -1
int min(int a,int b){	return (a<b?a:b);	}
int max(int a,int b){	return (a>b?a:b);	}
main(){
	int n ,i ,j;
	s(n);
	char s[n+1] ,m[n+1];
	scanf("\n%s\n%s" ,s ,m);
	int a[10];
	mset(a ,0);
	For(i ,n)	a[m[i]-'0']++;
	int ans1=0 ,ans2=0;
	For(i ,n){
		int x = s[i]-'0';
		j=x+1;
		while(j<10&&a[j]==0)	j++;
		if(j==10){
			j=0;
			while(j<10&&a[j]==0)	j++;
			a[j]--;
		}else{
			ans2++;
			a[j]--;
		}
	}
	mset(a ,0);
	For(i ,n)	a[m[i]-'0']++;
	For(i ,n){
		int x = s[i]-'0';
		if(a[x])	a[x]--;
		else{
			j = x+1;
			while(j<10&&a[j]==0)	j++;
			if(j==10){
				ans1++;
				j=0;
				while(j<10&&a[j]==0)	j++;
				a[j]--;
			}else 	a[j]--;
		}
	}
	printf("%d\n%d" ,ans1 ,ans2);
	return 0;
}


//Date:06-03-17

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<float.h>
#include<math.h>
#include<inttypes.h>
#include<assert.h>
#include<ctype.h>
#include<limits.h>
#include<time.h>
#define ll long long
#define For(i,n)	for(i=0;i<n;i++)
#define rep(i ,a ,b)	for(i=(a);i<=(b);i++)
#define mset(a ,value)	memset(a ,value ,sizeof(a))
#define s(a)	scanf("%d" ,&a);
#define ls(a)	scanf("%ld" ,&a)
#define reg(i)	register int i
#define infinite INT_MAX
#define MAX 1001
#define NIL -1
int min(int a,int b){	return (a<b?a:b);	}
int max(int a,int b){	return (a>b?a:b);	}
main(){
	int n ,i ,j;
	s(n);
	char s[n+1] ,m[n+1];
	scanf("\n%s\n%s" ,s ,m);
	int a[10];
	mset(a ,0);
	For(i ,n)	a[m[i]-'0']++;
	int ans1=0 ,ans2=0;
	For(i ,n){
		int x = s[i]-'0';
		if(x+1<10&&a[x+1])
			a[x+1]-- ,ans2++;
		else{
			j=0;
			while(j<10&&a[j]==0)	j++;
			a[j]--;
		}
	}
	mset(a ,0);
	For(i ,n)	a[m[i]-'0']++;
	For(i ,n){
		int x = s[i]-'0';
		if(a[x])	a[x]--;
		else{
			j = x+1;
			while(j<10&&a[j]==0)	j++;
			if(j==10){
				ans1++;
				j=0;
				while(j<10&&a[j]==0)	j++;
				a[j]--;
			}else 	a[j]--;
		}
	}
	printf("%d\n%d" ,ans1 ,ans2);
	return 0;
}


//Date:06-03-17

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<float.h>
#include<math.h>
#include<inttypes.h>
#include<assert.h>
#include<ctype.h>
#include<limits.h>
#include<time.h>
#define ll long long
#define For(i,n)	for(i=0;i<n;i++)
#define rep(i ,a ,b)	for(i=(a);i<=(b);i++)
#define mset(a ,value)	memset(a ,value ,sizeof(a))
#define s(a)	scanf("%d" ,&a);
#define ls(a)	scanf("%ld" ,&a)
#define reg(i)	register int i
#define infinite INT_MAX
#define MAX 1001
#define NIL -1
int min(int a,int b){	return (a<b?a:b);	}
int max(int a,int b){	return (a>b?a:b);	}
main(){
	int n ,i ,j;
	s(n);
	char s[n+1] ,m[n+1];
	scanf("\n%s\n%s" ,s ,m);
	int a[10];
	mset(a ,0);
	For(i ,n)	a[m[i]-'0']++;
	int ans1=0 ,ans2=0;
	For(i ,n){
		int x = s[i]-'0';
		if(x+1<10&&a[x+1])
			a[x+1]-- ,ans2++;
		else{
			if(a[x])	a[x]--;
			else{
			j=0;
			while(j<10&&a[j]==0)	j++;
			a[j]--;
			}
		}
	}
	mset(a ,0);
	For(i ,n)	a[m[i]-'0']++;
	For(i ,n){
		int x = s[i]-'0';
		if(a[x])	a[x]--;
		else{
			j = x+1;
			while(j<10&&a[j]==0)	j++;
			if(j==10){
				ans1++;
				j=0;
				while(j<10&&a[j]==0)	j++;
				a[j]--;
			}else 	a[j]--;
		}
	}
	printf("%d\n%d" ,ans1 ,ans2);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
int n;char temp;int countans1=0,countans2=0,i,j;
scanf("%d",&n);
char sher[n+1],mor[n+1];
scanf("%s%s",sher,mor);
sher[n]='\0';
mor[n]='\0';
for(i=0;i<n-1;i++)
{
    for(j=i+1;j<n;j++)
    {
        if(sher[i]>sher[j])
        {
            temp=sher[j];
            sher[j]=sher[i];
            sher[i]=temp;}
            if(mor[i]>mor[j])
            {
                temp=mor[j];
                mor[j]=mor[i];
                mor[i]=temp;}

            }}i=n-1;
            j=n-1;

            while(i>=0&&j>=0)
            {
                if(sher[i]>mor[j])
                {countans1++;
                i--;}
                else
                {i--;j--;}

            }i=n-1;j=n-1;
            while(i>=0&&j>=0)
            {
                if(sher[i]>=mor[j])
               { i--;j--;}
               else
              { countans2++;
               i--;}

            }printf("%d\n%d",countans1,countans2);return 0;}


#include<stdio.h>
#include<stdlib.h>
int main()
{
int n;char temp;int countans1=0,countans2=0,i,j;
scanf("%d",&n);
char sher[n+1],mor[n+1];
scanf("%s%s",sher,mor);
sher[n]='\0';
mor[n]='\0';
for(i=0;i<n-1;i++)
{
    for(j=i+1;j<n;j++)
    {
        if(sher[i]>sher[j])
        {
            temp=sher[j];
            sher[j]=sher[i];
            sher[i]=temp;}
            if(mor[i]>mor[j])
            {
                temp=mor[j];
                mor[j]=mor[i];
                mor[i]=temp;}

            }}i=n-1;
            j=n-1;

            while(i>=0&&j>=0)
            {
                if(sher[i]>mor[j])
                {countans1++;
                i--;}
                else
                {i--;j--;}

            }i=n-1;j=n-1;
            while(i>=0&&j>=0)
            {
                if(mor[i]>sher[j])
               { countans2++;
                  i--;j--;}
               else
              {
               j--;}

            }printf("%d\n%d",countans1,countans2);return 0;}


#include <stdio.h>

int CntS[10];
int CntM[10];

int main()
{
    int n;
    char strS[101], strM[101];
    scanf("%d %s %s", &n, strS, strM);
    for(int i = 0; i < n; ++i) {
        ++CntS[strS[i] - '0'];
        ++CntM[strM[i] - '0'];
    }
    int min = 0;
    for(int i = 9; i >= 0; --i) {
        while(CntM[i]) {
            --CntM[i];
            char find = 0;
            for(int j = i; j >= 0; --j) {
                if(CntS[j]) {
                    --CntS[j];
                    find = 1;
                    break;
                }
            }
            if(!find) {
                ++min;
            }
        }
    }
    for(int i = 0; i < 10; ++i) {
        CntS[i] = CntM[i] = 0;
    }
    for(int i = 0; i < n; ++i) {
        ++CntS[strS[i] - '0'];
        ++CntM[strM[i] - '0'];
    }
    int max = 0;
    for(int i = 9; i >= 0; --i) {
        while(CntM[i]) {
            --CntM[i];
            for(int j = i - 1; j >= 0; --j) {
                if(CntS[j]) {
                    --CntS[j];
                    ++max;
                    break;
                }
            }
        }
    }
    printf("%d\n%d\n", min, max);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
int n,flag=0,max=0,i;
cin>>n;
int a[n],b[n],c[n];
for(i=0;i<n;i++)
{
	cin>>a[i]>>b[i];
	if(flag=1)
	{
		c[i-1]=(b[i-1]-a[i]+b[i]);
	}
	flag=1;
}
max=c[0];
for(i=0;i<n;i++)
{
	if(max<c[i])
	{
		max=c[i];
	}
}
cout<<max;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
int n,flag=0,max=0,i,j;
cin>>n;
int a[n],b[n],c[n];
for(i=0,j=-1;i<n;i++,j++)
{
	cin>>a[i]>>b[i];
	if(flag=1)
	{
		c[j]=(b[j]-a[i]+b[i]);
	}
	flag=1;
}
max=c[0];
for(i=0;i<n;i++)
{
	if(max<c[i])
	{
		max=c[i];
	}
}
cout<<max;
}


#include <bits/stdc++.h>

using namespace std;

int main()

{
    int n,cap=0,max_v=0,b=0,a=0;
    cin>>n;
for (int i=0; i<n; i++)

{
        cin>>a>>b;
        cap=cap-a+b;

        max_v=max(max_v,cap);
    }
    cout<<max_v;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;int cap,max_v=INT_MIN;
    for(int i=0;i<n;i++)
    {
        int a,b;cin>>a>>b;
        cap=cap-a+b;
        max_v=max(cap,max_v);
    }

    cout<<max_v<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;int cap,max_v=0;
    for(int i=0;i<n;i++)
    {
        int a,b;cin>>a>>b;
        cap=cap-a+b;
        max_v=max(cap,max_v);
    }

    cout<<max_v<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;int cap,max_v=0;
    for(int i=0;i<n;i++)
    {
        int a,b;cin>>a>>b;
        cap=cap-a+b;
        max_v=max(cap,max_v);
    }

    cout<<max<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;int cap,max_v=0;
    for(int i=0;i<n;i++)
    {
        int a,b;cin>>a>>b;
        cap=cap-a+b;
        max_v=max(cap,max);
    }

    cout<<max<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;int cap,max_v=INT_MIN;
    for(int i=0;i<n;i++)
    {
        int a,b;cin>>a>>b;
        cap=cap-a+b;
        max_v=max(cap,max_v);
    }

    cout<<max<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",&s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

void fastscan(int &number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c=='-')
	{
		negative = true;
		c = getchar();
	}
	for (; (c>47 && c<58); c=getchar())
		number = number *10 + c - 48;
	if (negative)
		number *= -1;
}

void solve() {
	int i;
	int count[1000];
	int exitTram[1000], enterTram[1000];
	int peoplebefore = 0, peopleafter = 0 ,maxintram = 0;
	int stops;
	cin >> stops;
	// inTram[0] = 1;
	fo(i, stops){
		count[i] = 0;
	}
	fo(i,stops){
		cin >> exitTram[i] >> enterTram[i];
	}
	fo(i,stops){
		peopleafter = (peoplebefore-exitTram[i]) + enterTram[i];
		deb(peopleafter);
		cout<<endl;
		if((peoplebefore < peopleafter)){
			if(maxintram < peopleafter){
				maxintram = peopleafter;
				cout<<"in if: ";
				deb2(peoplebefore, peopleafter);
				cout<<endl;
			}
		}
		peoplebefore = peopleafter;
		deb(maxintram);
	}
	cout<<maxintram;

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    // fastscan(t);
    while(t--) {
      solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",&s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

void fastscan(int &number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c=='-')
	{
		negative = true;
		c = getchar();
	}
	for (; (c>47 && c<58); c=getchar())
		number = number *10 + c - 48;
	if (negative)
		number *= -1;
}

void solve() {
	int i;
	int count[1000];
	int exitTram[1000], enterTram[1000];
	int peoplebefore = 0, peopleafter = 0 ,maxintram = 0;
	int stops;
	cin >> stops;
	// inTram[0] = 1;
	fo(i, stops){
		count[i] = 0;
	}
	fo(i,stops){
		cin >> exitTram[i] >> enterTram[i];
	}
	fo(i,stops){
		peopleafter = (peoplebefore-exitTram[i]) + enterTram[i];
		// deb(peopleafter);
		// cout<<endl;
		if(peoplebefore < peopleafter){
			maxintram = peopleafter;
			// cout<<"in if: ";
			// deb2(peoplebefore, peopleafter);
			// cout<<endl;
		}
		peoplebefore = peopleafter;
		// deb(maxintram);
	}
	cout<<maxintram;

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    // fastscan(t);
    while(t--) {
      solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",&s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

void fastscan(int &number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c=='-')
	{
		negative = true;
		c = getchar();
	}
	for (; (c>47 && c<58); c=getchar())
		number = number *10 + c - 48;
	if (negative)
		number *= -1;
}

void solve() {
	int i;
	int exitTram[1000], enterTram[1000];
	int peoplebefore = 0, peopleafter = 0 ,maxintram = 0;
	int stops;
	cin >> stops;
	fo(i,stops){
		cin >> exitTram[i] >> enterTram[i];
	}
	fo(i,stops){
		peopleafter = (peoplebefore-exitTram[i]) + enterTram[i];
		if((peoplebefore < peopleafter)){
			if(maxintram < peopleafter){
				maxintram = peopleafter;
			}
		}
		peoplebefore = peopleafter;
	}
	cout<<maxintram;

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    // fastscan(t);
    while(t--) {
      solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",&s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

void fastscan(int &number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c=='-')
	{
		negative = true;
		c = getchar();
	}
	for (; (c>47 && c<58); c=getchar())
		number = number *10 + c - 48;
	if (negative)
		number *= -1;
}

void solve() {
	int i;
	int exitTram[1000], enterTram[1000], inTram = 0;
	int stops;
	cin >> stops;
	fo(i,stops){
		// deb(i);
		cin >> exitTram[i] >> enterTram[i];
		if (inTram < ((inTram-exitTram[i])+enterTram[i])){
			inTram = (inTram-exitTram[i])+enterTram[i];
		}
	}
	cout << inTram;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    // fastscan(t);
    while(t--) {
      solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",&s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

void fastscan(int &number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c=='-')
	{
		negative = true;
		c = getchar();
	}
	for (; (c>47 && c<58); c=getchar())
		number = number *10 + c - 48;
	if (negative)
		number *= -1;
}

void solve() {
	int i;
	int count[1000];
	int exitTram[1000], enterTram[1000];
	int peoplebefore = 0, peopleafter = 0 ,maxintram = 0;
	int stops;
	cin >> stops;
	// inTram[0] = 1;
	fo(i, stops){
		count[i] = 0;
	}
	fo(i,stops){
		cin >> exitTram[i] >> enterTram[i];
	}
	fo(i,stops){
		peopleafter = (peoplebefore-exitTram[i]) + enterTram[i];
		// deb(peopleafter);
		// cout<<endl;
		if((peoplebefore < peopleafter)){
			if(maxintram < peopleafter){
				maxintram = peopleafter;
				// cout<<"in if: ";
				// deb2(peoplebefore, peopleafter);
				// cout<<endl;
			}
		}
		peoplebefore = peopleafter;
		// deb(maxintram);
	}
	cout<<maxintram;

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    // fastscan(t);
    while(t--) {
      solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",&s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

void fastscan(int &number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c=='-')
	{
		negative = true;
		c = getchar();
	}
	for (; (c>47 && c<58); c=getchar())
		number = number *10 + c - 48;
	if (negative)
		number *= -1;
}

void solve() {
	int i;
	int exitTram[1000], enterTram[1000];
	int peoplebefore = 0, peopleafter = 0 ,maxintram = 0;
	int stops;
	cin >> stops;
	fo(i,stops){
		// cin >> exitTram[i] >> enterTram[i];
		fastscan(exitTram[i]);
		fastscan(enterTram[i]);
	}
	fo(i,stops){
		peopleafter = (peoplebefore-exitTram[i]) + enterTram[i];
		if((peoplebefore < peopleafter)){
			if(maxintram < peopleafter){
				maxintram = peopleafter;
			}
		}
		peoplebefore = peopleafter;
	}
	cout<<maxintram;

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    // fastscan(t);
    while(t--) {
      solve();
    }
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,big=0;
    cin>>n;
    pair<int,int>a[n];
    int tram[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first;
        cin>>a[i].second;
    }
    tram[0]=a[0].second;
    for(int i=1;i<n;i++)
    {
        if(i==1)
        tram[i]=a[0].second-a[1].first+a[1].second;
        else
        tram[i]=tram[i-1]-a[i].first+a[i].second;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(arr[i]>=arr[j])
            big=arr[i];
        }
    }
    cout<<big;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,big=0;
    cin>>n;
    pair<int,int>a[n];
    int tram[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first;
        cin>>a[i].second;
    }
    tram[0]=a[0].second;
    for(int i=1;i<n;i++)
    {
        if(i==1)
        tram[i]=a[0].second-a[1].first+a[1].second;
        else
        tram[i]=tram[i-1]-a[i].first+a[i].second;
    }
    for(int i=0;i<n;i++)
    {
        if(tram[i]>tram[i-1]&&tram[i]>tram[i+1])
        big=tram[i];
    }
    cout<<big;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,big=0;
    cin>>n;
    pair<int,int>a[n];
    int tram[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first;
        cin>>a[i].second;
    }
    tram[0]=a[0].second;
    for(int i=1;i<n;i++)
    {
        if(i==1)
        tram[i]=a[0].second-a[1].first+a[1].second;
        else
        tram[i]=tram[i-1]-a[i].first+a[i].second;
    }
    for(int i=0;i<n;i++)
    {
        if(tram[i]>=tram[i-1]&&tram[i]>=tram[i+1])
        big=tram[i];
    }
    cout<<big;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,big=0;
    cin>>n;
    pair<int,int>a[n];
    int tram[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first;
        cin>>a[i].second;
    }
    tram[0]=a[0].second;
    for(int i=1;i<n;i++)
    {
        if(i==1)
        tram[i]=a[0].second-a[1].first+a[1].second;
        else
        tram[i]=tram[i-1]-a[i].first+a[i].second;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(tram[i]>=tram[j])
            big=arr[i];
        }
    }
    cout<<big;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,big=0;
    cin>>n;
    pair<int,int>a[n];
    int tram[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first;
        cin>>a[i].second;
    }
    tram[0]=a[0].second;
    for(int i=1;i<n;i++)
    {
        if(i==1)
        tram[i]=a[0].second-a[1].first+a[1].second;
        else
        tram[i]=tram[i-1]-a[i].first+a[i].second;
    }
    for(int i=0;i<n;i++)
    {
        if(tram[i]>tram[i+1])
        big=tram[i];
    }
    cout<<big;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,big=0;
    cin>>n;
    pair<int,int>a[n];
    int tram[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first;
        cin>>a[i].second;
    }
    tram[0]=a[0].second;
    for(int i=1;i<n;i++)
    {
        if(i==1)
        tram[i]=a[0].second-a[1].first+a[1].second;
        else
        tram[i]=tram[i-1]-a[i].first+a[i].second;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(tram[i]>=tram[j])
            big=tram[i];
        }
    }
    cout<<big;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,big=0;
    cin>>n;
    pair<int,int>a[n];
    int tram[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first;
        cin>>a[i].second;
    }
    tram[0]=a[0].second;
    for(int i=1;i<n;i++)
    {
        if(i==1)
        tram[i]=a[0].second-a[1].first+a[1].second;
        else
        tram[i]=tram[i-1]-a[i].first+a[i].second;
    }
    big=tram[0];
    for(int i=0;i<n;i++)
    {
        if(tram[i]>big)
        big=tram[i];
    }
    cout<<big;
    return 0;
}


#include <iostream>
#include<string.h>
using namespace std;

int main()
{
   int a,b,n,c=0,d=0,i,d1=0;
   cin>>n;
   for(i=0;i<n;i++)
    {
        cin>>a>>b;

        d=d-a+b;

        if(c<d)
        {
            c=d;

        }
    }
    cout<<c;
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
int main(){
	int n;
	int capacity=0;
	max = 0;
	for(int i=0;i<n;i++){
		int leave,arrive;
		cin>>leave;
		cin>>arrive;
		capacity=capacity-leave;
		capacity+= arrive;
		if(capacity>max){
			max = capacity;
		}
	}
	cout<<capacity;
}


#include "bits/stdc++.h"
using namespace std;
int main(){
	int n;
	int capacity=0;
	int max = 0;
	for(int i=0;i<n;i++){
		int leave,arrive;
		cin>>leave;
		cin>>arrive;
		capacity=capacity-leave;
		capacity+= arrive;
		if(capacity>max){
			max = capacity;
		}
	}
	cout<<capacity;
}


#include "bits/stdc++.h"
using namespace std;
int main(){
	int n;
	cin>>n;
	int capacity=0;
	int max = 0;
	for(int i=0;i<n;i++){
		int leave,arrive;
		cin>>leave;
		cin>>arrive;
		capacity=capacity-leave;
		capacity+= arrive;
		if(capacity>max){
			max = capacity;
		}
	}
	cout<<max;
}


#include <iostream>
#include<string.h>
using namespace std;

int main()
{
   int a,b,n,c=0,d=0,i,d1=0;
   cin>>n;
   for(i=0;i<n;i++)
    {
        cin>>a>>b;

        d=d-a+b;

        if(c<d)
        {
            c=c+d;

        }
    }
    cout<<c;
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
int main(){
	int n;
	cin>>n;
	int capacity=0;
	int max = 0;
	for(int i=0;i<n;i++){
		int leave,arrive;
		cin>>leave;
		cin>>arrive;
		capacity=capacity-leave;
		capacity+= arrive;
		if(capacity>max){
			max = capacity;
		}
	}
	cout<<capacity;
}


#include<iostream>
using namespace std;

int main()
{
    int n,i,j;
    int a[1000],b[1000],p[1000],max=0;

    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i];
    }
    for(i=0;i<n;i++)
    {
        p[i]=b[i]-a[i+1]+b[i+1];

        //cout<<p[i-1]<<" ";
    }
     for(i=0;i<n;i++)
     {
      if(max<p[i])
            max=p[i];
     }
     cout<<max;
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n,i,j;
    int a[1000],b[1000],p[1000],max=0;

    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        cin>>b[i];
    }
    for(i=1;i<n;i++)
    {
        p[i-1]=b[i]-a[i+1]+b[i+1];

        //cout<<p[i-1]<<" ";
    }
     for(i=0;i<n;i++)
     {
      if(max<p[i])
            max=p[i];
     }
     cout<<max;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,j;
    cin>>n;
    int a[n],b[n],m,s;
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    s=b[0],m=b[0];
    for(i=1;i<n;i++)
    {
       s+= -a[i]+b[i];
       m=(s>m)?s:m;

    }
    cout<<m<<endl;
}


#include<iostream>
using namespace std;
int main(){
    int n,sum=0,max=0,a,b;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        sum+=b-a;
        if(sum>max)max=sum;
    }
    cout<<max<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,j;
    cin>>n;
    int a[n],b[n],s[n]={0},m;
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(i=0;i<n;i++)
    {
       s[i]= b[i]-a[i+1]+b[i+1];
       b[i+1]=s[i];

    }
    m=s[0];
    for(i=1;i<n;i++)
    {
        if(s[i]>m)
        {
        m=s[i];
        }

    }
    cout<<m<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,sum=0,max=0,a,b;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        sum+=b-a;
        if(sum>max)max=sum;
    }
    cout<<max<<endl;
}


#include<iostream>
using namespace std;

int main(){
    int n, a1, b1, a, b, max_passenger, passenger, i =1;
    cin >> n;
    cin >> a1 >> b1;
    max_passenger = b1;
    while(i<n){
    cin >>a>>b;
    passenger = b1+b-a;
    if (passenger > max_passenger){
        max_passenger = passenger;

    }
    i += 1;
    }
    cout<<max_passenger<<endl;
   return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n, a1, b1, a, b, max_passenger, passenger, i =1;
    cin >> n;
    cin >> a1 >> b1;
    max_passenger = b1;
    while(i<=n){
    cin >>a>>b;
    passenger = b1+b-a;
    if (passenger > max_passenger){
        max_passenger = passenger

    }
    i += 1;
    }
    cout<<max_passenger<<endl;
   return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n, a1, b1, a, b, max_passenger, passenger;
    cin >> n;
    cin >> a1 >> b1;
    max_passenger = b1
    for (i= 1,i<=n,i++){
    cin >>a>>b;
    passenger = b1+b-a;
    if (passenger > max_passenger){
        max_passenger = passenger

    }
    }
    cout<<max_passenger<<endl;
   return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n, a1, b1, a, b, max_passenger, passenger, i =1;
    cin >> n;
    cin >> a1 >> b1;
    max_passenger = b1;
    while(i<=n){
    cin >>a>>b;
    passenger = b1+b-a;
    if (passenger > max_passenger){
        max_passenger = passenger

    }
    i += 1
    }
    cout<<max_passenger<<endl;
   return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n, a1, b1, a, b, max_passenger, passenger, i =1;
    cin >> n;
    cin >> a1 >> b1;
    max_passenger = b1;
    while(i<=n){
    cin >>a>>b;
    passenger = b1+b-a;
    if (passenger > max_passenger){
        max_passenger = passenger;

    }
    i += 1;
    }
    cout<<max_passenger<<endl;
   return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n, a1, b1, a, b, max_passenger, passenger;
    cin >> n;
    cin >> a1 >> b1;
    max_passenger = b1;
    for (i= 1,i<=n,i++){
    cin >>a>>b;
    passenger = b1+b-a;
    if (passenger > max_passenger){
        max_passenger = passenger

    }
    }
    cout<<max_passenger<<endl;
   return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n, a1, b1, a, b, max_passenger, passenger, i =1;
    cin >> n;
    cin >> a1 >> b1;
    max_passenger = b1;
    passenger = b1;
    while(i<n){
    cin >>a>>b;
    passenger += b-a;
    if (passenger > max_passenger){
        max_passenger = passenger;
        }
    i += 1;
    }
    cout<<max_passenger<<endl;
    return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n, a1, b1, a, b, max_passenger, passenger;
    cin >> n;
    cin >> a1 >> b1;
    max_passenger = b1
    for (i= 1,i<=n,i++){
    cin >>a>>b;
    passenger = b1+b-a;
    if (passenger > max_passenger){
        max_passenger = passenger

    }
    }
    print(max_passenger)
   return 0;
}


#include<iostream>
using namespace std;
int main()
{
int a,b,c,n,i,d=0;
int m=0;
cin>>n;
cin>>a>>b;
if(a==0 && b==0)
{
	d++;
}
c=b;
for(i=0;i<n-1;i++)
{
	cin>>a>>b;
	if(a==0 && b==0)
	{
		d++;
	}

	else
	{
	c=c-a+b;
	m=max(m,c);
	}
}

if(d==n) cout<<"0"<<endl;
else if(m==0) cout<<m+1<<endl;

else
{
cout<<m<<endl;
}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
int a,b,c,n,i;
int m=0;
cin>>n;
cin>>a>>b;
c=b;
for(i=0;i<n-1;i++)
{
	cin>>a>>b;
	c=c-a+b;
	m=max(m,c);
}
if(m==0) cout<<m+1<<endl;
else
{
cout<<m<<endl;
}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
int a,b,c,n,m,i;

cin>>n;
cin>>a>>b;
m=max(a,b);
//***if(a==0 && b==0)
//{
//	d++;
//}

c=b;

for(i=0;i<n-1;i++)
{
	cin>>a>>b;
	c=c-a+b;
	m=max(m,c);

}

cout<<m<<endl;

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
int a,b,c,n,i;
int m=0;
cin>>n;
cin>>a>>b;
c=b;
for(i=0;i<n-1;i++)
{
	cin>>a>>b;
	c=c-a+b;
	m=max(m,c);
}
cout<<m<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
int a,b,c,n,i,d=0,e;
int m=0;
cin>>n;
cin>>a>>b;
if(a==0 && b==0)
{
	d++;
}
c=b;
e=c;
for(i=0;i<n-1;i++)
{
	cin>>a>>b;
	if(a==0 && b==0)
	{
		d++;
	}

	else
	{
	c=c-a+b;
	m=max(m,c);
	}

}

if(d==n) cout<<"0"<<endl;
else if(m==0) cout<<e<<endl;

else
{
cout<<m<<endl;
}
	return 0;
}


#include<iostream>

int main()
{
    int n,x,temp,max,flag=0;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&x);
        if(i==0)
        continue;
        if(i==1)
        {
            if(n==2)
            {
            ans=x;
            break;
            }
            else
            {
            temp=x;
            ans=x;
            }
        }
        if(i%2==0 && i!=0)
        {
            temp=temp-x;
        }
        else
        {
            if(i!=1)
            {
            temp=temp+x;
            if(temp>ans)
            ans=temp;
            }
            else
            continue;
        }
    }
     printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,arr[1000],max;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&arr[i]);
    }

    if(n==2)
    ans=arr[1];

    else
    {

    int temp = arr[1];
    max=temp;
    for(int i=2;i<(n*2)-2;i+=2)
    {
        temp=(temp-arr[i])+arr[i+1];
        printf("%d\n",temp);
        if(temp>max)
        {
            max=temp;
        }
    }
    ans=max;
    }
    //printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,arr[1000],max;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&arr[i]);
    }

    if(n==2)
    ans=arr[1];

    else
    {

    int temp = arr[1];
    max=temp;
    for(int i=2;i<(n*2)-2;i+=2)
    {
        temp=(temp-arr[i])+arr[i+1];
        //printf("%d\n",temp);
        if(temp>max)
        {
            max=temp;
        }
    }
    ans=max;
    }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,x,temp,max,flag=0;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&x);
        if(i==0)
        continue;
        if(i==1)
        {
            if(n==2)
            {
            ans=x;
            break;
            }
            else
            {
            temp=x;
            ans=x;
            }
        }
        if(i%2==0 && i!=0)
        {
            temp=temp-x;
        }
        else
        {
            if(i!=1)
            {
            temp=temp+x;
            printf("%d\n",temp);
            if(temp>ans)
            ans=temp;
            }
            else
            continue;
        }
    }
     //printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,arr[1000],max;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&arr[i]);
    }

    if(n==2)
    ans=arr[1];

    else
    {

    int temp = arr[1];
    max=temp;
    for(int i=2;i<(n*2)-2;i++)
    {
        temp=(temp-arr[i])+arr[i+1];
        printf("%d\n",temp);
        if(temp>max)
        {
            max=temp;
        }
    }
    ans=max;
    }
    //printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,arr[1000];
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&arr[i]);
    }

    if(n==2)
    ans=arr[1];

    else
    {

    int temp = arr[1];
    max=temp;
    for(int i=2;i<(n*2)-2;i++)
    {
        temp=(temp-arr[i])+arr[i+1];
        if(temp>max)
        {
            max=temp;
        }
    }
    ans=max;
    }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,x,temp,max,flag=0;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&x);
        if(i==1)
        {
            if(n==2)
            {
            ans=x;
            break;
            }
            else
            {
            temp=x;
            max=x;
            }
        }
        if(i%2==0 && i!=0)
        {
            flag=1;
            temp=temp-x;
        }
        if(flag==1)
        {
            temp=temp+x;
            if(temp>max)
            ans=temp;
            flag=0;
        }
    }
     printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,x,temp,max,flag;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&x);
        if(i==1)
        {
            if(n==2)
            {
            ans=x;
            break;
            }
            else
            {
            temp=x;
            max=x;
            }
        }
        if(i%2==0 && i!=0)
        {
            flag=1;
            temp=temp-x;
        }
        if(flag==1)
        {
            temp=temp+x;
            if(temp>max)
            ans=temp;
            flag=0;
        }
    }
     printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,arr[1000],max;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&arr[i]);
    }

    if(n==2)
    ans=arr[1];

    else
    {

    int temp = arr[1];
    max=temp;
    for(int i=2;i<(n*2)-2;i++)
    {
        temp=(temp-arr[i])+arr[i+1];
        if(temp>max)
        {
            max=temp;
        }
    }
    ans=max;
    }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,arr[1000];
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&arr[i]);
    }

    if(n==2)
    ans=arr[1];

    else
    {

    int temp = arr[1];
    max=temp;
    for(int i=2;i<(n*2)-2;i++)
    {
        temp=(temp-arr[i])+arr[i+1];
        if(temp>max)
        {
            max=temp;
        }
    }
    ans=max;
    }

    printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,x,temp,max,flag=0;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&x);
        if(i==1)
        {
            if(n==2)
            {
            ans=x;
            break;
            }
            else
            {
            temp=x;
            ans=x;
            }
        }
        if(i%2==0 && i!=0)
        {
            flag=1;
            temp=temp-x;
        }
        if(flag==1)
        {
            temp=temp+x;
            printf("%d\n",temp);
            if(temp>ans)
            ans=temp;
            flag=0;
        }
    }
     //printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,x,temp,max,flag=0;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&x);
        if(i==0)
        continue;
        if(i==1)
        {
            if(n==2)
            {
            ans=x;
            break;
            }
            else
            {
            temp=x;
            ans=x;
            }
        }
        if(i%2==0)
        {
            temp=temp-x;
        }
        else
        {
            temp=temp+x;
            printf("%d\n",temp);
            if(temp>ans)
            ans=temp;
        }
    }
     //printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,x,temp,max,flag=0;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&x);
        if(i==1)
        {
            if(n==2)
            {
            ans=x;
            break;
            }
            else
            {
            temp=x;
            ans=x;
            }
        }
        if(i%2==0 && i!=0)
        {
            flag=1;
            temp=temp-x;
        }
        if(flag==1)
        {
            temp=temp+x;
            if(temp>ans)
            ans=temp;
            flag=0;
        }
    }
     printf("%d\n",ans);
    return 0;
}


#include<iostream>

int main()
{
    int n,x,temp;
    scanf("%d",&n);
    int ans;
    for(int i=0;i<n*2;i++)
    {
        scanf("%d",&x);
        if(i==1)
        {
            if(n==2)
            {
            ans=x;
            break;
            }
            else
            {
            temp=x;
            max=x;
            }
        }
        if(i%2==0 && i!=0)
        {
            flag=1;
            temp=temp-x;
        }
        if(flag==1)
        {
            temp=temp+x;
            if(temp>max)
            ans=temp;
            flag=0;
        }
    }
     printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main() {
 int a,b,c,sum=0,sum2=0,total=0;
    cin>>a;

for(int i=0;i<a;i++){
cin>>b>>c;
sum -= a;
 sum += b;
total=max(total,sum);}

	 cout<<total;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main() {
int a;
cin >>a;
int y=0;
int c,b;
for (int i =0;i<a;i++){
    cin >>b>>c;
    y+=b;
}
cout<<y-4;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main() {
 int a,b,c,sum=0,total=0;
    cin>>a;

for(int i=0;i<a;i++){
cin>>b>>c;
  sum-= b;
 sum += c;
total=max(total,sum);}
cout<<total;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main() {
int a;
cin >>a;
int y=0;
int c[a],b[a];
for (int i =0;i<a;i++){
    cin >>b[i]>>c[i];
    y=b[i]+c[i];
}
cout<<y-4;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main() {
int a;
cin >>a;
int y=0;
int c,b;
for (int i =0;i<a;i++){
    cin >>b>>c;
    y+=b;
}
cout<<y-a;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main() {
int a;
cin >>a;
int y=0;
for (int i =0;i<a;i++){
    cin >>b[i]>>c[i];
    y=b[i]+c[i];
}
cout<<y-4;
return 0;
}


#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    int a[1000],b[1000];
    for(int i=0 ; i<n ; i++)
    cin>>a[i]>>b[i];

    int x=0,r;
    for(int i=0 ; i<n ; i++){
        r=b[i]-a[i+1];
        b[i+1]=b[i+1]+r;
        if(b[i+1]>=x)
        x=b[i+1];
    }
    cout<<x;

}


#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    int a[1000],b[1000];
    for(int i=0 ; i<n ; i++)
    cin>>a[i]>>b[i];

    int x=0,r;
    for(int i=0 ; i<n-1 ; i++){
        if(b[i+1]==0)
        x=b[i];
        else{
        r=b[i]-a[i+1];
        b[i+1]=b[i+1]+r;
        if(b[i+1]>=x)
        x=b[i+1];
        }
    }
    cout<<x;

}


#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    int a[1000],b[1000];
    for(int i=0 ; i<n ; i++)
    cin>>a[i]>>b[i];

    int x=0,r;
    for(int i=0 ; i<n-1 ; i++){
        r=b[i]-a[i+1];
        b[i+1]=b[i+1]+r;
        if(b[i+1]>x)
        x=b[i+1];
    }
    cout<<x;

}


#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    int a[1000],b[1000];
    for(int i=0 ; i<n ; i++)
    cin>>a[i]>>b[i];

    int x=0,r;
    for(int i=0 ; i<n-1 ; i++){
        if(b[i+1]==0 && i!=n-2)
        x=b[i];
        else{
        r=b[i]-a[i+1];
        b[i+1]=b[i+1]+r;
        if(b[i+1]>=x)
        x=b[i+1];
        }
    }
    cout<<x;

}


#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    int a[1000],b[1000];
    for(int i=0 ; i<n ; i++)
    cin>>a[i]>>b[i];

    int x=0,r;
    for(int i=0 ; i<n-1 ; i++){
        if(b[i+1]==0 && i!=n-2){
        x=b[i];
        break;
        }
        else{
        r=b[i]-a[i+1];
        b[i+1]=b[i+1]+r;
        if(b[i+1]>=x)
        x=b[i+1];
        }
    }
    cout<<x;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b,c=0,p=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		p+=b-a;
		if(p>c)
		c=p;
	}
	cout<<c;
}


#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    int a[1000],b[1000];
    for(int i=0 ; i<n-1 ; i++)
    cin>>a[i]>>b[i];

    int x=0,r;
    for(int i=0 ; i<n ; i++){
        r=b[i]-a[i+1];
        b[i+1]=b[i+1]+r;
        if(b[i+1]>=x)
        x=b[i+1];
    }
    cout<<x;

}


#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    int a[1000],b[1000];
    for(int i=0 ; i<n ; i++)
    cin>>a[i]>>b[i];

    int x=0,r;
    for(int i=0 ; i<n-1 ; i++){
        r=b[i]-a[i+1];
        b[i+1]=b[i+1]+r;
        if(b[i+1]>=x)
        x=b[i+1];
    }
    cout<<x;

}


#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    int a[1000],b[1000];
    for(int i=0 ; i<n-1 ; i++)
    cin>>a[i]>>b[i];

    int x=0,r;
    for(int i=0 ; i<n ; i++){
        r=b[i]-a[i+1];
        b[i+1]=b[i+1]+r;
        if(b[i+1]>x)
        x=b[i+1];
    }
    cout<<x;

}


#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    int a[1000],b[1000];
    for(int i=0 ; i<n ; i++)
    cin>>a[i]>>b[i];

    int x=0,r;
    for(int i=0 ; i<n ; i++){
        r=b[i]-a[i+1];
        b[i+1]=b[i+1]+r;
        if(b[i+1]>x)
        x=b[i+1];
    }
    cout<<x;

}


#include<iostream>
using namespace std;
int main(){
    int n,a,b,c=0,p;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		p+=b-a;
		if(p>c)
		c=p;
	}
	cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)
#define conti continue
#define brk break
#define pb push_back
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
#define in cin>>
#define out cout<<
#define endl <<"\n"
#define ll long long
#define remove(a,b) a.erase(std::remove(a.begin(),a.end(),b),a.end())

int main()
{
	ll int a;
	in a;
	ll int c[a],d=0,l=0,e[a];
	forr(i,0,a*2)	{in c[i];}

	forr(i,1,a*2)
	{
		d+=b[i]-b[i-1];
		e[l]=d;
		l++;
		i++;
	}
	sort(e,e+l,greater<int>());
	out e[0];

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)
#define conti continue
#define brk break
#define pb push_back
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
#define in cin>>
#define out cout<<
#define endl <<"\n"
#define ll long long
#define remove(a,b) a.erase(std::remove(a.begin(),a.end(),b),a.end())

int main()
{
	ll int a;
	in a;
	ll int b[a],c[a],d=0,l=0,e[a];
	forr(i,0,a*2)	{in b[i];}

	forr(i,1,a*2-1)
	{
		d+=b[i]-b[i-1];
		e[l]=d;
		l++;
		i++;
	}
	sort(e,e+l,greater<int>());
	out e[0];

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)
#define conti continue
#define brk break
#define pb push_back
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
#define in cin>>
#define out cout<<
#define endl <<"\n"
#define ll long long
#define remove(a,b) a.erase(std::remove(a.begin(),a.end(),b),a.end())

int main()
{
	ll int a;
	in a;
	ll int b[a],c[a],d=0,l=0,e[a];
	forr(i,0,a*2)	{in b[i];}

	forr(i,1,a*2)
	{
		d+=b[i]-b[i-1];
		e[l]=d;
		l++;
		i++;
	}
	sort(e,e+l,greater<int>());
	out e[0];

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)
#define conti continue
#define brk break
#define pb push_back
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
#define in cin>>
#define out cout<<
#define endl <<"\n"
#define ll long long
#define remove(a,b) a.erase(std::remove(a.begin(),a.end(),b),a.end())

int main()
{
    ll	int a;
	in a;
    ll	int b[a],c[a],d=0,l=0,e[a];
	forr(i,0,a*2){	in b[i];}
	forr(i,1,a*2)
	{
		d+=b[i]-b[i-1];
		e[l]=d;
		l++;
		i++;
	}
	sort(e,e+l,greater<int>());
	out e[0];

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)
#define conti continue
#define brk break
#define pb push_back
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
#define in cin>>
#define out cout<<
#define endl <<"\n"
#define ll long long
#define remove(a,b) a.erase(std::remove(a.begin(),a.end(),b),a.end())
#define runn(it,a) for(auto it = a.begin(); it!= a.end(); it++)

int main()
{
	SPEED;

	ll int a;
	in a;
	ll int c[a*2],d=0,l=0,e[a];
	forr(i,0,a*2)	{in c[i];}

	forr(i,1,a*2)
	{
		d+=c[i]-c[i-1];
		e[l]=d;
		l++;
		i++;
	}
	sort(e,e+l);
	out e[l-1];

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)
#define conti continue
#define brk break
#define pb push_back
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
#define in cin>>
#define out cout<<
#define endl <<"\n"
#define ll long long
#define remove(a,b) a.erase(std::remove(a.begin(),a.end(),b),a.end())

int main()
{
	ll int a;
	in a;
	ll int c[a],d=0,l=0,e[a];
	forr(i,0,a*2)	{in c[i];}

	forr(i,1,a*2)
	{
		d+=c[i]-c[i-1];
		e[l]=d;
		l++;
		i++;
	}
	sort(e,e+l);
	out e[l-1];

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ull = unsigned long long;
using ll = long long;

int main() {
  cin.sync_with_stdio(false);

  ull array_size;
  cin >> array_size;

  vector<ll> array(array_size);
  for (size_t i = 0; i < array_size; ++i) {
    cin >> array.at(i);
  }

  ll total_sum = accumulate(array.begin(), array.end(), 0l, plus<ll>());

  if (array_size == 6) {
    cout << total_sum << " " << total_sum/3 << " " << (total_sum/3)*2 << endl;
  }

  ull num_splits = 0;
  if (total_sum % 3 == 0) {
    ll s1 = total_sum / 3, s2 = (total_sum / 3) * 2;
    ull num_s1 = 0;
    ll curr_sum = 0;
    for (ull i = 0; i < array_size - 1; ++i) {
      curr_sum += array.at(i);
      if (curr_sum == s2) num_splits += num_s1;
      if (curr_sum == s1) num_s1++;
    }
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main() {
  cin.sync_with_stdio(false);

  size_t array_size;
  cin >> array_size;

  vector<int> array(array_size);
  for (int i = 0; i < array_size; ++i) {
    cin >> array.at(i);
  }

  unordered_map<long long, int> sum2freq;
  long long total_sum = accumulate(array.begin(), array.end(), 0l, plus<long long>());
  long long curr_sum = 0;
  long long num_splits = 0;
  for (int i = 0; i < array_size - 1; ++i) {
    curr_sum += array.at(i);

    long long split_sum = curr_sum/2;
    if (curr_sum%2 == 0 && split_sum*3 == total_sum && sum2freq.count(split_sum) > 0) {
      num_splits += sum2freq.at(split_sum);
    }

    if (sum2freq.count(curr_sum) > 0)
      sum2freq.at(curr_sum)++;
    else
      sum2freq.emplace(curr_sum, 1);
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

int main() {
  cin.sync_with_stdio(false);

  size_t array_size;
  cin >> array_size;

  vector<int> array(array_size);
  copy_n(istream_iterator<int>(cin), array_size, array.begin());

  vector<long long> running_sum(array_size);
  partial_sum(array.begin(), array.end(), running_sum.begin(), plus<int>());
  long long total_sum = running_sum.back();

  vector<pair<long long, size_t>> sum2pos(array_size);
  for (int i = 0; i < array_size; ++i) {
    sum2pos.emplace(sum2pos.begin() + i, running_sum.at(i), i);
  }
  sort(sum2pos.begin(), sum2pos.end());

  int num_splits = 0;
  for (size_t i_inc = 0; i_inc < array_size; ++i_inc) {
    long long split_sum = running_sum.at(i_inc);
    if (total_sum != 3 * split_sum) continue;

    auto lower = lower_bound(
        sum2pos.begin(),
        sum2pos.end(),
        make_pair(2 * split_sum, i_inc + 1));

    auto upper = upper_bound(
        sum2pos.begin(),
        sum2pos.end(),
        make_pair(2 * split_sum, array_size - 2));

    long dist = distance(lower, upper);
    if (dist > 0) num_splits += dist;
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main() {
  cin.sync_with_stdio(false);

  size_t array_size;
  cin >> array_size;

  vector<int> array(array_size);
  for (int i = 0; i < array_size; ++i) {
    cin >> array.at(i);
  }

  unordered_map<long long, int> sum2freq;
  long long total_sum = accumulate(array.begin(), array.end(), 0l, plus<long long>());
  long long curr_sum = 0;
  long long num_splits = 0;
  for (int i = 0; i < array_size - 1; ++i) {
    curr_sum += array.at(i);

    long long split_sum = curr_sum/2;
    if (curr_sum % 2 == 0 && split_sum*3 == total_sum && sum2freq.count(split_sum) > 0) {
      num_splits += sum2freq.at(split_sum);
    }

    if (sum2freq.count(curr_sum) > 0) {
      sum2freq.at(curr_sum)++;
    }
    else sum2freq.emplace(curr_sum, 1);
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main() {
  cin.sync_with_stdio(false);

  size_t array_size;
  cin >> array_size;

  vector<int> array(array_size);
  for (int i = 0; i < array_size; ++i) {
    cin >> array.at(i);
  }

  unordered_map<long long, int> sum2freq;
  long long total_sum = accumulate(array.begin(), array.end(), 0l, plus<long long>());
  long long curr_sum = 0;
  long long num_splits = 0;
  for (int i = 0; i < array_size - 1; ++i) {
    curr_sum += array.at(i);
    long long split_sum = curr_sum/2;

    if (array_size == 6) {
      cout << "[" << i << "]=" << array.at(i) << "; "
           << "curr_sum=" << curr_sum << "; "
           << "curr_sum%2=" << curr_sum % 2 << "; "
           << "split_sum*3" << split_sum * 3 << "; "
           << "sum2freq.count(split_sum)" << sum2freq.count(split_sum) << "; "
           << "sum2freq.at(split_sum)=" << (sum2freq.count(split_sum) > 0 ? sum2freq.at(split_sum) : -1) << endl;
    }

    if (curr_sum%2 == 0 && split_sum*3 == total_sum && sum2freq.count(split_sum) > 0) {
      num_splits += sum2freq.at(split_sum);
    }

    if (sum2freq.count(curr_sum) > 0)
      sum2freq.at(curr_sum)++;
    else
      sum2freq.emplace(curr_sum, 1);
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main() {
  cin.sync_with_stdio(false);

  size_t array_size;
  cin >> array_size;

  vector<int> array(array_size);
  for (int i = 0; i < array_size; ++i) {
    cin >> array.at(i);
  }

  unordered_map<long long, int> sum2freq;
  long long total_sum = accumulate(array.begin(), array.end(), 0l, plus<long long>());
  long long curr_sum = 0;
  int num_splits = 0;
  for (int i = 0; i < array_size - 1; ++i) {
    curr_sum += array.at(i);

    if ((curr_sum/2) * 3 == total_sum && curr_sum % 2 == 0) {
      num_splits += sum2freq.count(curr_sum / 2);
    }

    if (sum2freq.count(curr_sum) > 0) sum2freq.at(curr_sum)++;
    else sum2freq.emplace(curr_sum, 1);
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

int main() {
  cin.sync_with_stdio(false);

  size_t array_size;
  cin >> array_size;

  vector<int> array(array_size);
  copy_n(istream_iterator<int>(cin), array_size, array.begin());

  vector<long long> running_sum(array_size);
  partial_sum(array.begin(), array.end(), running_sum.begin(), plus<int>());
  long long total_sum = running_sum.back();

  vector<pair<long long, int>> sum2pos(array_size);
  for (int i = 0; i < array_size; ++i) {
    sum2pos.emplace(sum2pos.begin() + i, running_sum.at(i), i);
  }
  sort(sum2pos.begin(), sum2pos.end());

  int num_splits = 0;
  for (int i_inc = 0; i_inc < array_size; ++i_inc) {
    long long split_sum = running_sum.at(i_inc);
    if (total_sum != 3 * split_sum) continue;
    num_splits += count_if(
        lower_bound(
            sum2pos.begin(),
            sum2pos.end(),
            make_pair(2 * split_sum, numeric_limits<int>::min())),
        upper_bound(
            sum2pos.begin(),
            sum2pos.end(),
            make_pair(2 * split_sum, numeric_limits<int>::max())),
        [i_inc, array_size](const pair<long long, int> &s2p) {
            return s2p.second > i_inc && s2p.second < array_size - 1;
        }
    );
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

int main() {
  cin.sync_with_stdio(false);

  size_t array_size;
  cin >> array_size;

  vector<int> array(array_size);
  copy_n(istream_iterator<int>(cin), array_size, array.begin());

  vector<long long> running_sum(array_size);
  partial_sum(array.begin(), array.end(), running_sum.begin(), plus<int>());
  long long total_sum = running_sum.back();

  vector<pair<long long, size_t>> sum2pos(array_size);
  for (int i = 0; i < array_size; ++i) {
    sum2pos.emplace(sum2pos.begin() + i, running_sum.at(i), i);
  }
  sort(sum2pos.begin(), sum2pos.end());

  int num_splits = 0;
  for (size_t i_inc = 0; i_inc < array_size; ++i_inc) {
    long long split_sum = running_sum.at(i_inc);
    if (total_sum != 3 * split_sum) continue;

    auto lower = lower_bound(
        sum2pos.begin(),
        sum2pos.end(),
        make_pair(2 * split_sum, i_inc + 1));

    auto upper = upper_bound(
        sum2pos.begin(),
        sum2pos.end(),
        make_pair(2 * split_sum, array_size - 2));

    num_splits += max(distance(lower, upper), 0l);
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ull = unsigned long long;
using ll = long long;

int main() {
  cin.sync_with_stdio(false);

  ull array_size;
  cin >> array_size;

  vector<ll> array(array_size);
  for (size_t i = 0; i < array_size; ++i) {
    cin >> array.at(i);
  }

  ll total_sum = accumulate(array.begin(), array.end(), 0ll, plus<ll>());

  ull num_splits = 0;
  if (total_sum % 3 == 0) {
    ll s1 = total_sum / 3, s2 = (total_sum / 3) * 2;
    ull num_s1 = 0;
    ll curr_sum = 0;
    for (ull i = 0; i < array_size - 1; ++i) {
      curr_sum += array.at(i);
      if (curr_sum == s2) num_splits += num_s1;
      if (curr_sum == s1) num_s1++;
    }
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ull = unsigned long long;
using ll = long long;

int main() {
  cin.sync_with_stdio(false);

  ull array_size;
  cin >> array_size;

  vector<ll> array(array_size);
  for (size_t i = 0; i < array_size; ++i) {
    cin >> array.at(i);
  }

  ll total_sum = accumulate(array.begin(), array.end(), 0ll, plus<ll>());

  if (array_size == 6) {
    cout << total_sum << " " << total_sum/3 << " " << (total_sum/3)*2 << endl;
  }

  ull num_splits = 0;
  if (total_sum % 3 == 0) {
    ll s1 = total_sum / 3, s2 = (total_sum / 3) * 2;
    ull num_s1 = 0;
    ll curr_sum = 0;
    for (ull i = 0; i < array_size - 1; ++i) {
      curr_sum += array.at(i);
      if (curr_sum == s2) num_splits += num_s1;
      if (curr_sum == s1) num_s1++;
    }
  }

  cout << num_splits << endl;

  return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long sufic[600000];
long long leftanswers[600000];
long long rightanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	for (int i = N-1; i >= 0; --i)
	{
		if (i < N-1)
			sufic[i] = a[i] + sufic[i+1];
		else
			sufic[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	long long  cc = 1;
	long long  maxCount = 0;
	long long first = 0;
	for (long long i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] % 2*parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] == parties)
		{
			if (first == 0)
			{
				first = i;
			}
		}
	}
	cc = 0;
	long long partNear = first;
	for (long long i = N-2; i >= 0; --i)
	{
		if (pref[i] == parties)
		{
			partNear = i;
			rightanswers[partNear] = cc;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] >= 2*parties && pref[i] % 2*parties == 0)
		{
			//rightanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (long long i = 0; i < N-1; ++i)
		{
			if (pref[i] == parties)
			{
				//for (int k = i+1; k < N; ++k)
				{
					//if (rightanswers[k] > 0 && pref[k] >= 2*parties && pref[k] % 2*parties == 0)
					{
						answer += rightanswers[i];
						//break;
					}
				}
			}

		}
		//cout << answer;
		//return 0;
	}

		answer = 0;
	for (int i = 0; i < N-2; ++i)
	{
		long long part1 = pref[i];
		if(part1 == parties)
		{
			for (long long j = i+1; j < N-1; ++j)
			{
				long long part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					long long part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 480000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long sufic[600000];
long long leftanswers[600000];
long long rightanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	for (int i = N-1; i >= 0; --i)
	{
		if (i < N-1)
			sufic[i] = a[i] + sufic[i+1];
		else
			sufic[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	long long  cc = 1;
	long long  maxCount = 0;
	long long first = 0;
	for (long long i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] % 2*parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] == parties)
		{
			if (first == 0)
			{
				first = i;
			}
		}
	}
	cc = 0;
	long long partNear = first;
	for (long long i = N-2; i >= 0; --i)
	{
		if (pref[i] == parties)
		{
			partNear = i;
			rightanswers[partNear] = cc;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] >= 2*parties && pref[i] % 2*parties == 0)
		{
			//rightanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (long long i = 0; i < N-1; ++i)
		{
			if (pref[i] == parties)
			{
				//for (int k = i+1; k < N; ++k)
				{
					//if (rightanswers[k] > 0 && pref[k] >= 2*parties && pref[k] % 2*parties == 0)
					{
						answer += rightanswers[i];
						//break;
					}
				}
			}

		}
		//cout << answer;
		//return 0;
	}

		answer = 0;
	for (int i = 0; i < N-2; ++i)
	{
		long long part1 = pref[i];
		if(part1 == parties)
		{
			for (long long j = i+1; j < N-1; ++j)
			{
				long long part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					long long part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 510000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long sufic[600000];
long long leftanswers[600000];
long long rightanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	for (int i = N-1; i >= 0; --i)
	{
		if (i < N-1)
			sufic[i] = a[i] + sufic[i+1];
		else
			sufic[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	long long  cc = 1;
	long long  maxCount = 0;
	int first = 0;
	for (int i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] % 2*parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] == parties)
		{
			if (first == 0)
			{
				first = i;
			}
		}
	}
	cc = 1;
	for (int i = N-1; i >= 0; --i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] % 2*parties == 0)
		{
			rightanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (int i = first; i < N; ++i)
		{
			if (pref[i] == parties)
			{
				for (int k = i+1; k < N; ++k)
				{
					if (rightanswers[k] > 0)
					{
						answer += rightanswers[k];
						break;
					}
				}
			}

		}
		if (answer == 0) {
			cout << 0;
			return 0;
		}
		cout << (parties == 0 ? answer : answer);
		return 0;
	}
	for (int i = 0; i < N-2; ++i)
	{
		int part1 = pref[i];
		if(part1 == parties)
		{
			for (int j = i+1; j < N-1; ++j)
			{
				int part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					int part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 1000000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long answer = 0;
long long a[600000];
long long pref[600000];
long long leftanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	int cc = 1;
	int maxCount = 0;
	int firstt = -1;
	for (int i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 || parties != 0 && pref[i] % parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
			if (firstt == -1)
				firstt = i;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (int i = firstt; i < N; ++i)
		{
			if ( parties == 0 && leftanswers[i] > 0 || parties != 0 && pref[i] % 2*parties == 0)
			{
				answer += (maxCount - leftanswers[i]);

			}
		}

		cout << (parties == 0 ? answer : answer-1);
		return 0;
	}
	for (int i = 0; i < N-2; ++i)
	{
		int part1 = pref[i];
		if(part1 == parties)
		{
			for (int j = i+1; j < N-1; ++j)
			{
				int part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					int part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 1000000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long sufic[600000];
long long leftanswers[600000];
long long rightanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	for (int i = N-1; i >= 0; --i)
	{
		if (i < N-1)
			sufic[i] = a[i] + sufic[i+1];
		else
			sufic[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	long long  cc = 1;
	long long  maxCount = 0;
	long long first = 0;
	for (long long i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] % 2*parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] == parties)
		{
			if (first == 0)
			{
				first = i;
			}
		}
	}
	cc = 1;
	long long partNear = 1;
	for (long long i = N-2; i >= 0; --i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] >= 2*parties && pref[i] % 2*parties == 0)
		{
			//rightanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
		if (pref[i] == parties)
		{
			partNear = i;
			rightanswers[partNear] = cc-1;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (long long i = first; i < N-1; ++i)
		{
			if (pref[i] == parties)
			{
				//for (int k = i+1; k < N; ++k)
				{
					//if (rightanswers[k] > 0 && pref[k] >= 2*parties && pref[k] % 2*parties == 0)
					{
						answer += rightanswers[i];
						//break;
					}
				}
			}

		}
		cout << answer;
		return 0;
	}

	for (int i = 0; i < N-2; ++i)
	{
		int part1 = pref[i];
		if(part1 == parties)
		{
			for (int j = i+1; j < N-1; ++j)
			{
				int part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					int part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 1000000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long sufic[600000];
long long leftanswers[600000];
long long rightanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	for (int i = N-1; i >= 0; --i)
	{
		if (i < N-1)
			sufic[i] = a[i] + sufic[i+1];
		else
			sufic[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	long long  cc = 1;
	long long  maxCount = 0;
	long long first = 0;
	for (long long i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] % 2*parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] == parties)
		{
			if (first == 0)
			{
				first = i;
			}
		}
	}
	cc = 0;
	long long partNear = first;
	for (long long i = N-2; i >= 0; --i)
	{
		if (pref[i] == parties)
		{
			partNear = i;
			rightanswers[partNear] = cc;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] >= 2*parties && pref[i] % 2*parties == 0)
		{
			//rightanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (long long i = 0; i < N-1; ++i)
		{
			if (pref[i] == parties)
			{
				//for (int k = i+1; k < N; ++k)
				{
					//if (rightanswers[k] > 0 && pref[k] >= 2*parties && pref[k] % 2*parties == 0)
					{
						answer += rightanswers[i];
						//break;
					}
				}
			}

		}
		//cout << answer;
		//return 0;
	}

		answer = 0;
	for (int i = 0; i < N-2; ++i)
	{
		int part1 = pref[i];
		if(part1 == parties)
		{
			for (int j = i+1; j < N-1; ++j)
			{
				int part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					int part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 1000000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long answer = 0;
long long a[600000];
long long pref[600000];
int N;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	const int parties = pref[N-1]/3;
	for (int i = 0; i < N-2; ++i)
	{
		int part1 = ( i == 0 ? a[i] : pref[i] );
		if(part1 == parties)
		{
			for (int j = i+1; j < N-1; ++j)
			{
				int part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					int part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long sufic[600000];
long long leftanswers[600000];
long long rightanswers[600000];
int N;
long long counter = 0;

void longSolve()
{
	long long parties = pref[N-1]/3;
	answer = 0;
	for (int i = 0; i < N-2; ++i)
	{
		long long part1 = pref[i];
		if(part1 == parties)
		{
			for (long long j = i+1; j < N-1; ++j)
			{
				long long part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					long long part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 451000000)
				{
					cout << answer;
					return ;
				}
			}
		}
	}
	cout << answer;
}

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}

	long long parties = pref[N-1] / 3;
	long long  cc = 0;
	for (long long i = N-2; i >= 0; --i)
	{
		if (pref[i] == parties)
		{
			rightanswers[i] = cc;
		}
		if ( parties == 0 && pref[i] == 0 ||
		     parties != 0 && pref[i] == 2*parties)
		{
			cc++;
		}
	}

	answer = 0;
	for (long long i = 0; i < N-1; ++i)
	{
		if (pref[i] == parties)
		{
			answer += rightanswers[i];
		}
	}

	cout << answer;

	//longSolve();
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long leftanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	long long  cc = 1;
	long long  maxCount = 0;
	long long  firstt = -1;
	for (int i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 || parties != 0 && pref[i] % parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
			if (firstt == -1)
				firstt = i;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (int i = firstt; i < N; ++i)
		{
			if (parties != 1)
			{
				if ( parties == 0 && leftanswers[i] > 0 || parties != 0 && pref[i] % 2*parties == 0)
				{
					answer += (maxCount - leftanswers[i]);

				}
			}
			else
			{
				if (pref[i] == 1) {
					answer += (maxCount - leftanswers[i]);
				}
			}
		}
		if (answer == 0) {
			cout << 0;
			return 0;
		}
		cout << (parties == 0 ? answer : answer-1);
		return 0;
	}
	for (int i = 0; i < N-2; ++i)
	{
		int part1 = pref[i];
		if(part1 == parties)
		{
			for (int j = i+1; j < N-1; ++j)
			{
				int part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					int part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 1000000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long sufic[600000];
long long leftanswers[600000];
long long rightanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	for (int i = N-1; i >= 0; --i)
	{
		if (i < N-1)
			sufic[i] = a[i] + sufic[i+1];
		else
			sufic[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	long long  cc = 1;
	long long  maxCount = 0;
	int first = 0;
	for (int i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] % 2*parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] == parties)
		{
			if (first == 0)
			{
				first = i;
			}
		}
	}
	cc = 1;
	for (int i = N-1; i >= 0; --i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] >= 2*parties && pref[i] % 2*parties == 0)
		{
			rightanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (int i = first; i < N; ++i)
		{
			if (pref[i] == parties)
			{
				for (int k = i+1; k < N; ++k)
				{
					if (rightanswers[k] > 0)
					{
						answer += rightanswers[k];
						break;
					}
				}
			}

		}
		if (answer == 0) {
			cout << 0;
			return 0;
		}
		cout << (parties == 0 ? answer : answer);
		return 0;
	}
	for (int i = 0; i < N-2; ++i)
	{
		int part1 = pref[i];
		if(part1 == parties)
		{
			for (int j = i+1; j < N-1; ++j)
			{
				int part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					int part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 1000000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long sufic[600000];
long long leftanswers[600000];
long long rightanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	for (int i = N-1; i >= 0; --i)
	{
		if (i < N-1)
			sufic[i] = a[i] + sufic[i+1];
		else
			sufic[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	long long  cc = 1;
	long long  maxCount = 0;
	long long first = 0;
	for (long long i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] % 2*parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] == parties)
		{
			if (first == 0)
			{
				first = i;
			}
		}
	}
	cc = 0;
	long long partNear = first;
	for (long long i = N-2; i >= 0; --i)
	{
		if (pref[i] == parties)
		{
			partNear = i;
			rightanswers[partNear] = cc;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] >= 2*parties && pref[i] % 2*parties == 0)
		{
			//rightanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (long long i = 0; i < N-1; ++i)
		{
			if (pref[i] == parties)
			{
				//for (int k = i+1; k < N; ++k)
				{
					//if (rightanswers[k] > 0 && pref[k] >= 2*parties && pref[k] % 2*parties == 0)
					{
						answer += rightanswers[i];
						//break;
					}
				}
			}

		}
		//cout << answer;
		//return 0;
	}

		answer = 0;
	for (int i = 0; i < N-2; ++i)
	{
		int part1 = pref[i];
		if(part1 == parties)
		{
			for (int j = i+1; j < N-1; ++j)
			{
				int part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					int part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 500000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

long long  answer = 0;
long long a[600000];
long long pref[600000];
long long sufic[600000];
long long leftanswers[600000];
long long rightanswers[600000];
int N;
long long counter = 0;

int main(void)
{
	ios_base::sync_with_stdio(0);
	//freopen("ancestor.in", "rt", stdin);
	//freopen("ancestor.out", "wt", stdout);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		if (i > 0)
			pref[i] = a[i] + pref[i-1];
		else
			pref[i] = a[i];
	}
	for (int i = N-1; i >= 0; --i)
	{
		if (i < N-1)
			sufic[i] = a[i] + sufic[i+1];
		else
			sufic[i] = a[i];
	}
	long long parties = pref[N-1]/3;
	long long  cc = 1;
	long long  maxCount = 0;
	long long first = 0;
	for (long long i = 1; i < N; ++i)
	{
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] % 2*parties == 0)
		{
			leftanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] == parties)
		{
			if (first == 0)
			{
				first = i;
			}
		}
	}
	cc = 0;
	long long partNear = first;
	for (long long i = N-2; i >= 0; --i)
	{
		if (pref[i] == parties)
		{
			partNear = i;
			rightanswers[partNear] = cc;
		}
		if ( parties == 0 && pref[i] == 0 ||
			parties == 1 && pref[i] == 1 ||
			parties != 0 && pref[i] >= 2*parties && pref[i] % 2*parties == 0)
		{
			//rightanswers[i] = cc;
			maxCount = cc;
			cc++;
		}
	}
	//if (parties == 0)
	{
		answer = 0;
		for (long long i = 0; i < N-1; ++i)
		{
			if (pref[i] == parties)
			{
				//for (int k = i+1; k < N; ++k)
				{
					//if (rightanswers[k] > 0 && pref[k] >= 2*parties && pref[k] % 2*parties == 0)
					{
						answer += rightanswers[i];
						//break;
					}
				}
			}

		}
		//cout << answer;
		//return 0;
	}

		answer = 0;
	for (int i = 0; i < N-2; ++i)
	{
		long long part1 = pref[i];
		if(part1 == parties)
		{
			for (long long j = i+1; j < N-1; ++j)
			{
				long long part2 = ( pref[j] - pref[i] );
				if(part2 == parties)
				{
					long long part3 = pref[N-1] - pref[j];
					if(part3 == parties)
					{
						answer++;
					}
				}
				counter++;
				if (counter > 460000000)
				{
					cout << answer;
					return 0;
				}
			}
		}
	}
	cout << answer;
	return 0;
}