#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,c,d=0,e=0,i;
    scanf("%d",&a);
    while(a>0)
    {
        scanf("%d",&b);
        c=b;
        b=b/2;
      if(b%2==1)
      {
          printf("NO\n");
          continue;
      }
      else{
        for(i=1;i<=b;i++)
        {
            printf("YES\n");
            printf("%d ",2*i);
            d=d+2*i;
        }
        for(i=1;i<=b-1;i++)
        {
            printf("%d ",2*i-1);
            e=e+(2*i-1);
        }
        printf("%d\n",d-e);
      }
        a--;
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int t,i,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        if (n%4!=0)
            {printf("NO\n");}
        else
        {
            printf("YES\n");
            for(i=2;i<=n;i=i+2)
            {
                printf("%d ",i);
            }
            for(i=1;i<n-2;i=i+2)
            {
                printf("%d ",i);

            }
            printf("%d \n",n+n/2-1);

        }

    }
    return 0;

}


#include<stdio.h>
int main()
{
    int t,i,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        if(n%4==0)
        {
            printf("YES\n");
            for(i=2;i<=n;i=i+2)
            {
                printf("%d ",i);
            }
            for(i=1;i<n;i=i+2)
            {
                printf("%d ",i*2-1);
            }
            printf("%d \n",3*n-1);
        }
        else
            printf("NO\n");
    }
    return 0;

}


#include<stdio.h>
int main()
{
      long long int a,b,c,d,i,j;

      scanf("%lld",&a);
      while(a--)
      {
            scanf("%lld",&b);
            if(b%2!=0)
            printf("NO\n");
            else
            {
                  printf("YES\n");
                  for(i=1;i<=b/2;i++)
                  {
                        printf("%lld",i*2);
                  }
                  for(i=1;i<b/2;i++)
                  {
                        printf("%lld",i*2-1);
                  }
                  printf("%lld\n",3*i-1);
            }
      }
      return 0;
}


#include <iostream>
#define N 20005
using namespace std;
int n;
int a[N],ans=0,max1=0,b[N];
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    int temp=0;
    for(int i=1;i<=n;i++)
        b[++temp]=a[i];
    for(int i=1;i<=n;i++)
    {
        if(a[i]==1)
            ans++;
        else
            ans=0;
        if(ans>max1)
            max1=ans;
    }
    for(int i=1;i<=n;i++)
    {
        if(b[i]==1)
            ans++;
        else
            ans=0;
        if(ans>max1)
            max1=ans;
    }
    cout << max1 << endl;
    return 0;
}


#include <iostream>

int main()
   {
   int n,i,cnt1=0,cnt2=0,res;
   bool ok=false;

   std::cin >> n;

   bool *a = new bool[n];

   for(i=0; i<n; i++) std::cin >> a[i];

   for(i=0; i<n; i++)
      {
      if(!a[i]) break;
      else cnt1++;
      }

   if(cnt1>0)
      {
      for(i=n-1; i>=0; i--)
         {
         if(!a[i]) break;
         else cnt1++;
         }
      }

   res=cnt1;

   for(i=0; i<n; i++)
      {
      if(!ok)
         {
         if(a[i])
            {
            ok=true;
            cnt2=1;
            }
         }
      else
         {
         if(!a[i])
            {
            ok=false;
            if(cnt2>res) res=cnt2;
            }
         else cnt2++;
         }
      }

   if(cnt2>res) res=cnt2;

   std::cout << res << std::endl;

   //std::system("pause");

   delete [] a;

   return 0;
   }


#include <iostream>

int main()
   {
   int n,i,cnt1,cnt2,res;
   bool ok=false;

   std::cin >> n;

   bool *a = new bool[n];

   for(i=0; i<n; i++) std::cin >> a[i];

   cnt1=0;

   for(i=0; i<n; i++)
      {
      if(!a[i]) break;
      else cnt1++;
      }

   if(cnt1>0)
      {
      for(i=n-1; i>=0; i--)
         {
         if(!a[i]) break;
         else cnt1++;
         }
      }

   res=cnt1;

   for(i=0; i<n; i++)
      {
      if(!ok)
         {
         if(a[i])
            {
            ok=true;
            cnt2=1;
            }
         }
      else
         {
         if(!a[i])
            {
            ok=false;
            if(cnt2>res) res=cnt2;
            }
         else cnt2++;
         }
      }

   std::cout << res << std::endl;

   //std::system("pause");

   delete [] a;

   return 0;
   }


#include <iostream>

int main()
   {
   int n,i,cnt1,cnt2,res;
   bool ok=false;

   std::cin >> n;

   bool *a = new bool[n];

   for(i=0; i<n; i++) std::cin >> a[i];

   cnt1=0;

   for(i=0; i<n; i++)
      {
      if(!a[i]) break;
      else cnt1++;
      }

   if(cnt1>0)
      {
      for(i=n-1; i>=0; i--)
         {
         if(!a[i]) break;
         else cnt1++;
         }
      }

   res=cnt1;

   for(i=0; i<n; i++)
      {
      if(!ok)
         {
         if(a[i])
            {
            ok=true;
            cnt2=1;
            }
         }
      else
         {
         if(!a[i])
            {
            ok=false;
            if(cnt2>res) res=cnt2;
            }
         else cnt2++;
         }
      }

   std::cout << res << std::endl;

   std::system("pause");

   delete [] a;

   return 0;
   }


#include <iostream>

int main()
   {
   int n,i,cnt1,cnt2,res;
   bool ok=false;

   std::cin >> n;

   bool *a = new bool[n];

   for(i=0; i<n; i++) std::cin >> a[i];

   cnt1=0;

   for(i=0; i<n; i++)
      {
      if(!a[i]) break;
      else cnt1++;
      }

   if(cnt1>0)
      {
      for(i=n-1; i>=0; i--)
         {
         if(i<n-1 && !a[i]) break;
         else cnt1++;
         }
      }

   res=cnt1;

   for(i=0; i<n; i++)
      {
      if(!ok)
         {
         if(a[i])
            {
            ok=true;
            cnt2=1;
            }
         }
      else
         {
         if(!a[i])
            {
            ok=false;
            if(cnt2>res) res=cnt2;
            }
         else cnt2++;
         }
      }

   std::cout << res << std::endl;

   //std::system("pause");

   delete [] a;

   return 0;
   }


#include <stdio.h>
#include <algorithm>
using namespace std;

int arr[400100];

int main()
{
	int n, maxv = 0, nowv;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
	for (int i = 0; i < n; i++) arr[i + n] = arr[i];

	for (int i = 0; i < n; i++) {
		if (arr[i]) {
			nowv = 0;
			while (arr[i]) { nowv++; i++; }
			maxv = max(maxv, nowv);
		}
	}
	printf("%d\n", maxv);
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a, long long b) { while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = { -1, 0, 1, 0, -1, 1,  1, -1 };
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1 };

long long GCD(long long b, long long a)
{
	if (a == 0)
		return b;
	return GCD(a, b%a);
}
long long getLCM(long long a, long long b) {
	long long c = a / GCD(a, b);
	return b * c;
}
LL a[200005];

int main() {
	//freopen ("d:/Codejam/lazy_loading.txt","r",stdin);
	//freopen ("d:/Codejam/output.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test, l;
	string str;

	int c = 0, position;
	while (cin >> n) {

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

		ans = 0;

		for (i = 1; i <= n; i++) {
			if ((i == 1 && a[n]) )
				x = 1;
			else
				x = 0;

			while (a[i] && i<=n) {
				x++;
				i++;
			}
			if (i > n && a[1])
				x++;

			if (x > ans)
				ans = x;
		}

		if (ans > n)
			ans = n;

		cout << ans << endl;

	}

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a, long long b) { while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = { -1, 0, 1, 0, -1, 1,  1, -1 };
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1 };

long long GCD(long long b, long long a)
{
	if (a == 0)
		return b;
	return GCD(a, b%a);
}
long long getLCM(long long a, long long b) {
	long long c = a / GCD(a, b);
	return b * c;
}
LL a[200005];

int main() {
	//freopen ("d:/Codejam/lazy_loading.txt","r",stdin);
	//freopen ("d:/Codejam/output.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test, l;
	string str;

	int c = 0, position;
	while (cin >> n) {

		//http://codeforces.com/contest/1141/submission/51490078 for  easier calculation
		for (i = 1; i <= n; i++) {
			cin >> a[i];
		}

		ans = 0;

		for (i = 1; i <= n; i++) {
			j = i;
			if ((i == 1 && a[n]))
				x = 1;
			else
				x = 0;

			while (a[i] && i <= n) {
				x++;
				i++;
			}
			if (i > n) {
				i = 1;
				while (a[i]) {
					x++;
					i++;
				}
				i = n + 1;
			}

			if (x > ans)
				ans = x;
		}

		if (ans > n)
			ans = n;

		cout << ans << endl;

	}

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a, long long b) { while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = { -1, 0, 1, 0, -1, 1,  1, -1 };
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1 };

long long GCD(long long b, long long a)
{
	if (a == 0)
		return b;
	return GCD(a, b%a);
}
long long getLCM(long long a, long long b) {
	long long c = a / GCD(a, b);
	return b * c;
}
LL a[200005];

int main() {
	//freopen ("d:/Codejam/lazy_loading.txt","r",stdin);
	//freopen ("d:/Codejam/output.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test, l;
	string str;

	int c = 0, position;
	while (cin >> n) {
		for (int i = 1; i <= n; i++){
			cin >> a[i];
			a[i + n] = a[i];// make the array double for cyclic calucaltion and It is guaranteed that there is at least one working hour in a day. all 1 not possible
		}
		k = 0;
		for (int i = 1; i <= 2 * n; i++){
			if (a[i]) k++;
			else k = 0;
			ans = max(k, ans);
		}

		cout << ans << endl;

	}

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a, long long b) { while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = { -1, 0, 1, 0, -1, 1,  1, -1 };
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1 };

long long GCD(long long b, long long a)
{
	if (a == 0)
		return b;
	return GCD(a, b%a);
}
long long getLCM(long long a, long long b) {
	long long c = a / GCD(a, b);
	return b * c;
}
LL a[200005];

int main() {
	//freopen ("d:/Codejam/lazy_loading.txt","r",stdin);
	//freopen ("d:/Codejam/output.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test, l;
	string str;

	int c = 0, position;
	while (cin >> n) {
		for (int i = 1; i <= n; i++){
			cin >> a[i];
			a[i + n] = a[i];
		}
		for (int i = 1; i <= 2 * n; i++){
			if (a[i]) k++;
			else k = 0;
			ans = max(k, ans);
		}

		cout << ans << endl;

	}

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a, long long b) { while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = { -1, 0, 1, 0, -1, 1,  1, -1 };
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1 };

long long GCD(long long b, long long a)
{
	if (a == 0)
		return b;
	return GCD(a, b%a);
}
long long getLCM(long long a, long long b) {
	long long c = a / GCD(a, b);
	return b * c;
}
LL a[200005];

int main() {
	//freopen ("d:/Codejam/lazy_loading.txt","r",stdin);
	//freopen ("d:/Codejam/output.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test, l;
	string str;

	int c = 0, position;
	while (cin >> n) {

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

		ans = 0;

		for (i = 1; i <= n; i++) {
			j = i;
			if ((i == 1 && a[n]) )
				x = 1;
			else
				x = 0;

			while (a[i] && i<=n) {
				x++;
				i++;
			}
			if (i > n) {
				i = 1;
				while (a[i]) {
					x++;
					i++;
				}
				i = n+1;
			}

			if (x > ans)
				ans = x;
		}

		if (ans > n)
			ans = n;

		cout << ans << endl;

	}

	return 0;
}


#include <iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
using namespace std;
int main()
{
    double n,m;
    cin>>n>>m;

    int ans=0;

    int x=m/n;
    double y=m/n;
    bool flag=0;

    if(y-x!=0)
    {
        cout<<"-1"<<endl;

        return 0;

    }

        if(y-x==0&&n!=1)
        {
            while(x%3==0)
            {
                ans++;
                x/=3;
            }

            while(x%2==0)
            {
                ans++;
                x/=2;
            }
        }

        else
        {
            while(x!=n)
            {
               while(x%3==0)
            {
                ans++;
                x/=3;
            }

            while(x%2==0)
            {
                ans++;
                x/=2;
            }

            if(m==x)
            {
                flag=1;
                break;
            }

            }
        }
        if(flag==0)
        cout<<ans<<endl;

        else
            cout<<"-1"<<endl;
}


#include <iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
const int maxn=4*1e5+1;
int a[maxn];
using namespace std;
int main()
{
    int n;
    cin>>n;

    int ans=0;
    int cnt=0;

    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i+n]=a[i];
    }

    int pos=0;

    n*=2;
    while(pos!=n)
    {
        while(a[pos]==1)
        {
            if(pos==n)
            {
                break;
            }

            cnt++;
            pos++;
        }

        if(a[pos]==0)
        {
            if(pos==n)
            {
                break;
            }
            ans=max(ans,cnt);
            cnt=0;
            pos++;
        }
    }
      cout<<ans<<endl;
}


#include <iostream>
#include<vector>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int ans=0,curr=0;
    if(a[0]==1 && a[n-1]==1)
    {
        int j=0;
        while(a[j]==1)
        {
            ans++;
            j++;
        }
        j=n-1;
        while(a[j]==1)
        {
            ans++;
            j--;
        }
    }
    for(int i=0;i<a.size();i++)
    {
        curr=0;
        while(a[i]==1)
        {
            curr++;
            i++;
        }
        if(curr>ans)
            ans=curr;

    }
    cout<<ans<<endl;
    return 0;
}


#include<stdio.h>
#include<iostream>

using namespace std;
int max(int a, int b)
{
	if (a > b) return a;
	return b;
}
int main(void)
{
	int n, d, ans, i ;
	int a[200001];
	d = 0;
	ans = 0;
	cin >> n;
	for (i = 1; i <= n; i++) cin >> a[i];
	for (i = 1; i <= n; i++) {
		if (a[i] == 1) d++;
		else d = 0;
		ans = max(d, ans);
	}
	for (i = 1; i <= n; i++) {
		if (a[i] == 1) d++;
		else d = 0;
		ans = max(d, ans);
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdio>

using namespace std;
#define N 200005
int num[N*2];

 int main()
{
    int n;
    while(cin>>n)
    {
        int t;
        memset(num,0,sizeof(num));
        for(int i=0;i<n;i++)
        {
            cin>>num[i];
            num[i+n]=num[i];
        }
        int f=-1;
        int cnt=0;
        int ret=0;
        f=num[0];

        if(f==1)
        {
            cnt++;
        }
        for(int i=1;i<2*n;i++)
        {
            t=num[i];
            if(t==f)
            {
                if(f==1)
                {
                    cnt++;
                }
            }
            else
            {
                f=t;
                ret=max(ret,cnt);
                if(f==1)
                {
                    cnt=1;
                }
            }
        }

        cout<<ret<<endl;

    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdio>

using namespace std;
#define N 200005
int num[N];

 int main()
{
    int n;
    while(cin>>n)
    {
        int t;
        //memset(num,0,sizeof(num));
        int f=-1;
        int cnt=0;
        int ret=0;
        cin>>t;
        int tmp=t;
        f=t;
        if(f==1)
        {
            cnt++;
        }
        for(int i=1;i<n;i++)
        {
            cin>>t;
            if(t==f)
            {
                if(f==1)
                {
                    cnt++;
                }
            }
            else
            {
                f=t;
                ret=max(ret,cnt);
                if(f==1)
                {
                    cnt=1;
                }
            }
        }
        if(f==tmp&&f==1)
        {
            cnt++;
            ret=max(ret,cnt);
        }
        cout<<ret<<endl;

    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int arr[200010];
int main(void){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	int ans1=0;
	int i=0;
	for(;i<n;i++)
	{
		if(arr[i]==1)
			ans1++;
		else
			break;
	}
	int ans2=ans1;
	for(;i<n;i++)
	{
		int t=0;
		while(arr[i]==1)
		{
			t++;
			i++;
		}
		if(t>ans2)
			ans2=t;
	}
	for(i=n-1;i>=0;i--)
	{
		if(arr[i]==1)
			ans1++;
		else break;
	}
	printf("%d\n",max(ans1,ans2));
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<vector>
#define N 200003
using namespace std;
int main()
{
	int a[N];
	long n;
	cin>>n;
	long i=0;
	for(;i<n;i++)
        cin>>a[i];
    long m=0,temp=0,temp1=0;
    if(a[0]==1)
        m=1;
    for(i=1;i<n;i++){
        if(a[i]==1){
            if(a[i]==a[i-1]){
                m++;
			}
            else
                m=1;
		    if(temp<m)
				temp=m;
        }
        else
            m=0;
    }

	if(a[0]==a[n-1]&&a[0]==1){
        i=0;
        while(a[i++]==1&&i<n){}
        temp1=i-1;
        i=n-1;
        while(a[i--]==1&&i>0){}
        temp1+=n-i-2;
	}
	cout<<((temp>temp1)?temp:temp1)<<endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<vector>
#define N 200003
using namespace std;
int main()
{
	int a[N];
	long n;
	cin>>n;
	long i=0;
	for(;i<n;i++)
        cin>>a[i];
    long m=0,temp=0,temp1=0;
    if(a[0]==1)
	{ m=1;temp=1;}
    for(i=1;i<n;i++){
        if(a[i]==1){
            if(a[i]==a[i-1]){
                m++;
			}
            else
                m=1;
		    if(temp<m)
				temp=m;
        }
        else
            m=0;
    }

	if(a[0]==a[n-1]&&a[0]==1){
        i=0;
        while(a[i++]==1&&i<n){}
        temp1=i-1;
        i=n-1;
        while(a[i--]==1&&i>0){}
        temp1+=n-i-2;
	}
	cout<<((temp>temp1)?temp:temp1)<<endl;

    return 0;
}


#include<stdio.h>
int x[500000];
int s;
int n,m;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&x[i]);
	int con=0,ma=0;
	for(int i=0;i<=2*n;i++)
	{
		if(x[i%n]==0)
		{
			if (con>ma)ma=con;
			con=0;
		}else
		{
			con++;
		}
	}
	if (con>ma) ma=con;
	printf("%d",ma);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
int arr1[200005];
int arr2[200005];
int arr3[200005];
int main()
{
    int n;cin>>n;
    for(int i=0;i<n;i++) cin>>arr1[i];
    int x=0;
    int y=0;
    for(int i=0;i<n;i++) if(arr1[i]==0) arr2[x]=i,x++;
    for(int i=1;i<x;i++) arr3[y]=arr2[i]-arr1[i-1],y++;
    sort(arr3,arr3+y);
    int ans=arr3[y-1]-1;
    if(arr1[0]==1&&arr1[n-1]==1)
    {
        int i=1;
        int num=2;
        while(arr1[i]==1&&i<=n-2)
        {
            num++;
            i++;
        }
        i=n-2;
        while(arr1[i]==1&&i>=1)
        {
            num++;
            i--;
        }
        ans=max(ans,num);

    }
    cout<<ans<<endl;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int ans=0;
int n;
int arr[400005];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        arr[i+n]=arr[i];
    }
    int num=0;
    for(int i=0;i<2*n-1;i++)
    {
        if(arr[i]==1) num++;
        else ans=max(num,ans),num=0;
    }
    cout<<ans<<endl;
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    int a[200100];
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",a+i);
    }
    int st=0,ed=0,inmax=0;
    int max=0;
    for (int i = 0; i < n; i++)
    {
        if(a[i]==1)st=i+1;
        else break;
    }
    for (int i = n-1; i >= 0; i--)
    {
        if(a[i]==1) ed=n-i;
        else break;
    }
    for (int i = st; i < n; i++)
    {
        if(a[i]==1) inmax++;
        else{
            max=max>inmax?max:inmax;
            inmax=0;
        }
    }
    if(st+ed<n)
    max=max>st+ed?max:st+ed;
    printf("%d",max);

}


#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<bool>f;
	for (int i = 0; i < n; i++) {
		bool a;
		cin >> a;
		f.push_back(a);
	}
	int t = 0;
	int y = 0;
	for (int i = 0; i < n; i++) {
		if (f[i]) {
			y++;
			t = max(t, y);
		}
		else y = 0;
	}
	for(int i=0;i<n;i++) {
		if (f[i]) {
			y++;
			t = max(t, y);
		}
		else y = 0;
	}
	cout << t << endl;

}


#include <iostream>
#include <algorithm>
using namespace std;
long long n,a[200002],l,ans;
int main(){
	int i,j;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++){
		if(a[i]==1){
			l++;
		}
		else
			break;
	}
	for(i=n-1;i>=0;i--){
		if(a[i]==1){
			l++;
		}
		else
			break;
	}
	ans=l;
	for(l=0,i=0;i<n;i++){
		if(a[i]==1){
			l++;
		}
		else{
			ans=max(ans,l);
			l=0;
		}
	}
	cout<<ans<<endl;
//	system("pause");
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int N;
int A[200001];
int cnt;
int answer = 0;

int main(int argc,char** argv){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	A[N] = A[0];
	for(int i=0;i<=N;i++){
		if(A[i]==0){
			cnt = 0;
		}else{
			cnt++;
		}
		answer = max(answer, cnt);
	}

	cout << answer << "\n";

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int N;
int A[400000];
int cnt;
int answer = 0;

int main(int argc,char** argv){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
		A[i+N] = A[i];
	}
	for(int i=0;i<2*N;i++){
		if(A[i]==0){
			cnt = 0;
		}else{
			cnt++;
		}
		answer = max(answer, cnt);
	}

	cout << answer << "\n";

	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;
int a[200001];
int main() {
	int n, count = 0, num, max = 0, na = 0, ko = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] == 1) {
			count++;
		}
		else {
			if (max < count) {
				max = count;
			}
			count = 0;
		}
	}
	int i = 1;
	while (a[i] != 0) {
		na++;
		i++;
	}
	i = n;
	while (a[i] != 0) {
		ko++;
		i--;
	}
	if (na + ko > max) {
		max = na + ko;
	}
	cout << max;
}


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

 int n;

 cin >> n;
 int result = 1;
 int *a = new int[n];
 vector<int> v;

 for ( int i = 0; i < n; i++)
 cin >> a[i];
 int k = 0;
 for(int i = 0; i < n; i++)
 {
   if (a[i] == 0)
       k++;
  else continue;
 }
 if (k == n)
 cout << 0 << endl;

 else
 {
 for (int i = 1; i < n; i++)
 {
  if (a[i] == 1 && a[i-1] == 1)
  {
      result = result + 1;
      v.push_back(result);
  }

  else result = 1;

  }
 int max = -1;

 for ( int i = 0; i < v.size(); i++)
  {

    if(v[i] > max)

    max = v[i];
  }
  if (a[0] != 0 && a[n - 1]!= 0)
  {
      int c = 2;
      int i = n - 2;
      while (a[i] != 0)
        {
          if (a[i] == 1)
              c++;
          i--;
        }
        i = 1;
        while (a[i] != 0)
           {
             if (a[i] == 1)
                 c++;
             i++;
           }

           if (c > max)
           cout << c;
           else cout << max;

  }

  else cout << max << endl;
}
return 0;
}


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

 int n;

 cin >> n;
 int result = 1;
 int *a = new int[n];
 vector<int> v;

 for ( int i = 0; i < n; i++)
 cin >> a[i];
 int k = 0;
 for(int i = 0; i < n; i++)
 {
   if (a[i] == 0)
       k++;
  else continue;
 }
 if (k == n)
 cout << 0 << endl;

 else
 {
 for (int i = 1; i < n; i++)
 {
  if (a[i] == 1 && a[i-1] == 1)
  {
      result = result + 1;
      v.push_back(result);
  }

  else
  {
  result = 1;
  v.push_back(1);
}
  }
 int max = -1;

 for ( int i = 0; i < v.size(); i++)
  {

    if(v[i] > max)

    max = v[i];
  }
  if (a[0] != 0 && a[n - 1]!= 0)
  {
      int c = 2;
      int i = n - 2;
      while (a[i] != 0)
        {
          if (a[i] == 1)
              c++;
          i--;
        }
        i = 1;
        while (a[i] != 0)
           {
             if (a[i] == 1)
                 c++;
             i++;
           }

           if (c > max)
           cout << c;
           else cout << max;

  }

  else cout << max << endl;
}
return 0;
}


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

 int n;

 cin >> n;
 int result = 1;
 int *a = new int[n];
 vector<int> v;

 for ( int i = 0; i < n; i++)
 cin >> a[i];
 int k = 0;
 for(int i = 0; i < n; i++)
 {
   if (a[i] == 0)
       k++;
  else continue;
 }
 if (k == n)
 cout << 0 << endl;

 else
 {

 for (int i = 0; i < n; i++)
 {
  if (a[i] == 1 && a[i-1] == 1)
      result = result + 1;

  else
  {
  v.push_back(result);
  result = 1;
  }

  }
 int max = -1;

 for ( int i = 0; i < v.size(); i++)
  {
    if(v[i] > max)
    max = v[i];
  }
  if (a[0] != 0 && a[n - 1]!= 0)
  {
      int c = 2;
      int i = n - 2;
      while (a[i] != 0)
        {
          if (a[i] == 1)
              c++;
          i--;
        }
        i = 1;
        while (a[i] != 0)
           {
             if (a[i] == 1)
                 c++;
             i++;
           }

           if (c > max)
           cout << c;
           else cout << max;

  }

  else cout << max << endl;
}
return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[200005];
int main()
{
	int n,cnt=0,l=0;
	cin>>n;
	while(n--)
	{
		int m;
		cin>>m;
		if(!m)
		{
			a[l++]=cnt;
			cnt=0;
		}
		if(m)
			cnt++;
	}
	a[l++]=cnt;
	int y=a[0];
	a[0]+=a[l-1];
	a[l-1]+=y;
	sort(a,a+l);
	cout<<a[l-1];
}


#include <iostream>
const int SIZE = 200000;

using namespace std;

int main ()
{
	int n, i, cnt = 0, cntl = 0;
	int a[SIZE];

	cin >> n;

	for (i = 0; i < n; i++)
		cin >> a[i];

	for (i = 0; i < n; i++){
		if (a[i] == 1)
			cntl++;
		else{
			if (cntl > cnt)
				cnt = cntl;
			cntl = 0;
		}

	}

	for (i = 0; i < n;i++)
		if (a[i] == 1)
			cntl++;
		else
			break;

	if (cntl > cnt)
		cout << cntl;
	else
		cout << cnt;
}


#include <iostream>
const int SIZE = 100000;

using namespace std;

int main ()
{
	int n, i, cnt = 0, cntl = 0, c = 0;
	int a[SIZE];

	cin >> n;

	for (i = 0; i < n; i++)
		cin >> a[i];

	for (i = 0; i < n; i++){
		if (a[i] == 1)
			cntl++;
		else{
			if (cntl > cnt)
				cnt = cntl;
			cntl = 0;
		}

	}

	for (i = 0; i < n;i++)
		if (a[i] == 1)
			cntl++;
		else
			break;

	if (cntl > cnt)
		cout << cntl;
	else
		cout << cnt;
}


#include <iostream>
const int SIZE = 100000;

using namespace std;

int main ()
{
	int n, i, cnt = 0, cntl = 0, c = 0;
	int a[SIZE];

	cin >> n;

	for (i = 0; i < n; i++){
		cin >> a[i];
		if (a[i] == 1)
			cntl++;
		else
			if (cntl > cnt){
				cnt = cntl;
				cntl = 0;
			}
	}

	i = 0;

	while (a[i] != 0){
		c++;
		i++;
	}

	i = n;

	while (a[i] != 0){
		c++;
		i--;
	}

	if (c > cnt)
		cout << c - 1;
	else
		cout << cnt;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#define INF -10000
using namespace std;
bool visit[100];
int list[100];
int a[30005];
//void back(int input[], int n, int sum, int key, int size)
//{
//	if(sum==key) {
//		int idx=1;
//		for(int j=0; j<=n; j++) {
//			if(visit[j])
//			    list[idx++] = input[j];
//		}
//		return ;
//	}
//	for(int i = n; i<size; i++) {
//			if (!visit[i]) {
//				sum += input[i];
//				visit[i] = true;
//				if (i != size - 1) {
//					back(input, i + 1, sum, key,size);
//				} else {
//					back(input, i, sum, key,size);
//				}
//				visit[i] = false;
//				sum -= input[i];
//
//				// �ظ���Ԫ��ֻͳ��һ�Σ����������ظ������β�����ǰ���ǣ������Ѿ��������Բ���input����������õģ�
//				while (i < size - 1 && input[i] == input[i + 1]) {
//					i++;
//				}
//			}
//
//	}
//}
int main()
{
    int n;
    int i, j, t, max,flag,flag2;
    cin>>n;
    for(i=0; i<n; i++) cin>>a[i];
    for(i=0,max=0; i<n; i++) {
    	    t=0;
    		while(a[i] == 1) {
    			t++;
    			i++;
			}
		if(max <= t) max = t;
	}
	i=n-1;
	t=0;
	flag2=0;
	while(a[i] == 1) {
		flag2 = 1;
		t++;
		i--;
	}
	if(a[0] == 1&&flag2 == 1) t++;
	if(t > max) max = t;
    cout<<max<<endl;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#define INF -10000
using namespace std;
bool visit[100];
int list[100];
int a[300005];
//void back(int input[], int n, int sum, int key, int size)
//{
//	if(sum==key) {
//		int idx=1;
//		for(int j=0; j<=n; j++) {
//			if(visit[j])
//			    list[idx++] = input[j];
//		}
//		return ;
//	}
//	for(int i = n; i<size; i++) {
//			if (!visit[i]) {
//				sum += input[i];
//				visit[i] = true;
//				if (i != size - 1) {
//					back(input, i + 1, sum, key,size);
//				} else {
//					back(input, i, sum, key,size);
//				}
//				visit[i] = false;
//				sum -= input[i];
//
//				// �ظ���Ԫ��ֻͳ��һ�Σ����������ظ������β�����ǰ���ǣ������Ѿ��������Բ���input����������õģ�
//				while (i < size - 1 && input[i] == input[i + 1]) {
//					i++;
//				}
//			}
//
//	}
//}
int main()
{
    int n;
    int i, j, t, max,flag,flag2;
    cin>>n;
    for(i=0; i<n; i++) cin>>a[i];
    for(i=0,max=0; i<n; i++) {
    	    t=0;
    		while(a[i] == 1) {
    			t++;
    			i++;
			}
		if(max <= t) max = t;
	}
	i=n-1;
	t=0;
	flag2=0;
	while(a[i] == 1) {
		flag2 = 1;
		t++;
		i--;
	}
	if(a[0] == 1&&flag2 == 1) t++;
	if(t > max) max = t;
    cout<<max<<endl;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#define INF -10000
using namespace std;
bool visit[100];
int list[100];
int a[300005];
//void back(int input[], int n, int sum, int key, int size)
//{
//	if(sum==key) {
//		int idx=1;
//		for(int j=0; j<=n; j++) {
//			if(visit[j])
//			    list[idx++] = input[j];
//		}
//		return ;
//	}
//	for(int i = n; i<size; i++) {
//			if (!visit[i]) {
//				sum += input[i];
//				visit[i] = true;
//				if (i != size - 1) {
//					back(input, i + 1, sum, key,size);
//				} else {
//					back(input, i, sum, key,size);
//				}
//				visit[i] = false;
//				sum -= input[i];
//
//				// �ظ���Ԫ��ֻͳ��һ�Σ����������ظ������β�����ǰ���ǣ������Ѿ��������Բ���input����������õģ�
//				while (i < size - 1 && input[i] == input[i + 1]) {
//					i++;
//				}
//			}
//
//	}
//}
int main()
{
    int n;
    int i, j, t1,t2,t3, max=0,flag,flag2;
    cin>>n;
    for(i=0; i<n; i++) cin>>a[i];
    for(i=0,t1=0; i<n; i++) {
    	    int t=0;
    		while(a[i] == 1) {
    			t++;
    			i++;
			}
		if(t1 <= t) t1 = t;
	}
	i=0;
	t2=0;
	while(a[i] == 1) {
		t2++;
		i++;
	}
	i=n-1;
	t3=0;
	while(a[i] == 1) {
		t3++;
		i--;
	}
	if(t1 >= (t2 + t3)) max = t1;
	if(t1 < (t2 + t3)) max = t2 + t3;
	cout<<max<<endl;
}


#include <iostream>

using namespace std;

int main()
{
	int n, a[200001];

	cin >> n;

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

	a[n] = a[0];

	int max_cnt = 0, cnt = 0;

	for (int i = 0; i < n + 1; i++)
		if (a[i] == 1)
			cnt++;
		else
		{
			max_cnt = max (max_cnt, cnt);
			cnt = 0;
		}

	max_cnt = max (max_cnt, cnt);

	cout << max_cnt;
}


#include <iostream>

using namespace std;

int main()
{
	int n, a[200000];

	cin >> n;

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

	int max_cnt = 0, cnt = 0;

	for (int i = 0; i < n; i++)
		if (a[i] == 1)
			cnt++;
		else
		{
			max_cnt = max (max_cnt, cnt);
			cnt = 0;
		}

	for (int i = 0; i < n; i++)
		if (a[i] == 1)
			cnt++;
		else
			break;

	max_cnt = max (max_cnt, cnt);

	cout << max_cnt;
}


#include <iostream>

using namespace std;

int main()
{
	int n, a[200000];

	cin >> n;

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

	int max_cnt = 0, cnt = 0;

	for (int i = 0; i < n; i++)
		if (a[i] == 1)
			cnt++;
		else
		{
			max_cnt = max (max_cnt, cnt);
			cnt = 0;
		}

	if (a[0] == 1)
			cnt++;

	max_cnt = max (max_cnt, cnt);

	cout << max_cnt;
}


#include<iostream>
using namespace std;

int main() {
	int t;
	cin >> t;
	int x;
	int x_start = 0;
	int count = 0;
	int max = 0;
	int i = 0;
	for (i = 0; i < t; i++) {
		cin >> x;
		if (x) {
			x_start++;
			count++;
		}
		else {
			count = 0;
			break;
		}
		if (count > max) max = count;
	}
	for (i++; i < t; i++) {
		cin >> x;
		if (x) {
			count++;
		}
		else {
			count = 0;
		}
		if (count > max) max = count;
	}
	if (x) {
		count += x_start;
		if (count > max) max = count;
	}
	cout << max << endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <math.h>
#include <vector>
#include <utility>
using namespace std;
const int maxn=400010;
typedef _int64 ll;
int max(int a,int b){return a>b?a:b;}
int a[maxn];
int main()
{
#ifdef _DEBUG
	freopen("in.txt","r",stdin);
#endif
	int n,i;
	while(cin>>n)
	{
		for( i = 0 ; i < n ; i++)
			cin>>a[i];
		for( i = n ; i < 2*n ; i++)
			a[i]=a[i-n];
		int ans=0,cnt=0;
		for( i = 0 ; i < 2*n ; i++)
		{
			if(a[i]==0)
			{
				cnt++;
			}
			else
			{
				ans=max(ans,cnt);
				cnt=0;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <math.h>
#include <vector>
#include <utility>
using namespace std;
const int maxn=400010;
typedef _int64 ll;
int max(int a,int b){return a>b?a:b;}
int a[maxn];
int main()
{
#ifdef _DEBUG
	freopen("in.txt","r",stdin);
#endif
	int n,i;
	while(cin>>n)
	{
		for( i = 0 ; i < n ; i++)
			cin>>a[i];
		for( i = n ; i < 2*n ; i++)
			a[i]=a[i-n];
		int ans=0,cnt=0;
		for( i = 0 ; i < 2*n ; i++)
		{
			if(a[i]==1)
			{
				cnt++;
			}
			else
			{
				ans=max(ans,cnt);
				cnt=0;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

void main()
{
	int n;

	vector<int> arr;
	cin >> n;
	int c;

	for (int i = 0; i < n; i++)
	{
		cin >> c;
		arr.push_back(c);
	}

	int maxRestHour = 0;
	int restHour = 0;

	for (int i = 0; i < n * 3; i++)
	{
		if (arr[i%n] == 1)
			restHour += 1;
		else
		{
			if (restHour > maxRestHour)
				maxRestHour = restHour;
			restHour = 0;
		}
	}

	cout << maxRestHour;

	system("pause");
}


#include <iostream>
#include <vector>

using namespace std;

void main()
{
	int n;

	vector<int> arr;
	cin >> n;
	int c;

	for (int i = 0; i < n; i++)
	{
		cin >> c;
		arr.push_back(c);
	}

	int maxRestHour = 0;
	int restHour = 0;

	for (int i = 0; i < n * 3; i++)
	{
		if (arr[i%n] == 1)
			restHour += 1;
		else
		{
			if (restHour > maxRestHour)
				maxRestHour = restHour;
			restHour = 0;
		}
	}

	cout << maxRestHour;

}


#include <stdio.h>
using namespace std;

int add(int* mas, int cur)
{
	int i = 0;
	while (mas[i] == 1)
	{
		cur++;	i++;
	}
	return cur;
}

int main()
{
	int n, best = 0, cur;	scanf_s("%d", &n);
	int* mas = new int[n];

	for (int i = 0; i < n; i++)
		scanf_s("%d", &mas[i]);

	int i = 0;
	while (i < n)
	{
		cur = 0;
		while (mas[i] == 1)
		{
			cur++;
			i++;
		}
		if (cur > best)	best = cur;
		i++;
	}

	if (i >= n && mas[n - 1] == 1)
	{
		cur = add(mas, cur);
		if (cur > best)	best = cur;
	}

	printf("%d", best);
	delete[] mas;
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<iostream>
using namespace std;
const int N=2e5;
int main()
{
    int n,a[N+5],i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    j=0;int ma=0;
    for(i=0;i<n;i++)
    {
        if(a[i]==1)
            j++;
        else
        {
            if(j>ma)
                ma=j;
            j=0;
        }
    }if(a[0]==1&&a[n-1]==1)
    {
        j=0;
        for(i=0;i<n;i++)
        {
            if(a[i]==1)
                j++;
            else
                break;
        }for(i=n-1;i>=0;i--)
        {
            if(a[i]==1)
                j++;
            else
                break;
        }
    }printf("%d",max(ma,j));
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

#define ff first
#define ss second
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

//5058144A604A6214584F145662144C584D4E ^-^

ll gcd(ll a, ll b) {
	while (a != 0 && b != 0) {
		if (a > b) {
			a %= b;
		}
		else if (a < b) {
			b %= a;
		}
		else {
			return a;
		}
	}
	return a + b;
}

ll divS(ll a) {
	ll res = 0;
	while (a > 0) {
		res += a % 10;
		a /= 10;
	}
	return res;
}

struct word {
	string data;
	int count;
};

int main() {
	ios_base::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, i = 1, k = 1, m = 0;
	cin >> n;

	vi a(n);
	int lCount = 0, rCount = 0;
	cin >> a[0];
	if (a[0] == 1) {
		lCount = 1;
		while (a[i] == 1) {
			cin >> a[i];
			lCount++;
			i++;
		}
	}
	else i = 1;
	for (int j = i; j < n; j++) {
		cin >> a[j];
		if (a[j] == a[j - 1] && a[j] != 0) {
			k++;
		}
		else {
			m = max(k, m);
			k = 1;
		}
	}
	if (a[n - 1] == a[0] && a[0] != 0) {
		int j = n - 1;
		while (a[j] == a[0]) {
			rCount++;
			j--;
		}
	}
	cout << max(m, (lCount + rCount));
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

#define ff first
#define ss second
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

//5058144A604A6214584F145662144C584D4E ^-^

ll gcd(ll a, ll b) {
	while (a != 0 && b != 0) {
		if (a > b) {
			a %= b;
		}
		else if (a < b) {
			b %= a;
		}
		else {
			return a;
		}
	}
	return a + b;
}

ll divS(ll a) {
	ll res = 0;
	while (a > 0) {
		res += a % 10;
		a /= 10;
	}
	return res;
}

struct word {
	string data;
	int count;
};

int main() {
	ios_base::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, k = 1, m = 1, first, firstCount, lastCount = 0;
	bool b;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	if (a[0] == a[n - 1]) {
		b = true;
		first = a[0];
		firstCount = 1;
		int i = 1;
		while (a[i] == first) {
			firstCount++;
			i++;
			if (i == n) {
				cout << firstCount;
				return 0;
			}
		}
	}

	repn(i, 1, n) {
		if (a[i] == a[i - 1]) {
			k++;
		}
		else {
			m = max(m, k);
			k = 1;
		}
	}
	int i = n - 1;
	if (b) {
		while (a[i] == first) {
			lastCount++;
			i--;
		}
	}
	cout << max(m, (lastCount + firstCount));
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

#define ff first
#define ss second
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

//5058144A604A6214584F145662144C584D4E ^-^

ll gcd(ll a, ll b) {
	while (a != 0 && b != 0) {
		if (a > b) {
			a %= b;
		}
		else if (a < b) {
			b %= a;
		}
		else {
			return a;
		}
	}
	return a + b;
}

ll divS(ll a) {
	ll res = 0;
	while (a > 0) {
		res += a % 10;
		a /= 10;
	}
	return res;
}

struct word {
	string data;
	int count;
};

int main() {
	ios_base::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, i = 1, k = 1, m = 0;
	cin >> n;

	vi a(n);
	int lCount = 0, rCount = 0;
	cin >> a[0];
	if (a[0] == 1) {
		lCount = 1;
		while (a[i] == 1) {
			cin >> a[i];
			lCount++;
			i++;
		}
	}
	else i = 1;
	for (int j = i; j < n; j++) {
		cin >> a[j];
		if (a[j] == a[j - 1]) {
			k++;
		}
		else {
			m = max(k, m);
			k = 1;
		}
	}
	if (a[n - 1] == a[0] && a[0] != 0) {
		int j = n - 1;
		while (a[j] == a[0]) {
			rCount++;
			j--;
		}
	}
	cout << max(m, (lCount + rCount));
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

#define ff first
#define ss second
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

//5058144A604A6214584F145662144C584D4E ^-^

ll gcd(ll a, ll b) {
	while (a != 0 && b != 0) {
		if (a > b) {
			a %= b;
		}
		else if (a < b) {
			b %= a;
		}
		else {
			return a;
		}
	}
	return a + b;
}

ll divS(ll a) {
	ll res = 0;
	while (a > 0) {
		res += a % 10;
		a /= 10;
	}
	return res;
}

struct word {
	string data;
	int count;
};

int main() {
	ios_base::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, lCount = 0, rCount = 0, j = 0;
	cin >> n;
	vi a(n);
	bool b = false;
	rep(i, n) {
		cin >> a[i];
		if (!b && a[i] == 1) {
			b = !b;
		}
	}
	if (!b) {
		cout << 0;
		return 0;
	}
	if (a[0] == 1) {
		j = 0;
		while (a[j] == 1) {
			lCount++;
			j++;
			if (j == n - 1) {
				cout << lCount;
				return 0;
			}
		}
	}
	else j = 1;
	int k = 1, m = 1;
	for (int i = j; i < n; i++) {
		if (a[i] == a[i - 1] && a[i] != 0) {
			k++;
		}
		else {
			k = 1;
		}
		m = max(m, k);
	}
	if (a[0] * a[n - 1] == 1) {
		j = n - 1;
		while (a[j] == 1) {
			rCount++;
			j--;
		}
	}
	cout << max(m, (lCount + rCount));
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

#define ff first
#define ss second
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

//5058144A604A6214584F145662144C584D4E ^-^

ll gcd(ll a, ll b) {
	while (a != 0 && b != 0) {
		if (a > b) {
			a %= b;
		}
		else if (a < b) {
			b %= a;
		}
		else {
			return a;
		}
	}
	return a + b;
}

ll divS(ll a) {
	ll res = 0;
	while (a > 0) {
		res += a % 10;
		a /= 10;
	}
	return res;
}

struct word {
	string data;
	int count;
};

int main() {
	ios_base::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, i = 1, k = 1, m = 1;
	cin >> n;

	vi a(n);
	int lCount = 0, rCount = 0;
	cin >> a[0];
	if (a[0] == 1) {
		lCount = 1;
		while (a[i] == 1) {
			cin >> a[i];
			lCount++;
			i++;
		}
	}
	else i = 1;
	for (int j = i; j < n; j++) {
		cin >> a[j];
		if (a[j] == a[j - 1] && a[j] != 0) {
			k++;
		}
		else {
			m = max(k, m);
			k = 1;
		}
	}
	if (a[n - 1] == a[0] && a[0] != 0) {
		int j = n - 1;
		while (a[j] == a[0]) {
			rCount++;
			j--;
		}
	}
	cout << max(m, (lCount + rCount));
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

#define ff first
#define ss second
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

//5058144A604A6214584F145662144C584D4E ^-^

ll gcd(ll a, ll b) {
	while (a != 0 && b != 0) {
		if (a > b) {
			a %= b;
		}
		else if (a < b) {
			b %= a;
		}
		else {
			return a;
		}
	}
	return a + b;
}

ll divS(ll a) {
	ll res = 0;
	while (a > 0) {
		res += a % 10;
		a /= 10;
	}
	return res;
}

struct word {
	string data;
	int count;
};

int main() {
	ios_base::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, i = 1, k = 0, m = 0;
	cin >> n;

	vi a(n);
	int lCount = 0, rCount = 0;
	cin >> a[0];
	if (a[0] == 1) {
		lCount = 1;
		while (a[i] == 1) {
			cin >> a[i];
			lCount++;
			i++;
		}
	}
	else i = 1;
	for (int j = i; j < n; j++) {
		cin >> a[j];
		if (a[j] == a[j - 1] && a[j] != 0) {
			k++;
		}
		else {
			m = max(k, m);
			k = 0;
		}
	}
	if (a[n - 1] == a[0] && a[0] != 0) {
		int j = n - 1;
		while (a[j] == a[0]) {
			rCount++;
			j--;
		}
	}
	cout << max(m, (lCount + rCount));
	return 0;
}


#include <iostream>
typedef long long ll;
using namespace std;
int a[400005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=n+1;i<=2*n;i++)a[i]=a[i-n];
    int cnt=1;
    int ans=0;
    for(int i=1;i<=2*n;i++)
    {
        if(a[i]==1&&a[i-1]==1)cnt++;
        else cnt=1;
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
typedef long long ll;
using namespace std;
int a[400005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=n+1;i<=2*n;i++)a[i]=a[i-n];
    int cnt=0;
    int ans=0;
    int flag=0;
    for(int i=1;i<=2*n;i++)
    {
        if(a[i]==1)flag=1;
        if(a[i]==1&&a[i-1]==1)cnt++;
        else cnt=0;
        ans=max(ans,cnt);
    }
    if(flag)cout<<ans+1<<endl;
    else cout<<ans<<endl;
    return 0;
}


#include <iostream>
typedef long long ll;
using namespace std;
int a[400005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=n+1;i<=2*n;i++)a[i]=a[i-n];
    int cnt=0;
    int ans=0;
    for(int i=1;i<=2*n;i++)
    {
        if(a[i]==1&&a[i-1]==1)cnt++;
        else cnt=0;
        ans=max(ans,cnt);
    }
    if(ans==0)cout<<ans<<endl;
    else
    cout<<ans+1<<endl;
    return 0;
}


#include<stdio.h>
#include<algorithm>

using namespace std;

int we[200100];

int main()
{
	int n;
	int i;
	int now;
	int mx = 0 ;
	scanf("%d",&n);

	we[0] = 0;

	for( i = 1 ; i <= n ; i++ )
	{
		scanf("%d",&now);

		if( now == 1 )
			we[i] = we[i-1] + 1;
		else
			we[i] = 0;

		mx = max( mx , we[i] );
	}

	int fst = 0;
	int lst = 0;

	i = 1;
	bool t1 = false;
	bool t2 = false;

	while( !( t1 && t2 ) && i < n - i + 1 )
	{
		if( !t1 && we[i] != 0 )
			fst++;
		else
			t1 = true;

		if( !t2 && we[ n - i + 1 ] != 0 )
			lst++;
		else
			t2 = true;

		i++;
	}

	printf("%d", max( lst + fst , mx ) );
}


#include<stdio.h>
#include<algorithm>

using namespace std;

int arr[200010];

int main()
{
	int n;
	int i;
	int mx = 0;

	scanf("%d",&n );

	arr[0] =0;

	for( i = 1 ; i <= n ; i++ )
	{
		scanf("%d",&arr[i] );

		if( arr[i] == 1 )
			arr[i] += arr[i-1];
		else
			arr[i] = 0;

		mx = max( arr[i] , mx );
	}

	if( arr[n] != 0 && arr[1] != 0 )
	{
		for( i = 1 ; i <= n ; i++ )
		{
			if( arr[i] == 0 )
				break;
		}

		mx = max( arr[n] + arr[i-1] , mx );
	}

	printf("%d",mx );
}


#include<stdio.h>
#include<algorithm>

using namespace std;

int we[200100];

int main()
{
	int n;
	int i;
	int now;
	int mx = 0 ;
	scanf("%d",&n);

	we[0] = 0;

	for( i = 1 ; i <= n ; i++ )
	{
		scanf("%d",&now);

		if( now == 1 )
			we[i] = we[i-1] + 1;
		else
			we[i] = 0;

		mx = max( mx , we[i] );
	}

	int fst = 0;
	int lst = 0;

	i = 1;
	bool t1 = false;
	bool t2 = false;

	while( !( t1 && t2 ) )
	{
		if( !t1 && !t2 && i == n - i + 1 )
			break;

		if( !t1 && we[i] != 0 )
			fst++;
		else
			t1 = true;

		if( !t2 && we[ n - i + 1 ] != 0 )
			lst++;
		else
			t2 = true;

		i++;
	}

	printf("%d", max( lst + fst , mx ) );
}


#include <iostream>
#include <algorithm>

using namespace std;

int arr[400002];
int main()
{
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	for (int i = n; i < 2 * n; i++)
	{
		arr[i] = arr[i - n];
	}
	int maxx = 0;
	int cnt = 0;
	for (int i = 0; i < 2 * n; i++)
	{
		if (arr[i] == 1)
		{
			cnt++;
		}
		else
		{
			cnt = 0;
		}
		maxx = max(cnt, maxx);
	}
	cout << maxx;

	return 0;
}


#include <iostream>
#include<algorithm>
#include <string>
#include<sstream>
#include <iomanip>
#include <cmath>
#include <math.h>
#include <functional>
#include <ostream>
#include <set>
#include <iterator>
#include <vector>
#include <cctype>
#include <map>
//#include <bits/stdc++.h>
#define pi 3.14159265359;

using namespace std;

int main()
{
	int x;
	int arr[1001];

	cin >> x;
	int counter = 1;
	int max = 0;

	for (int i = 0; i < x; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < x; i++)
	{
		if (arr[i] == 1) {

			if (arr[i] == arr[i + 1]) {
				counter++;
				if (counter >= max) {
					max = counter;
				}

			}
			else if (arr[i] == 1 && arr[x - 1] == 1 && max <= 2) {
				max = 2;
			}
			else
				counter = 1;
		}

	}
	cout << max << endl;

	return 0;
}


#include <iostream>
#include<algorithm>
#include <string>
#include<sstream>
#include <iomanip>
#include <cmath>
#include <math.h>
#include <functional>
#include <ostream>
#include <set>
#include <iterator>
#include <vector>
#include <cctype>
#include <map>
//#include <bits/stdc++.h>
#define pi 3.14159265359;

using namespace std;

int main()
{
	long long  x;
	cin >> x;
	long long * arr = new long long [x];

	int counter = 0;
	int max = 0;

	for (int i = 0; i < x; i++)
	{
		cin >> arr[i];
		arr[i + x] = arr[i];
	}
	for (int i = 0; i < 2*x; i++)
	{

			if (arr[i] == 1) {
				counter++;
				if (counter >= max) {
					max = counter;
				}
			}
			else counter = 0;

	}
	cout << max << endl;
	delete[] arr;
	return 0;
}


#include <iostream>
#include<algorithm>
#include <string>
#include<sstream>
#include <iomanip>
#include <cmath>
#include <math.h>
#include <functional>
#include <ostream>
#include <set>
#include <iterator>
#include <vector>
#include <cctype>
#include <map>
//#include <bits/stdc++.h>
#define pi 3.14159265359;

using namespace std;

int main()
{
	int x;
	int arr[1001];

	cin >> x;
	int counter = 0;
	int max = 0;

	for (int i = 0; i < x; i++)
	{
		cin >> arr[i];
		arr[i + x] = arr[i];
	}
	for (int i = 0; i < 2*x; i++)
	{

			if (arr[i] == 1) {
				counter++;
				if (counter >= max) {
					max = counter;
				}
			}
			else counter = 0;

	}
	cout << max << endl;

	return 0;
}


#include <iostream>
#include<algorithm>
#include <string>
#include<sstream>
#include <iomanip>
#include <cmath>
#include <math.h>
#include <functional>
#include <ostream>
#include <set>
#include <iterator>
#include <vector>
#include <cctype>
#include <map>
//#include <bits/stdc++.h>
#define pi 3.14159265359;

using namespace std;

int main()
{
	long long  x;
	cin >> x;
	long long * arr = new long long [2*x];

	int counter = 0;
	int max = 0;

	for (int i = 0; i < x; i++)
	{
		cin >> arr[i];
		arr[i + x] = arr[i];
	}
	for (int i = 0; i < 2*x; i++)
	{

			if (arr[i] == 1) {
				counter++;
				if (counter >= max) {
					max = counter;
				}
			}
			else counter = 0;

	}
	cout << max << endl;
	delete[] arr;
	return 0;
}


#include<iostream>
using namespace std;

int main() {
	char danil[] = { 'D', 'a', 'n', 'i', 'l' };
	char olya[] = { 'O', 'l', 'y', 'a' };
	char slave[] = { 'S','l','a','v','a' };
	char ann[] = { 'A','n','n' };
	char nikita[] = { 'N','i','k','i','t','a' };

	char *str = new char[100];
	bool flag = false, flag2 = false;
	cin >> str;
	int d = 0, o = 0, s = 0, n = 0, a = 0;
	for (int i = 0; str[i] != '\0'; i++) {
		if (str[i] == danil[d]) {
			d++;
			if (d == 5) {
				if (flag == true)
					flag2 = true;
				flag = true;
				d = 0;
			}
		}
		else if (str[i] == danil[d-1] && !flag) {
			d = 1;
		}
		else {
			d = 0;
			if (str[i] == danil[d]) {
				d++;
				if (d == 5) {
					if (flag == true)
						flag2 = true;
					flag = true;
					d = 0;
				}
			}
		}
		if (str[i] == ann[a]) {
			a++;
			if (a == 3) {
				if (flag == true)
					flag2 = true;
				flag = true;
				a = 0;
			}
		}
		else if (str[i] == ann[a-1] && !flag) {
			a = 1;
		}
		else {
			a = 0;
			if (str[i] == ann[a]) {
				a++;
				if (a == 3) {
					if (flag == true)
						flag2 = true;
					flag = true;
					a = 0;
				}
			}
		}
		 if (str[i] == olya[o]) {
			 o++;
			 if (o == 4) {
				 if (flag == true)
					 flag2 = true;
				 flag = true;
				 o = 0;
			 }
		}
		 else if (str[i] == olya[o-1] && !flag) {
			 o = 1;
		 }
		 else {
			 o = 0;
			 if (str[i] == olya[o]) {
				 o++;
				 if (o == 4) {
					 if (flag == true)
						 flag2 = true;
					 flag = true;
					 o = 0;
				 }
			 }
		 }
		 if (str[i] == slave[s]) {
			 s++;
			 if (s == 5) {
				 if (flag == true)
					 flag2 = true;
				 flag = true;
				 s = 0;
			 }
		 }
		 else if (str[i] == slave[s-1] && !flag) {
			 s = 1;
		 }
		 else {
			 s = 0;
			 if (str[i] == slave[s]) {
				 s++;
				 if (s == 5) {
					 if (flag == true)
						 flag2 = true;
					 flag = true;
					 s = 0;
				 }
			 }
		 }
		 if (str[i] == nikita[n]) {
			 n++;
			 if (n == 6) {
				 if (flag == true)
					 flag2 = true;
				 flag = true;
				 n = 0;
			 }
		 }
		 else if (str[i] == nikita[n - 1] && !flag) {
			 n = 1;
		 }
		 else {
			 n = 0;
			 if (str[i] == nikita[n]) {
				 n++;
				 if (n == 6) {
					 if (flag == true)
						 flag2 = true;
					 flag = true;
					 n = 0;
				 }
			 }
		 }
	}
	if (flag && flag2)
		cout << "NO" << endl;

	else if (flag)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	//system("pause");
	return 0;
}


int main() {
	int c;
	cin >> c;
	int *nums = new int[c];
	for (int i = 0; i < c; i++)
		cin >> nums[i];
	int max_rest = 0, rest = 0;
	bool flag = 0;
	for (int i = 0; i < c; i++) {
		if (nums[i] == 1)
			rest++;
		else {
			if (max_rest < rest)
				max_rest = rest;
			rest = 0;
		}
		if (i == c - 1 && !flag) {
			i = -1;
			flag = true;
		}
	}
	cout << max_rest << endl;

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

int main() {
	int c;
	cin >> c;
	int *nums = new int[c];
	for (int i = 0; i < c; i++)
		cin >> nums[i];
	int max_rest = 0, rest = 0;
	bool flag = 0;
	for (int i = 0; i < c; i++) {
		if (nums[i] == 1)
			rest++;
		else {
			if (max_rest < rest)
				max_rest = rest;
			rest = 0;
		}
		if (i == c - 1 && !flag) {
			i = -1;
			flag = true;
		}
	}
	cout << max_rest << endl;

	//system("pause");
	return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
    int temp=0,max=0,max2=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i])temp++;
        if(!arr[i]){
            if(max<temp)
            max=temp;
            temp=0;
        }
    }
    if(max<=temp)max=temp;
    if(arr[n-1]==1)
    {
        max2=1;
        for(int i=0;i<n;i++)
        {
        if(arr[i])max2++;
        else break;
        }
    }
    if(max>=max2)cout<<max;
    else cout<<max2;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
     int temp=0,max=0,max2=1;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i])temp++;
        else{
            max=temp;
            temp=0;
        }
    }
    if(arr[n-1]==1)for(int i=0;i<n;i++)if(arr[i])max2++;
    if(max<=max2)cout<<max2;
    else cout<<max;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
    int temp=0,max=0,max2=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i])temp++;
        else{
            if(max<temp)
            max=temp;
            temp=0;
        }
    }
    if(arr[n-1]==1)
    {
        max2=1;
        for(int i=0;i<n;i++)
        {
        if(arr[i])max2++;
        else break;
        }
    }
    if(max>=max2)cout<<max;
    else cout<<max2;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
     int *count=new int[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        count[i]=0;
    }

    for(int i=0;i<n;i++)
    {
        int j=i;
        while(arr[j])
            {
                count[i]++;
                j++;
                if(j>i)j%=n;
                if(count[i]==n)
                {
                    cout<<count[i];
                    return 0;
                }
            }
    }
    cout<<Max(count,n);
    delete []count;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
     int temp=0,max=0,max2=1;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i])temp++;
        else{
            max=temp;
            temp=0;
        }
    }
    if(arr[n-1]==1)for(int i=0;i<n;i++)
    {
        if(arr[i])max2++;
        else break;
    }

    if(max<=max2)cout<<max2;
    else cout<<max;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
     int temp=0,max=0,max2=1;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i])temp++;
        else{
            max=temp;
            temp=0;
        }
    }
    if(arr[n-1]==1)for(int i=0;i<n;i++)if(arr[i])max2++;
    /*for(int i=0;i<n;i++)
    {
        int j=i;
        while(arr[j])
            {
                count[i]++;
                j++;
                if(j>i)j%=n;
                if(count[i]==n)
                {
                    cout<<count[i];
                    return 0;
                }
            }
    }

    cout<<Max(count,n);
    delete []count;*/
    cout<<max<max2?max:max2;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
     int temp=0,max=0,max2=1;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i])temp++;
        else{
            max=temp;
            temp=0;
        }
    }
    if(arr[n-1]==1)for(int i=0;i<n;i++)if(arr[i])max2++;
    /*for(int i=0;i<n;i++)
    {
        int j=i;
        while(arr[j])
            {
                count[i]++;
                j++;
                if(j>i)j%=n;
                if(count[i]==n)
                {
                    cout<<count[i];
                    return 0;
                }
            }
    }

    cout<<Max(count,n);
    delete []count;*/
    if(max<=max2)cout<<max2;
    else cout<<max;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
     int *count=new int[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        count[i]=0;
    }

    for(int i=0;i<n;i++)
    {
        int j=i;
        while(arr[j])
            {
                count[i]++;
                j++;
                if(j>i)j%=n;
            }
    }
    cout<<Max(count,n);
    delete []count;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
    int temp=0,max=0,max2=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i])temp++;
        if(!arr[i]{
            if(max<temp)
            max=temp;
            temp=0;
        }
    }
    if(max<=temp)max=temp;
    if(arr[n-1]==1)
    {
        max2=1;
        for(int i=0;i<n;i++)
        {
        if(arr[i])max2++;
        else break;
        }
    }
    if(max>=max2)cout<<max;
    else cout<<max2;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
    int temp=0,max=0,max2=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i])temp++;
        if(!arr[i]){
            if(max<temp)
            max=temp;
            temp=0;
        }
    }
    if(max<=temp)max=temp;
    if(arr[n-1]==1)
    {
        int t=n-1;
        int count=0;
        while(t>0)
        {
            if(arr[t])count++;
            else break;
            t--;
        }
        max2=count;
        for(int i=0;i<n;i++)
        {
        if(arr[i])max2++;
        else break;
        }
    }
    if(max>=max2)cout<<max;
    else cout<<max2;
    delete []arr;
    return 0;
}


#include <iostream>
using namespace std;
int Max(int *arr,int n){
    if(!arr)return 0;
    int max=arr[0];
    for(int i=0;i<n;i++)
    {
        if(max<arr[i])max=arr[i];
    }
    return max;
}
int main()
{
    int n,*arr;
    cin>>n;
    arr= new int[n];
     int temp=0,max=0,max2=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i])temp++;
        else{
            max=temp;
            temp=0;
        }
    }
    if(arr[n-1]==1)
    {
        max2=1;
        for(int i=0;i<n;i++)
        {
        if(arr[i])max2++;
        else break;
        }
    }
    if(max<=max2)cout<<max2;
    else cout<<max;
    delete []arr;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n, i, str[200005], flag = 1, find = 0 , s, ans = 0, max = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &str[i]);
		if (flag&&str[i] == 0)
		{
			find = i;
			flag = 0;
		}
	}
	if (find == n - 1)
		find = 0;
	for (i = find, s = 0; s < n; s++, i++)
	{
		if (str[i] == 1)
			ans++;
		else
		{
			if (ans>max)
				max = ans;
			ans = 0;
		}
		if (i == n - 1)
			i = -1;
	}
	if (ans>max)
		max = ans;
	printf("%d\n", max);
	return 0;
}


#include<iostream>

using namespace std;

bool in[200009];

int main()
{
	int n;
	cin>>n;
	for(int i =0; i < n; i++)
		cin>>in[i];
	int temp = 0;
	int all = 0;
	for(int i = 0; i < n; i++)
	{
		if(in[i])
		{
			temp++;
			all = all > temp ? all : temp;
		}
		else
			temp = 0;
	}
	temp = 0;
	if(in[0]&&in[n - 1])
	{
		for(int i = 0; i < n; i++)
		{
			if(in[i])
			{
				temp++;
			}
			else
				break;
		}
		for(int i = n - 1; i >= 0; i--)
		{
			if(in[i])
			{
				temp++;
			}
			else
				break;
		}
	}
	all = all > temp ? all : temp;
	cout<<all<<endl;
	return 0;
}


#include<iostream>

using namespace std;

bool in[200009];
int ans[200009];

int main()
{
	int n;
	cin>>n;
	for(int i =0; i < n; i++)
		cin>>in[i];
	int temp = 0;
	int all = 0;
	for(int i = 0; i < n; i++)
	{
		if(in[i])
		{
			temp++;
			ans[i] = temp;
			all = all > temp ? all : temp;
		}
		else
			temp = 0;
	}
	if(ans[0]&&ans[n - 1])
		all = ans[0] + ans[n - 1] > all ? ans[0] + ans[n - 1] : all;
	cout<<all<<endl;
	return 0;
}


#include<iostream>

using namespace std;

bool in[200009];

int main()
{
	int n;
	cin>>n;
	for(int i =0; i < n; i++)
		cin>>in[i];
	int temp = 0;
	int all = 0;
	for(int i = 0; i < n; i++)
	{
		if(in[i])
		{
			temp++;
			ans[i] = temp;
			all = all > temp ? all : temp;
		}
		else
			temp = 0;
	}
	if(ans[0]&&ans[n - 1])
		all = ans[0] + ans[n - 1] > all ? ans[0] + ans[n - 1] : all;
	cout<<all<<endl;
	return 0;
}


#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
	int n;
	int j=0;
	int s=0;
	int a[24];
	int b[50];
	int num[48]={0};
	cin>>n;
	if(n<0||n>24)return 0;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		b[i]=a[i];
		b[n+i]=a[i];
	}
    for(int i=0;i<2*n;i++){
    	j++;
    	while(b[i]==1){
    		i++;
    		num[j]++;
		}

	}
	for(int i=0;i<2*n;i++){
		s=max(num[i],s);

	}
	cout<<s;}


#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
	int n;
	int j=0;
	int s=0;
	int a[24];
	int b[48];
	int num[48]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		b[i]=a[i];
		b[n+i]=a[i];
	}
    for(int i=0;i<2*n;i++){
    	j++;
    	while(b[i]==1){
    		i++;
    		num[j]++;
		}

	}
	for(int i=0;i<2*n;i++){
		s=max(num[i],s);

	}
	cout<<s;}


#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
	int n;
	int j=0;
	int s=0;
	int a[200000];
	int b[400000];
	int num[400000]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		b[i]=a[i];
		b[n+i]=a[i];
	}
    for(int i=0;i<2*n;i++){
    	j++;
    	while(b[i]==1){
    		i++;
    		num[j]++;
		}

	}
	for(int i=0;i<2*n;i++){
		s=max(num[i],s);

	}
	cout<<s;}


#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
	int n;
	int j=0;
	int s=0;
	int a[24];
	int b[50];
	int num[48]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		b[i]=a[i];
		b[n+i]=a[i];
	}
    for(int i=0;i<2*n;i++){
    	j++;
    	while(b[i]==1){
    		i++;
    		num[j]++;
		}

	}
	for(int i=0;i<2*n;i++){
		s=max(num[i],s);

	}
	cout<<s;}


#include<iostream>
using namespace std;
int a[400005]={0};
int main(void)
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[n+i]=a[i];
	}
	int c=0,max=0;
	for(int i=0;i<2*n;i++){
		if(a[i] == 1)c++;
		if(max<c){
			max=c;
		}
		if(a[i]==0) c=0;
	}
	cout<<max<<endl;
	}


#include<iostream>
using namespace std;
int main()
{int i,t,n,s[100];
cin>>t>>n;
while(t>0)
    {for(i=0;i<n;i++)
        {cin>>s[i];}
    for(i=0;i<n;i++)
        {if(s[i]==2048)
            {cout<<"yes"<<endl;
             break;}
             cout<<"no";
        }
    t--;}
    return 0;
}


#include <iostream>
#include <stdio.h>

using namespace std;
int time[200005];
int num[200005]={0};
int main()
{
   int n,j=0,maxx=0,flag=0;
   scanf("%d",&n);
   for(int i=0;i<n;i++)
   {
       scanf("%d",&time[i]);
       if(time[i]==1)
       {
           num[j]++;
           flag=0;
       }
       else
       {
          j++;
          flag=1;
       }
   }

    if((time[n-1]==1)&&(time[0]==1))
    {
        if(flag==1)
        num[j]=num[j-1]+num[0];
        else
        {
            j++;
            num[j]=num[j-1]+num[0];
        }
    }

    for(int p=0;p<=j;p++)
    {
        if(num[p]>maxx)
            maxx=num[p];

    }

    printf("%d",maxx);
    return 0;
}


/*#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int main() {
	int n, m;
	scanf_s("%d %d", &n, &m);
	if (m%n!=0) {
		printf("-1");
		return 0;
	}
	int output = 0,div=m/n;
	while (div % 2 == 0) {
		div /= 2;
		output++;
	}
	while (div % 3 == 0) {
		div /= 3;
		output++;
	}
	if (div == 1)
		printf("%d", output);
	else
		printf("-1");
	return 0;
}*/
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int input[200000];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &input[i]);
	}
	int maximum = 0, cnt = 0;
	for (int i = 0; i < 2*n; i++) {
		if (input[i%n] == 1)
			cnt++;
		else {
			maximum = max(maximum, cnt);
			cnt = 0;
		}
	}
	if (maximum > n)
		maximum = n;
	printf("%d", maximum);
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
const int N_MAX=2e5+10;
int x,n,maxx=-0x3f3f3f3f;
vector<int> workhour(N_MAX);

int main(){
	int length=0;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>workhour[i];
	}

	for(int i=0;i<2*n;i++){
		if(workhour[i%n]==1){
			length++;
			maxx=max(maxx,length);
		}

		else{
			length=0;
		}
	}
	maxx=max(maxx,length);
	cout<<maxx<<endl;
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stack>
using namespace std;
int a[200005];
int main()
{
    int n;
    long long maxn=0,cur=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    cin>>a[i];
    if(a[i]==1)
    cur++;
    else{
        if(cur>maxn)maxn=cur;
        cur=0;
        }
    }

    for(int i=1;i<=n;i++)
    {
    if(a[i]==1)cur++;
    else break;
    }
    if(cur>maxn)maxn=cur;
    cout<<maxn;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <cmath>
using namespace std;
struct node
{
    int shuzi;
    int cishu;
} a[200005];
int main()
{
    int n;
    cin>>n;
    int i;
    a[0].cishu=0;
    int minn=-1;
    int flag=1;
    int step=0;
    for(i=1; i<=n; i++)
    {
        cin>>a[i].shuzi;
        if(i==n) break;
        if(a[i].shuzi==1&&flag==1) step++;
        if(a[i].shuzi==0) flag=0,a[i].cishu=0;
        if(a[i].shuzi==1) a[i].cishu=a[i-1].cishu+1;
        if(a[i].cishu>minn) minn=a[i].cishu;
    }
    if(a[n].shuzi==1) {a[n].cishu=a[n-1].cishu+1+step;
    if(minn<a[n].cishu) minn=a[n].cishu;}
    cout<<minn<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <cmath>
using namespace std;
struct node
{
    int shuzi;
    int cishu;
} a[200005];
int main()
{
    int n;
    cin>>n;
    int i;
    a[0].cishu=0;
    int minn=0;
    int flag=1;
    int step=0;
    for(i=1; i<=n; i++)
    {
        cin>>a[i].shuzi;
        if(a[i].shuzi==1&&flag==1) step++;
        if(i!=n)
        { if(a[i].shuzi==0) flag=0,a[i].cishu=0;
          if(a[i].shuzi==1) a[i].cishu=a[i-1].cishu+1;
          if(a[i].cishu>minn) minn=a[i].cishu;}
    }
    if(a[n].shuzi==1) {a[n].cishu=a[n-1].cishu+1+step;
    if(minn<a[n].cishu) minn=a[n].cishu;}
    cout<<minn<<endl;
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <cmath>
#include <vector>
#include <stack>
#include <fstream>
#include <iomanip>

using namespace std;

#define endl '\n'
int a[1000001];
int p[1000001];
int main() {
	int n, m, count = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int max_ = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 1) {
			count++;
		}
		else {
			max_ = max(max_, count);
			count = 0;
		}
	}
	int j = 0;
	while (a[j] != 0) {
		count++;
		j++;
	}
	cout << max(max_, count) << endl;
	return 0;
}


def bubblesort(alist):
    for passnum in range(len(alist)-1,0,-1):
        for i in range(passnum):
            if alist[i]>alist[i+1]:
                temp = alist[i]
                alist[i] = alist[i+1]
                alist[i+1] = temp
    return alist
sumfirst=0
sumremain=0
counter=0
a=int(input())
b=input().split()
for i in range(len(b)):
	b[i]=int(b[i])
	sumremain=sumremain+b[i]
b=bubblesort(b)
for i in range(len(b)):
	sumremain=sumremain-b[i]
	sumfirst=sumfirst+b[i]
	counter=counter+1
	if(sumfirst>sumremain):
		print(counter)
		break
o=0


def bubblesort(alist):
    for passnum in range(len(alist)-1,0,-1):
        for i in range(passnum):
            if alist[i]>alist[i+1]:
                temp = alist[i]
                alist[i] = alist[i+1]
                alist[i+1] = temp
    return alist
sumfirst=0
sumremain=0
counter=0
a=int(input())
b=input().split()
for i in range(len(b)):
	b[i]=int(b[i])
	sumremain=sumremain+b[i]
b=bubblesort(b)
for i in range(len(b)):
	sumremain=sumremain-b[i]
	sumfirst=sumfirst+b[i]
	counter=counter+1
	if(sumfirst>sumremain):
		print(counter)
		break
	break


def bubblesort(alist):
    for passnum in range(len(alist)-1,0,-1):
        for i in range(passnum):
            if alist[i]>alist[i+1]:
                temp = alist[i]
                alist[i] = alist[i+1]
                alist[i+1] = temp
    return alist
sumfirst=0
sumremain=0
counter=0
a=int(input())
b=input().split()
for i in range(len(b)):
	b[i]=int(b[i])
	sumremain=sumremain+b[i]
b=bubblesort(b)
for i in range(len(b)):
	sumremain=sumremain-b[i]
	sumfirst=sumfirst+b[i]
	if(sumfirst>sumremain):
		print(counter)
		break
	counter=counter+1


def bubblesort(alist):
    for passnum in range(len(alist)-1,0,-1):
        for i in range(passnum):
            if alist[i]>alist[i+1]:
                temp = alist[i]
                alist[i] = alist[i+1]
                alist[i+1] = temp
    return alist
sumfirst=0
sumremain=0
counter=0
a=int(input())
b=input().split()
for i in range(len(b)):
	b[i]=int(b[i])
	sumremain=sumremain+b[i]
b=bubblesort(b)
for i in range(len(b)):
	sumremain=sumremain-b[i]
	sumfirst=sumfirst+b[i]
	counter=counter+1
	if(sumfirst>sumremain):
		print(counter)
		break


def bubblesort(alist):
    for passnum in range(len(alist)-1,0,-1):
        for i in range(passnum):
            if alist[i]<alist[i+1]:
                temp = alist[i]
                alist[i] = alist[i+1]
                alist[i+1] = temp
    return alist
sumfirst=0
sumremain=0
counter=0
a=int(input())
b=input().split()
for i in range(len(b)):
	b[i]=int(b[i])
	sumremain=sumremain+b[i]
b=bubblesort(b)
flag=0
for i in range(len(b)):
	sumremain=sumremain-b[i]
	sumfirst=sumfirst+b[i]
	counter=counter+1
	if(sumfirst>sumremain):
		print(counter)
		break


a = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
k = []
for i in range(len(l)):
	k = l[0:i]
	t = l[i:len(l)]
	if sum(k) > sum(t):
		print(len(k))
		exit()
print(1)


a = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
k = []
for i in range(len(l)):
	k = l[0:i+1]
	t = l[i+1:len(l)]
	if sum(k) > sum(t):
		print(len(k))
		exit()
print(1)


a = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
k = []
for i in range(len(l)):
	k = l[0:i+1]
	t = l[i:len(l)]
	if k > t:
		print(len(k))
		exit()


a = int(input())
l = list(map(int,input().split()))
print(len(l)//2+1)


a = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
k = []
for i in range(len(l)):
	k = l[0:i+1]
	t = l[i:len(l)]
	if k > t:
		print(len(k))
		exit()
print(1)


a = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
k = []
for i in range(len(l)):
	k = l[0:i+1]
	t = l[i:len(l)]
	if sum(k) > sum(t):
		print(len(k))
		exit()
print(1)


i = int(input())
cv = input().split()

for j in range(len(cv)):
  cv[j] = int(cv[j])
s = sum(cv)
g = 0
l = 0

cv.sort(reverse=True)

if(cv[0] == 1):
  print(1)

for k in cv:
  g += k
  s -= k
  l += 1
  if(g > k):
    print(l)
    break


i = int(input())
cv = input().split()

for j in range(len(cv)):
  cv[j] = int(cv[j])
s = sum(cv)
g = 0
l = 0

cv.sort(reverse=True)

if(len(cv) == 1):
  print(1)
else:
  for k in cv:
    g += k
    s -= k
    l += 1
    if(g > s):
      print(l)
      break


i = int(input())
cv = input().split()

for j in range(len(cv)):
  cv[j] = int(cv[j])
s = sum(cv)
g = 0
l = 0

cv.sort(reverse=True)

if(len(cv) == 1):
  print(1)

for k in cv:
  g += k
  s -= k
  l += 1
  if(g > s):
    print(l)
    break


i = int(input())
cv = input().split()

for j in range(len(cv)):
  cv[j] = int(cv[j])
subtractor = sum(cv)
adder = 0
coinMin = 0

cv.sort(reverse=True)

if(len(cv) == 1):
  print(1)

else:
  for k in cv:
    adder += k
    subtractor -= k
    coinMin += 1
    if(adder > subtractor):
      print(coinMin)
      break


i = int(input())
cv = input().split()

for j in range(len(cv)):
  cv[j] = int(cv[j])
s = sum(cv)
g = 0
l = 0

cv.sort(reverse=True)

for k in cv:
  g += k
  s -= k
  l += 1
  if(g > k):
    print(l)
    break


i = int(input())
cv = input().split()

for j in range(len(cv)):
  cv[j] = int(cv[j])
s = sum(cv)
g = 0
l = 0

cv.sort(reverse=True)

if(len(cv) == 1):
  print(1)

for k in cv:
  g += k
  s -= k
  l += 1
  if(g > k):
    print(l)
    break


def partition(a, start=0, end=0):
    pivot = a[end]
    pi = start
    for i in range(start, end):
        if a[i] <= pivot:
            a[i], a[pi] = a[pi], a[i]
            pi += 1
    a[pi], a[end] = a[end], a[pi]
    return pi

def quicksort(a, start = 0, end = 0):
    if start < end:
        pi = partition(a, start, end)
        quicksort(a, start, pi-1)
        quicksort(a, pi+1, end)

n = int(input())
l = []
arr = input().split()
if n == 1:
    print('1')
else:
    for i in range(n):
        l.append(int(arr[i]))
    quicksort(l, 0, n-1)
    twin = 0
    my = 0
    if n == 2 and my > twin:
        print('1')
    elif n == 2 and my == twin:
        print('2')
    elif l.count(l[0]) == n:
        print(n//2 + 1)
    else:
        j = n-1
        i = 0
        coins = 0
        while i != j:
            if twin >= my:
                my += l[j]
                j -= 1
                coins += 1
            else:
                twin += l[i]
                i += 1
        if twin >= my:
            coins += 1
        print(coins)


def partition(a, start=0, end=0):
    pivot = a[end]
    pi = start
    for i in range(start, end):
        if a[i] <= pivot:
            a[i], a[pi] = a[pi], a[i]
            pi += 1
    a[pi], a[end] = a[end], a[pi]
    return pi

def quicksort(a, start = 0, end = 0):
    if start < end:
        pi = partition(a, start, end)
        quicksort(a, start, pi-1)
        quicksort(a, pi+1, end)

n = int(input())
arr = input().split()
l = []
for i in range(n):
    l.append(int(arr[i]))
quicksort(l, 0, n-1)
twinsum = l[0]
mysum = l[n-1]
coins = 1
j = 0
for i in range(1, n-1):
    if twinsum < mysum:
        twinsum += l[i]
    else:
        mysum += l[n-i-1]
        j += 1
        coins += 1
    if i+j == n-1:
        break
if twinsum >= mysum:
    coins += 1
print(coins)


def partition(a, start=0, end=0):
    pivot = a[end]
    pi = start
    for i in range(start, end):
        if a[i] <= pivot:
            a[i], a[pi] = a[pi], a[i]
            pi += 1
    a[pi], a[end] = a[end], a[pi]
    return pi

def quicksort(a, start = 0, end = 0):
    if start < end:
        pi = partition(a, start, end)
        quicksort(a, start, pi-1)
        quicksort(a, pi+1, end)

n = int(input())
arr = input().split()
l = []
if n == 1:
    print('1')
else:
    for i in range(n):
        l.append(int(arr[i]))
    quicksort(l, 0, n-1)
    twinsum = l[0]
    mysum = l[n-1]
    coins = 1
    j = 0
    for i in range(1, n-1):
        if twinsum < mysum:
            twinsum += l[i]
        else:
            mysum += l[n-i-1]
            j += 1
            coins += 1
        if i+j == n-1:
            break
    if twinsum >= mysum:
        coins += 1
    print(coins)


def partition(a, start=0, end=0):
    pivot = a[end]
    pi = start
    for i in range(start, end):
        if a[i] <= pivot:
            a[i], a[pi] = a[pi], a[i]
            pi += 1
    a[pi], a[end] = a[end], a[pi]
    return pi

def quicksort(a, start = 0, end = 0):
    if start < end:
        pi = partition(a, start, end)
        quicksort(a, start, pi-1)
        quicksort(a, pi+1, end)

n = int(input())
arr = input().split()
l = []
if n == 1:
    print('1')
else:
    for i in range(n):
        l.append(int(arr[i]))
    quicksort(l, 0, n-1)
    twinsum = l[0]
    mysum = l[n-1]
    coins = 1
    j = 0
    for i in range(1, n-1):
        if twinsum < mysum:
            twinsum += l[i]
        else:
            mysum += l[n-i-1]
            j += 1
            coins += 1
    if twinsum >= mysum:
        coins += 1
    print(coins)


def partition(a, start=0, end=0):
    pivot = a[end]
    pi = start
    for i in range(start, end):
        if a[i] <= pivot:
            a[i], a[pi] = a[pi], a[i]
            pi += 1
    a[pi], a[end] = a[end], a[pi]
    return pi

def quicksort(a, start = 0, end = 0):
    if start < end:
        pi = partition(a, start, end)
        quicksort(a, start, pi-1)
        quicksort(a, pi+1, end)

n = int(input())
l = []
arr = input().split()
if n == 1:
    print('1')
else:
    for i in range(n):
        l.append(int(arr[i]))
    quicksort(l, 0, n-1)
    twin = l[0]
    my = l[n-1]
    if n == 2 and my > twin:
        print('1')
    elif n == 2 and my == twin:
        print('2')
    elif l.count(l[0]) == n:
        print(n//2 + 1)
    else:
        j = n-2
        i = 1
        coins = 1
        while i != j:
            if twin >= my:
                my += l[j]
                j -= 1
                coins += 1
            else:
                twin += l[i]
                i += 1
        if twin == my:
            coins += 1
        elif twin < my:
            twin += l[i]
            if twin >= my:
                coins += 1
        elif twin > my:
            my += l[i]
            if twin >= my:
                coins += 1
            coins += 1
        print(coins)


def partition(a, start=0, end=0):
    pivot = a[end]
    pi = start
    for i in range(start, end):
        if a[i] <= pivot:
            a[i], a[pi] = a[pi], a[i]
            pi += 1
    a[pi], a[end] = a[end], a[pi]
    return pi

def quicksort(a, start = 0, end = 0):
    if start < end:
        pi = partition(a, start, end)
        quicksort(a, start, pi-1)
        quicksort(a, pi+1, end)

n = int(input())
l = []
arr = input().split()
if n == 1:
    print('1')
else:
    for i in range(n):
        l.append(int(arr[i]))
    quicksort(l, 0, n-1)
    twin = l[0]
    my = l[n-1]
    if n == 2 and my > twin:
        print('1')
    elif n == 2 and my == twin:
        print('2')
    else:
        j = n-2
        i = 1
        coins = 1
        while i != j:
            if twin >= my:
                my += l[j]
                j -= 1
                coins += 1
            else:
                twin += l[i]
                i += 1
        if twin >= my:
            coins += 1
        print(coins+1)


n = int(input())

l1 = sorted(map(int,input().split()) ,reverse= True)

summ = 0
count = 0

for i in range(n):
    if summ > sum(l1) // 2:
        break
    else:
        summ += l1[i]
        count +=1

print(count)


n = int(input())
a = list(map(int,input().split()))
a = list(reversed(sorted((a))))
#print(a)
x = sum(a)
sm = 0
c = 0

for i in range(n):
    if sm > x :
        break
    else:
        sm += a[i]
        x -= a[i]
        c +=1

#print(x)
print(c)


n = int(input())
a = sorted(map(int,input().split()) , reverse= True)
c = 0
summ = 0
for i in range(n):
    if summ > sum(a) // 2 :
        break
    else:
        summ += a[i]
        c +=1
print(c)


input()
c = sorted(map(int,input().split()) ,reverse =True )
a = b = 0
while a <= sum(c) / 2 :
    a += c[b]
    b +=1

print(b)


n = int(input())
l = list(map(int,input().split()))
c = 0
summ1 = sum(l)
summ2 = 0

for i in range(n):
    if summ2 > summ1 // 2  :
        break
    else:
        summ2 += l[i]
        c +=1
print(c)


n = int(input())

l = list(map(int,input().split()))
#l.sort()
mx = max(l)
print(l.count(mx))


def sum(x):
    j=0
    for i in x:
        j += i
    return j

x = int(input())
lis = list(map(int,input().split()))
cis = sorted(lis,reverse=True)
if x>3:
    for i in range(len(cis)-1):
        if sum(cis[:i])>sum(cis[i:]):
            print(i)
            break
elif x ==3:
    if cis[0]>cis[1]+cis[2]:
        print('1')
    elif cis[0]+cis[1]>cis[2]:
        print("2")
    else:
        print("3")
elif x==1:
    print('1')
elif x==2:
    if cis[0]>cis[1]:
        print("1")
    else:
        print("2")


def sum(x):
    j=0
    for i in x:
        j += i
    return j

x = int(input())
lis = list(map(int,input().split()))
cis = sorted(lis,reverse=True)
if x>3:
    for i in range(len(cis)-1):
        if sum(cis[:i])>sum(cis[i:]):
            print(i)
            break
elif x ==3:
    if cis[0]>cis[1]+cis[2]:
        print('1')
    elif cis[0]+cis[1]>cis[2]:
        print("2")
    else:
        print("3")
else:
    print(2)


def sum(x):
    j=0
    for i in x:
        j += i
    return j

x = int(input())
lis = list(map(int,input().split()))
cis = sorted(lis,reverse=True)
if x>3:
    for i in range(len(cis)-1):
        if sum(cis[:i])>sum(cis[i:]):
            print(i)
            break
elif x ==3:
    if cis[0]>cis[1]+cis[2]:
        print('1')
    elif cis[0]+cis[1]>cis[2]:
        print("2")
    else:
        print("3")
elif x==1:
    print('1')
else x==2:
    if cis[0]>cis[1]:
        print("1")
    else:
        print("2")


def sum(x):
    j=0
    for i in x:
        j += i
    return j

x = int(input())
lis = list(map(int,input().split()))
cis = sorted(lis,reverse=True)
if len(cis)>2:
    for i in range(len(cis)-1):
        if sum(cis[:i])>sum(cis[i:]):
            print(i)
            break
else:
    print(2)


def sum(x):
    j=0
    for i in x:
        j += i
    return j

x = int(input())
lis = list(map(int,input().split()))
cis = sorted(lis,reverse=True)
for i in range(len(cis)-1):
    if sum(cis[:i])>sum(cis[i:]):
        print(i)
        break


def sum(x):
    j=0
    for i in x:
        j += i
    return j

x = int(input())
lis = list(map(int,input().split()))
cis = sorted(lis,reverse=True)
if x>3:
    for i in range(len(cis)-1):
        if sum(cis[:i])>sum(cis[i:]):
            print(i)
            break
elif x ==3:
    if cis[0]>cis[1]+cis[2]:
        print('1')
    elif cis[0]+cis[1]>cis[2]:
        print("2")
    else:
        print("3")
elif x==1:
    print('1')
else:
    print('2')


n=int(input());
coins=[];
maxBro=0;
minBro=0;
howMany=0;
coins=[int(i) for i in input().split()];
while maxBro<=minBro:
  minBro=0;
  for coin in coins:
    minBro+=coin;
  maxBro+=max(coins);
  minBro-=max(coins);
  coins.pop(coins.index(max(coins)));
  howMany+=1;
maxBro=0;
print(howMany);


n=input(); coins=[]; maxBro=0; minBro=0; howMany=0;
for i in range(int(n)):
  coins.append(int(input()));
while maxBro<=minBro:
  minBro=0;
  for coin in coins:
    minBro+=coin;
  maxBro+=max(coins);
  minBro-=max(coins);
  coins.pop(coins.index(max(coins)));
  howMany+=1;
print(howMany);


n=int(input()); coins=[]; maxBro=0; minBro=0; howMany=0;
coins=input().split();
while maxBro<=minBro:
  minBro=0;
  for coin in coins:
    minBro+=int(coin);
  maxBro+=int(max(coins));
  minBro-=int(max(coins));
  coins.pop(coins.index(max(coins)));
  howMany+=1;
maxBro=0;
print(howMany);


n=int(input()); coins=[]; maxBro=0; minBro=0; howMany=0;
for i in range(n):
  coins.append(int(input()));
while maxBro<=minBro:
  minBro=0;
  for coin in coins:
    minBro+=coin;
  maxBro+=max(coins);
  minBro-=max(coins);
  coins.pop(coins.index(max(coins)));
  howMany+=1;
print(howMany);


n=int(input()); coins=[]; maxBro=0; minBro=0; howMany=0;
coins=[int(i) for i in input().split()];
while maxBro<=minBro:
  minBro=0;
  for coin in coins:
    minBro+=coin;
  maxBro+=max(coins);
  minBro-=max(coins);
  coins.pop(coins.index(max(coins)));
  howMany+=1;
maxBro=0;
print(howMany);#number of coins


#Twins problem
n=int(input()); coins=[]; maxBro=0; minBro=0; howMany=0;
coins=[int(i) for i in input().split()];
while maxBro<=minBro:
  minBro=0;
  for coin in coins:
    minBro+=coin;
  maxBro+=max(coins);
  minBro-=max(coins);
  coins.pop(coins.index(max(coins)));
  howMany+=1;
maxBro=0;
print(howMany);


n=int(input()); coins=[]; maxBro=0; minBro=0; howMany=0;
coins=[int(i) for i in input().split()];
while maxBro<=minBro:
  minBro=0;
  for coin in coins:
    minBro+=coin;
  maxBro+=max(coins);
  minBro-=max(coins);
  coins.pop(coins.index(max(coins)));
  howMany+=1;
maxBro=0;
print(howMany);


n=input(); coins=[]; maxBro=0; minBro=0; howMany=0;
for i in range(int(n)):
  coins.append(int(input()));
while maxBro<=minBro:
  minBro=0;
  for coin in coins:
    minBro+=coin;
  maxBro+=max(coins);
  minBro-=max(coins);
  coins.pop(coins.index(max(coins)));
  howMany+=1;
maxBro=0;
print(howMany);


noc = int(input())
coins = input().split()

ra = sorted(coins, reverse = True)
toc = 0
for i in ra:
    toc += int(i)

i = 0
s = 0
while s <= toc/2 :
    s += int(ra[i])
    i += 1

print(i)


noc = int(input())
coins = list(input())

rac = coins.sort()
toc = sum(coins)

i = 0
s = 0
while s < toc/2 :
    s += rac[i]
    i += 1

print(i)


noc = int(input())
coins = input().split()

ra = sorted(coins,True)
toc = 0

for i in ra:
    toc += int(i)

i = 0
s = 0
while s <= toc/2 :
    s += int(ra[i])
    i += 1

print(i)


noc = int(input())
coins = input().split()

ra = sorted(coins)
toc = 0

for i in ra:
    toc += int(i)

i = 0
s = 0
while s <= toc/2 :
    s += int(ra[i])
    i += 1

print(i)


noc = int(input())
coins = input().split()

ra = sorted(coins, reverse = True)
toc = 0

for i in ra:
    toc += int(i)

i = 0
s = 0
while s <= toc/2 :
    s += int(ra[i])
    i += 1

print(i)


noc = int(input())
coins = list(map(int, input().split()))

ra = sorted(coins, reverse = True)
toc = 0

for i in ra:
    toc += int(i)

i = 0
s = 0
while s <= toc/2 :
    s += int(ra[i])
    i += 1

print(i)


noc = int(input())
coins = input().split()

ra = sorted(coins, reversed = True)
toc = 0

for i in ra:
    toc += int(i)

i = 0
s = 0
while s <= toc/2 :
    s += int(ra[i])
    i += 1

print(i)


input()
coinpick = []

coins = [int(x) for x in input().split()]
half = sum(coins) / 2

for i in range(len(coins)):
    for j in range(i+1,len(coins)):
        s = coins[i:j+1]
        if (len(s) < len(coinpick) or len(coinpick) == 0) and sum(s) > half:
            coinpick = [coins[i],coins[j]]
#print(coinpick)
print(len(coinpick))


input()
coinlen = 0
coinsum = 0

coins = [int(x) for x in input().split()]
half = sum(coins) / 2

if len(coins) == 1:
    coinlen = 1

for i in range(len(coins)):
    if coins[i] > half:
        coinlen = 1
        coinsum = coins[i]
    for j in range(i+1,len(coins)):
        s = coins[i:j+1]
        if (len(s) < coinlen or coinlen == 0) and sum(s) > half:
            coinlen = len(s)
            coinsum = sum(s)
print(coinlen)


input()
coinlen = 0
coinsum = 0

coins = [int(x) for x in input().split()]
half = sum(coins) / 2

if len(coins) == 1:
    coinpick = [coins[0]]

for i in range(len(coins)):
    for j in range(i+1,len(coins)):
        s = coins[i:j+1]
        if (len(s) < coinlen or coinlen == 0) and sum(s) > half:
            coinlen = len(s)
            coinsum = sum(s)
print(coinlen)


input()
coinpick = []

coins = [int(x) for x in input().split()]
half = sum(coins) / 2

if len(coins) == 1:
    coinpick = [coins[0]]

for i in range(len(coins)):
    for j in range(i+1,len(coins)):
        s = coins[i:j+1]
        if (len(s) < len(coinpick) or len(coinpick) == 0) and sum(s) > half:
            coinpick = [coins[i],coins[j]]
#print(coinpick)
print(len(coinpick))


input()
coinlen = 0
coinsum = 0

coins = sorted([int(x) for x in input().split()])
half = sum(coins) / 2

if len(coins) == 1:
    coinlen = 1

for i in range(len(coins)):
    if coins[i] > half:
        coinlen = 1
        coinsum = coins[i]
    for j in range(i+1,len(coins)):
        s = coins[i:j+1]
        if (len(s) < coinlen or coinlen == 0) and sum(s) > half:
            coinlen = len(s)
            coinsum = sum(s)
print(coinlen)


input()
coinlen = 0
coinsum = 0

coins = [int(x) for x in input().split()]
half = sum(coins) / 2

if len(coins) == 1:
    coinlen = 1

for i in range(len(coins)):
    for j in range(i+1,len(coins)):
        s = coins[i:j+1]
        if (len(s) < coinlen or coinlen == 0) and sum(s) > half:
            coinlen = len(s)
            coinsum = sum(s)
print(coinlen)


n=int(input())
x=input().split()
y=sorted(x)
a=0
b=0
c=0
for i in range(n):
    b=b+int(x[i])
for j in range(n):
    a=a+int(y[j])
    c=c+1
    if 2*a>b:
        print(n-c+1)
        break


n=int(input())
x=[int(z) for z in input().split()]
y=x.copy()
y.sort(reverse=True)
a=0
b=0
c=0
for i in range(n):
    b=b+x[i]
print(b,x,y)
for i in range(n):
    a=a+y[i]
    c=c+1
    if 2*a>b:
        print(c)
        break


n=int(input())
x=input().split()
y=sorted(x)
a=0
b=0
for i in range(n):
    b=b+int(x[i])
for j in range(n):
    a=a+int(y[j])
    if 2*a>b:
        print(j)
        break


n=int(input())
x=input().split()
y=x.copy()
y.sort(reverse=True)
a=0
b=0
c=0
for i in range(n):
    b=b+int(x[i])
for i in range(n):
    a=a+int(x[i])
    c=c+1
    if 2*a>b:
        print(c)
        break


n=int(input())
x=input().split()
y=sorted(x)
a=0
b=0
for i in range(n):
    b=b+int(x[i])
for j in range(n):
    a=a+int(y[j])
    if 2*a>b:
        print(n-j+1)
        break


n=int(input())
x=input().split()
y=x.copy()
y.sort(reverse=True)
a=0
b=0
c=0
for i in range(n):
    b=b+int(x[i])
for i in range(n):
    a=a+int(x[i])
    c=c+1
    if 2*a>b:
        print(c)


n=int(input())
x=[int(z) for z in input().split()]
y=x.copy()
y.sort(reverse=True)
a=0
b=0
c=0
for i in range(n):
    b=b+x[i]
for i in range(n):
    a=a+y[i]
    c=c+1
    if 2*a>b:
        print(c)
        break


n=int(input())
x=input().split()
y=reversed(sorted(x))
a=0
b=0
c=0
for i in range(n):
    b=b+int(x[i])
for j in range(n):
    a=a+int(y[j])
    c=c+1
    if 2*a>b:
        print(c)
        break


n=int(input())
m=0
L=sorted(list(map(int,input().split())))
x=sum(L)
for i in range(n):
    if 2*m>x:
        print(i+1)
        break
    else:
        num=L[i]
        m=m+num


n=int(input())
m=0
L=sorted(list(map(int,input().split())))
x=sum(L)
for i in range(n):
     num=L[i]
     m=m+num
    if 2*m>x:
        print(i+1)
        break