#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int a[4][100];
void solve(){
    int n,k;
    cin>>n>>k;
    if(k==2*n-4){
        rep(i,1,n-1){
            a[1][i]=a[2][i]=1;
        }
    }
    else if(k==2*n-5){
        cout<<"NO"<<endl;
        return;
    }
    else{
        if(k%2==0){
            rep(i,1,n-1){
                a[1][i]=1;
                a[2][i]=1;
                k-=2;
                if(!k) break;
            }
        }
        else{
            if(k<=n-2){
                a[1][n/2]=1;
                k--;
                int g=n/2-1;
                rep(i,0,k/2){
                    a[1][g]=a[1][n-1-g]=1;
                    g--;
                }
            }
            else{
                k-=n-2;
                rep(i,1,n-1){
                    a[1][i]=1;
                }
                rep(i,2,n-2){
                    a[2][i]=1;
                    k--;
                    if(!k) break;
                }
            }
        }
    }
    cout<<"YES"<<endl;
    rep(i,0,4){
        rep(j,0,n){
            if(a[i][j]) cout<<"#";
            else cout<<".";
        }
        cout<<endl;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int a[4][100];
void solve(){
    int n,k;
    cin>>n>>k;
    if(k==2*n-4){
        rep(i,1,n-1){
            a[1][i]=a[2][i]=1;
        }
    }
    else if(k==2*n-5){
        cout<<"NO"<<endl;
        return;
    }
    else{
        if(k%2==0){
            rep(i,1,n-1){
                a[1][i]=1;
                a[2][i]=1;
                k-=2;
                if(!k) break;
            }
        }
        else{
            if(k<=n-2){
                a[1][n/2]=1;
                k--;
                int g=n/2-1;
                rep(i,0,k/2){
                    a[1][g]=a[1][n-1-g]=1;
                    g--;
                }
            }
            else{
                k-=n-2;
                rep(i,1,n-1){
                    a[1][i]=1;
                }
                if(k){
                    k-=2;
                    a[2][1]=1;
                    a[2][n-2]=1;
                    rep(i,0,k){
                        a[2][i+2]=1;
                    }
                }
            }
        }
    }
    cout<<"YES"<<endl;
    rep(i,0,4){
        rep(j,0,n){
            if(a[i][j]) cout<<"#";
            else cout<<".";
        }
        cout<<endl;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int a[4][100];
void solve(){
    int n,k;
    cin>>n>>k;
    if(k==2*n-4){
        rep(i,1,n-1){
            a[1][i]=a[2][i]=1;
        }
    }
    else if(k==2*n-5){
        cout<<"NO"<<endl;
        return;
    }
    else{
        if(k>n-2){
            rep(i,1,n-1){
                a[1][i]=1;
            }
            k-=n-2;
            rep(i,2,n-2){
                a[2][i]=1;
                k--;
                if(!k) break;
            }
        }
        else{
            rep(i,0,k){
                a[1][i+1]=1;
            }
        }
    }
    cout<<"YES"<<endl;
    rep(i,0,4){
        rep(j,0,n){
            if(a[i][j]) cout<<"#";
            else cout<<".";
        }
        cout<<endl;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int a[4][100];
void solve(){
    int n,k;
    cin>>n>>k;
    if(k==2*n-4){
        rep(i,1,n-1){
            a[1][i]=a[2][i]=1;
        }
    }
    else if(k==2*n-5){
        cout<<"NO"<<endl;
        return;
    }
    else{
        if(k%2==0){
            rep(i,1,n-1){
                if(!k) break;
                a[1][i]=1;
                a[2][i]=1;
            }
        }
        else{
            if(k<=n-2){
                a[1][n/2]=1;
                k--;
                int g=n/2-1;
                rep(i,0,k/2){
                    a[1][g]=a[1][n-1-g]=1;
                    g--;
                }
            }
            else{
                k-=n-2;
                rep(i,1,n-1){
                    a[1][i]=1;
                }
                if(k){
                    k-=2;
                    a[2][1]=1;
                    a[2][n-2]=1;
                    rep(i,0,k){
                        a[2][i+2]=1;
                    }
                }
            }
        }
    }
    cout<<"YES"<<endl;
    rep(i,0,4){
        rep(j,0,n){
            if(a[i][j]) cout<<"#";
            else cout<<".";
        }
        cout<<endl;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int a[4][100];
void solve(){
    int n,k;
    cin>>n>>k;
    cout<<"YES"<<endl;
    if(k%2){
        a[1][n/2]=1;
        k--;
    }
    rep(j,1,n/2){
        if(!k) break;
        a[1][j]=a[2][j]=1;
        k-=2;
    }
    for(int j=n-2;j>=n/2;j--){
        if(!k) break;
        a[1][j]=a[2][j]=1;
        k-=2;
    }
    rep(i,0,4){
        rep(j,0,n){
            if(a[i][j]) cout<<"#";
            else cout<<".";
        }
        cout<<endl;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define test() ll t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define nax 1000005
#define pb push_back
#define mp make_pair
#define in insert
#define lpi(i,a,b) for(ll i=a;i<b;i++)
#define lpd(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin>>n>>k;
	char a[4][n];

	ll nn=(n-2)*2;
	if(nn<k)
	{
		cout<<"NO";
		return 0;
	}
	else cout<<"YES"<<endl;
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			a[i][j]='.';
		}
	}
	if(k%2==1)
	{
		a[1][n/2]='#';
		k--;

	}

		lpi(i,1,n/2)
		{
			ll j=n-1-i;
			if(k>0)
			{
				a[1][i]='#';

				a[1][j]='#';
				if(j!=i)
				k-=2;
				else
				k-=1;
			}
			if(j<i)
			break;
		}
		lpi(i,1,n/2)
		{
			ll j=n-1-i;
			if(k>0)
			{
				a[2][i]='#';
				a[2][j]='#';
				if(j!=i)
				k-=2;
				else
				k-=1;
			}
			if(j<=i)
			break;
		}
	 if(k==2)
	 {
	 	a[1][n/2]='#';
	 	a[2][n/2]='#';
	 }

	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			cout<<a[i][j];
		}
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#define test() ll t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define nax 1000005
#define pb push_back
#define mp make_pair
#define in insert
#define lpi(i,a,b) for(ll i=a;i<b;i++)
#define lpd(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin>>n>>k;
	char a[4][n];

	ll nn=(n-2)*2;
	if(nn<k)
	{
		cout<<"NO";
		return 0;
	}
	else cout<<"YES"<<endl;
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			a[i][j]='.';
		}
	}
	if(k%2==1)
	{
		a[1][n/2]='#';
		k--;

	}

		lpi(i,1,n/2+1)
		{
			ll j=n-1-i;
			if(k>0)
			{
				a[1][i]='#';
				if(j!=i)
				a[1][j]='#';
				k-=2;
			}
			if(j<i)
			break;
		}
		lpi(i,1,n/2+1)
		{
			ll j=n-1-i;
			if(k>0)
			{
				a[2][i]='#';
				if(j!=i)
				a[2][j]='#';
				k-=2;
			}
			if(j<i)
			break;
		}

	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			cout<<a[i][j];
		}
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#define test() ll t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define nax 1000005
#define pb push_back
#define mp make_pair
#define in insert
#define lpi(i,a,b) for(ll i=a;i<b;i++)
#define lpd(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin>>n>>k;
	char a[4][n];

	ll nn=(n-2)*2;
	if(nn<k)
	{
		cout<<"NO";
		return 0;
	}
	else cout<<"YES"<<endl;
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			a[i][j]='.';
		}
	}
	ll c=0;
	for(ll i=1;i<=n/2;i++)
	{
		if(c==k)
		break;
		ll j=n-1-i;
		if(j<i)
		{
			break;
		}
		a[1][i]='#';
		c++;
		if(c>=k)
		{
			break;
		}
		else
		{
			a[1][j]='#';
			c++;
		}
	}
	for(ll i=1;i<=n/2;i++)
	{
		if(c==k)
		break;
		ll j=n-1-i;
		if(j<i)
		{
			break;
		}
		a[2][i]='#';
		c++;
		if(c>=k)
		{
			break;
		}
		else
		{
			a[2][j]='#';
			c++;
		}
	}
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			cout<<a[i][j];
		}
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#define test() ll t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define nax 1000005
#define pb push_back
#define mp make_pair
#define in insert
#define lpi(i,a,b) for(ll i=a;i<b;i++)
#define lpd(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin>>n>>k;
	char a[4][n];

	ll nn=(n-2)*2;
	if(nn<k)
	{
		cout<<"NO";
		return 0;
	}
	else cout<<"YES"<<endl;
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			a[i][j]='.';
		}
	}
	if(k%2==1)
	{
		a[1][n/2]='#';
		k--;

	}

		lpi(i,1,n/2+1)
		{
			ll j=n-1-i;
			if(k>0)
			{
				a[1][i]='#';

				a[1][j]='#';
				if(j!=i)
				k-=2;
				else
				k-=1;
			}
			if(j<i)
			break;
		}
		lpi(i,1,n/2+1)
		{
			ll j=n-1-i;
			if(k>0)
			{
				a[2][i]='#';
				if(j!=i)
				a[2][j]='#';
				k-=2;
			}
			if(j<i)
			break;
		}

	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			cout<<a[i][j];
		}
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#define test() ll t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define nax 1000005
#define pb push_back
#define mp make_pair
#define in insert
#define lpi(i,a,b) for(ll i=a;i<b;i++)
#define lpd(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin>>n>>k;
	char a[4][n];

	ll nn=(n-2)*2;
	if(nn<k)
	{
		cout<<"NO";
		return 0;
	}
	else cout<<"YES"<<endl;
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			a[i][j]='.';
		}
	}
	if(k%2==1)
	{
		a[1][n/2]='#';
		k--;

	}
	else
	{
		lpi(i,1,n-1)
		{
			ll j=n-1-i;
			if(k>0)
			{
				a[1][i]='#';
				a[2][j]='#';
				k-=2;
			}
		}
	}
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			cout<<a[i][j];
		}
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#define test() ll t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define nax 1000005
#define pb push_back
#define mp make_pair
#define in insert
#define lpi(i,a,b) for(ll i=a;i<b;i++)
#define lpd(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin>>n>>k;
	char a[4][n];

	ll nn=(n-2)*2;
	if(nn<k)
	{
		cout<<"NO";
		return 0;
	}
	else cout<<"YES"<<endl;
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			a[i][j]='.';
		}
	}
	if(k%2==1)
	{
		a[1][n/2]='#';
		k--;

	}
	else
	{
		lpi(i,1,n/2+1)
		{
			ll j=n-1-i;
			if(k>0)
			{
				a[1][i]='#';
				if(j!=i)
				a[1][j]='#';
				k-=2;
			}
			if(j<i)
			break;
		}
		lpi(i,1,n/2+1)
		{
			ll j=n-1-i;
			if(k>0)
			{
				a[2][i]='#';
				if(j!=i)
				a[2][j]='#';
				k-=2;
			}
			if(j<i)
			break;
		}
	}
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			cout<<a[i][j];
		}
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#define test() ll t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define nax 1000005
#define pb push_back
#define mp make_pair
#define in insert
#define lpi(i,a,b) for(ll i=a;i<b;i++)
#define lpd(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin>>n>>k;
	char a[4][n];

	ll nn=(n-2)*2;
	if(nn<k)
	{
		cout<<"NO";
		return 0;
	}
	else cout<<"YES"<<endl;
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			a[i][j]='.';
		}
	}
	ll c=0;
	for(ll i=1;i<=n/2;i++)
	{
		if(c==k)
		break;
		ll j=n-1-i;
		if(j<i)
		{
			break;
		}
		a[1][i]='#';
		c++;
		if(c>=k)
		{
			break;
		}
		else if(j!=i)
		{
			a[1][j]='#';
			c++;
		}
	}

	for(ll i=1;i<=n/2;i++)
	{
		if(c==k)
		break;
		ll j=n-1-i;
		if(j<i)
		{
			break;
		}
		a[2][i]='#';
		c++;
		if(c>=k)
		{
			break;
		}
		else
		{
			a[2][j]='#';
			c++;
		}
	}
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			cout<<a[i][j];
		}
		cout<<endl;
	}

}


#include<bits/stdc++.h>
#define test() ll t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define nax 1000005
#define pb push_back
#define mp make_pair
#define in insert
#define lpi(i,a,b) for(ll i=a;i<b;i++)
#define lpd(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin>>n>>k;
	char a[4][n];

	ll nn=(n-2)*2;
	if(nn<k)
	{
		cout<<"NO";
		return 0;
	}
	else cout<<"YES"<<endl;
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			a[i][j]='.';
		}
	}
	ll c=0;
	for(ll i=1;i<=n/2;i++)
	{
		if(c==k)
		break;
		ll j=n-1-i;
		if(j<i)
		{
			break;
		}
		a[1][i]='#';
		c++;
		if(c>=k)
		{
			break;
		}
		else
		{
			a[1][j]='#';
			c++;
		}
	}
	for(ll i=1;i<=n/2;i++)
	{
		if(c==k)
		break;
		ll j=n-1-i;
		if(j<i)
		{
			break;
		}
		a[2][i]='#';
		c++;
		if(c>=k)
		{
			break;
		}
		else
		{
			a[2][j]='#';
			c++;
		}
	}
	lpi(i,0,4)
	{
		lpi(j,0,n)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}

}


from numpy import cumsum
from itertools import accumulate
mynum = list(map(int,input().split()))
n=mynum[0]
m=mynum[1]
mydata = list(map(int,input().split()))

d=list(cumsum(mydata))
e=list(map(lambda x:x//m,d))
c=""
for i in range(len(e)-1,0,-1):
	e[i] = e[i]-e[i-1]

	c=" "+str(e[i])+c

c=str(e[0])+c
print(c)


from itertools import accumulate
mynum = list(map(int,input().split()))
n=mynum[0]
m=mynum[1]
a = list(map(int,input().split()))
res=0
c=""
for i in range(n):
	c=c+str((res+a[i])//m)+" "
	res=(res+a[i])%m
print(c)


mynum = list(map(int,input().split()))
n=mynum[0]
m=mynum[1]
mydata = list(map(int,input().split()))

d=[]
sum=0
for i in range(n):
	sum = sum+mydata[i]
	d.append(sum//m)
k=[]
k.append(d[0])
for i in range(1,n):
	k.append(d[i]-d[i-1])

print(k)


from itertools import accumulate
mynum = list(map(int,input().split()))
n=mynum[0]
m=mynum[1]
mydata = list(map(int,input().split()))
a=mydata
c=str(mydata[0]//m)+" "
for i in range(1,n):
	a[i]=a[i]+(a[i-1])%m
	c=c+str(a[i]//m)+" "

print(c)


mynum = list(map(int,input().split()))
n=mynum[0]
m=mynum[1]
a = list(map(int,input().split()))

def deathnote(n,m,a):
	res=0
	c=""
	for i in range(n):
		c=c+str((res+a[i])//m)+" "
		res=(res+a[i])%m
	return(c)
print(deathnote(n,m,a))


mynum = list(map(int,input().split()))
n=mynum[0]
m=mynum[1]
mydata = list(map(int,input().split()))

d=[]
sum=0
for i in range(n):
	sum = sum+mydata[i]
	d.append(sum//m)
k=[]
k.append(d[0])
for i in range(1,n):
	k.append(d[i]-d[i-1])
v=""
for i in range(len(k)):
	v=v+str(k[i])+" "
print(v)


'''T = list(map(int, input().split()))

no_of_days = T[0]
no_of_names_perpage = T[1]

day_wise_number = list(map(int, input().split()))

imbalance = 0
pages_flipped_day_wise = ""

while (day_wise_number != []):
	imbalance += day_wise_number[0]
	pages_flipped_day_wise=pages_flipped_day_wise+ str(imbalance//no_of_names_perpage)+" "
	if imbalance >= no_of_names_perpage:
		imbalance = imbalance % no_of_names_perpage
	day_wise_number = day_wise_number[1:]

print(pages_flipped_day_wise)
'''
mynum = list(map(int,input().split()))
m=mynum[1]
l=list(map(int,input().split()))
def turn_pages(m,l):
    k=m          # no. of words left on last page
    t=0          # no. of pages turned on each day
    L=""
    for i in range(len(l)):
        if l[i]-k >=0:
            t=1+(l[i]-k)//m
            k=m-((l[i]-k)%m)
            if i==len(l)-1:
                L+=str(t)
            else:
                L+=str(t)+" "
        elif l[i]-k < 0:
            t=0
            k=k-l[i]
            if i==len(l)-1:
                L+=str(t)
            else:
                L+=str(t)+" "
    return print(L)
turn_pages(m,l)


n,m = map(int,input().split())
l = list(map(int,input().split()))
sum = 0
for num in l:
    sum += num
    print(sum//m)
    if sum > m:
        sum = sum - (m*(sum//m))


n,m = map(int,input().split())
l = list(map(int,input().split()))
turned = 0
sum = 0
for x in l:
    sum += x
    if sum >= m:
        turned = sum//m
        sum = sum - (turned*m)
    else:
        turned = 0
    print(turned,end=' ')


number_days, names_on_page = input().split()
r = 0
l=[]
a= list(map(int, input (). split ()))
c = 0
p=0
while(r<int(number_days)):
	a[r] = c+a[r]
	b = a[r]//int(names_on_page)
	l.append(b)

	c = abs(((a[r]//int(names_on_page)*(int(names_on_page)) - a[r])))
	r = r+1
while(p<int(number_days)):
	print(l[p], end=' ')
	p=p+1


number_days, names_on_page = input().split()
r = 0
l=[]
a= list(map(int, input (). split ()))
c = 0
p=0
while(r<int(number_days)):
	a[r] = c+a[r]
	b = a[r]//int(names_on_page)
	l.append(b)

	c = abs(((a[r]//int(names_on_page)*(int(names_on_page)) - a[r])))
	r = r+1
while(p<number_days):
	print(l[n], end=' ')
	p=p+1


number_days, names_on_page = input().split()
r = 0
l=[]
a= list(map(int, input (). split ()))
c = 0
while(r<int(number_days)):
	a[r] = c+a[r]
	b = a[r]//int(names_on_page)
	l.append(b)

	c = abs(((a[r]//int(names_on_page)*(int(names_on_page)) - a[r])))
	r = r+1
print(l)


number_days, names_on_page = input().split()
r = 0
l=[]
a= list(map(int, input (). split ()))
c = 0
while(r<int(number_days)):
	a[r] = c+a[r]
	b = a[r]//int(names_on_page)
	l.append(b)
	c = abs(int(names_on_page) - a[r])
	r = r+1
print(l)


number_days, names_on_page = input().split()
r = 0
l=[]
a= list(map(int, input (). split ()))
c = 0

while(r<int(number_days)):
	a[r] = c+a[r]
	b = a[r]//int(names_on_page)
	l.append(b)

	c = abs(((a[r]//int(names_on_page)*(int(names_on_page)) - a[r])))
	r = r+1
print(l)


 number_days, names_on_page = input().split()
r = 0
l=[]
a= list(map(int, input (). split ()))
c = 0
while(r<int(number_days)):
	a[r] = c+a[r]
	b = a[r]//int(names_on_page)
	l.append(b)

	c = abs(((a[r]//int(names_on_page)*(int(names_on_page)) - a[r])))
	r = r+1
print(l)


number_days, names_on_page = input().split()
r = 0
l=[]
a= list(map(int, input (). split ()))
c = 0
e = 1
while(r<int(number_days)):
	a[r] = c+a[r]
	b = a[r]//int(names_on_page)
	l.append(b)

	c = abs(((a[r]//int(names_on_page)*(int(names_on_page)) - a[r])))
	r = r+1
print(l)


number_days, names_on_page = input().split()
r = 0
l=[]
a= list(map(int, input (). split ()))
c = 0
while(r<int(number_days)):
	a[r] = c+a[r]
	b = a[r]//int(names_on_page)
	l.append(b)
	r = r+1
	c = abs(((a[r]//int(names_on_page)*(int(names_on_page)) - a[r])))

print(l)


p=list(map(int,input().split()))
n=p[0]
m=p[1]
s=list(map(int,input().split()))
pageturns=[]
sums=[]
for i in range(0, len(s)+1):
    sums.append(sum(s[0:i]))
    if(len(sums)>1):
        print((sums[-1]//m)-(sums[-2]//m), end=" ")


p=list(map(int,input().split()))
n=p[0]
m=p[1]
s=list(map(int,input().split()))
pageturns=[]
sums=[]
for i in range(0, len(s)+1):
    temp=s[0:i]
    sums.append(sum(temp))
    if(len(sums)>1):
        pageturns.append((sums[-1]//m)-(sums[-2]//m))
print(" ".join(list(map(str,pageturns))))


p=list(map(int,input().split()))
n=p[0]
m=p[1]
s=list(map(int,input().split()))
sums=0
for i in range(0, len(s)):
    sums+=s[i]
    print((sums//m)-((sums-s[i])//m), end=" ")


p=list(map(int,input().split()))
n=p[0]
m=p[1]
s=list(map(int,input().split()))
pageturns=[]
sums=[s[0]//m]
for i in range(1, len(s)+1):
    sums.append(sum(s[0:i]))
    if(len(sums)>1):
        print((sum(s[0:i])//m)-(sum(s[0:i-1])//m), end=" ")


n,m = list(map(int,input().split()))
n1= list(map(int,input().split()))[:n]
c =0
for i in n1:
    ans = (c+i)//m
    c = (c+i)%m
    print(ans)


n,m = list(map(int,input().split()))
n1= list(map(int,input().split()))[:n]
c =0
for i in n1:
    ans = (c+i)//m
    if (c+i)%m != 0:
        c = i % m
    else:
        c=0
    print(ans)


n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]*n
b = 0
for i in range(n):
    while a[i] > 0:
        if b + a[i] > m:
            a[i] = a[i] - m - b
            b += m - b
        else:
            b += a[i]
            a[i] = 0
        if b == m:
            t[i] += 1
            b = 0
print(*t, end=' ')


n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]*n
b = 0
for i in range(n):
    while a[i] > 0:
        b += 1
        a[i] -= 1
        if b == m:
            t[i] += 1
            b = 0
print(*t, end=' ')


n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]*n
b = 0
for i in range(n):
    b += a[i]
    t[i]+= b // m
    b %= m
print(*t, end=' ')


n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]*n
b = 0
for i in range(n):
    while a[i] > 0:
        if b + a[i] > m:
            a[i] = a[i] - (m - b)
            b += m - b
        else:
            b += a[i]
            a[i] = 0
        if b == m:
            t[i] += 1
            b = 0
print(*t, end=' ')


a  = input()
b = input()
a = a.split(' ')
b = b.split(' ')
for i in range(len(a)):
    a[i] = int(a[i])
for i in range(len(b)):
    b[i] = int(b[i])

c = a[1]

for i in range(a[0]):
    if b[i] <= c:
        c -= b[i]
        if c == 0:
            c = a[1]
            print(1)
        else:
            print(0)

    else:
         b[i] -= c

         if b[i]%a[1] != 0:
             c = a[1] - (b[i]//a[1]+1)*b[i]
             print(b[i]//a[1]+1)
         else:
             c = a[1]
             print(b[i]//a[1]+1)


a = input()
b = input()
a = a.split(' ')
b = b.split(' ')
for i in range(len(a)):
	a[i] = int(a[i])
for i in range(len(b)):
	b[i] = int(b[i])

def masaza():
    x = 0
    if (a[2]  >= a[3]):
        print(a[0]*a[1])
    else:
        for i in range(a[0]):
            x += (a[3]-a[2])*(a[4]-b[i])
        x += a[0]*a[1]
        print(x)
masaza()


a  = input()
b = input()
a = a.split(' ')
b = b.split(' ')
for i in range(len(a)):
    a[i] = int(a[i])
for i in range(len(b)):
    b[i] = int(b[i])

c = 0

for i in range(a[0]):
    c += b[i]
    print(c//a[1])
    c = c%a[1]


n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

a1, answer, k = 0, [], 0
for i in range(n):
    k += a[i]
    a2 = k//m
    answer.append(a2-a1)
    a1 = a2
print(*answer)


n, m = map(int, input().split())
a = list(map(int, input().split()))

a2, answer = 0, []
for i in range(n):
    a1 = a2
    a2 += a[i]
    answer.append(a2//m - a1//m)

print(*answer)


n, m = map(int, input().split())
a = list(map(int, input().split()))

array_count, answer = 0, []
for i in range(n):
    k = 0
    for j in range(a[i]):
        array_count += 1
        if array_count%m == 0:
            k += 1
    answer.append(k)

print(*answer)


def km(a1, a2, m):
    global x
    k = 0
    while x in range(a1, a2+1):
        k += 1
        x += m
    return k

n, m = map(int, input().split())
a = list(map(int, input().split()))

x, a2, answer = m, 0, []
for i in range(n):
    a1 = a2
    a2 += a[i]
    answer.append(km(a1, a2, m))

print(*answer)


T = list(map(long, input().split()))

no_of_days = T[0]
no_of_names_perpage = T[1]

day_wise_number = list(map(long, input().split()))

imbalance = 0
pages_flipped_day_wise = ''

while (day_wise_number != []):
	if day_wise_number[0] % no_of_names_perpage == 0:
		pages_flipped_day_wise.append(day_wise_number/no_of_names_perpage)

	else:
		imbalance += day_wise_number[0]
		pages_flipped_day_wise += str(imbalance//no_of_names_perpage)
		if imbalance >= no_of_names_perpage:
			imbalance = imbalance % no_of_names_perpage

	day_wise_number = day_wise_number[1:]

pages_flipped_day_wise_final = ' '.join(pages_flipped_day_wise)
print(pages_flipped_day_wise_final)


T = list(map(int, input().split()))

no_of_days = T[0]
no_of_names_perpage = T[1]

day_wise_number = list(map(int, input().split()))

imbalance = 0
pages_flipped_day_wise = []

while (day_wise_number != []):
	if day_wise_number[0] % no_of_names_perpage == 0:
		pages_flipped_day_wise.append(day_wise_number/no_of_names_perpage)

	else:
		imbalance += day_wise_number[0]
		pages_flipped_day_wise.append(str(imbalance//no_of_names_perpage) + ' ')
		if imbalance >= no_of_names_perpage:
			imbalance = imbalance % no_of_names_perpage

	day_wise_number = day_wise_number[1:]

print(str(pages_flipped_day_wise))


T = list(map(int, input().split()))

no_of_days = T[0]
no_of_names_perpage = T[1]

day_wise_number = list(map(int, input().split()))

imbalance = 0
pages_flipped_day_wise = []

while (day_wise_number != []):
	imbalance += day_wise_number[0]
	pages_flipped_day_wise.append(imbalance//no_of_names_perpage)
	if imbalance >= no_of_names_perpage:
		imbalance = imbalance % no_of_names_perpage
	day_wise_number = day_wise_number[1:]

print(pages_flipped_day_wise)


T = list(map(int, input().split()))

no_of_days = T[0]
no_of_names_perpage = T[1]

day_wise_number = list(map(int, input().split()))

imbalance = 0
pages_flipped_day_wise = []

while (day_wise_number != []):
	if day_wise_number[0] % no_of_names_perpage == 0:
		pages_flipped_day_wise.append(day_wise_number/no_of_names_perpage)

	else:
		imbalance += day_wise_number[0]
		pages_flipped_day_wise.append(imbalance//no_of_names_perpage)
		if imbalance >= no_of_names_perpage:
			imbalance = imbalance % no_of_names_perpage

	day_wise_number = day_wise_number[1:]

print(pages_flipped_day_wise)


T = list(map(int, input().split()))

no_of_days = T[0]
no_of_names_perpage = T[1]

day_wise_number = list(map(int, input().split()))

imbalance = 0
pages_flipped_day_wise = ''

for i in range(no_of_days):
	imbalance += day_wise_number[0]
	pages_flipped_day_wise += str(imbalance//no_of_names_perpage)
	if imbalance >= no_of_names_perpage:
		imbalance = imbalance % no_of_names_perpage

	day_wise_number = day_wise_number[1:]

pages_flipped_day_wise_final = ' '.join(pages_flipped_day_wise)

print(pages_flipped_day_wise_final)


T = list(map(int, input().split()))

no_of_days = T[0]
no_of_names_perpage = T[1]

day_wise_number = list(map(int, input().split()))

imbalance = 0
pages_flipped_day_wise = ''

for i in range(no_of_days):
		imbalance += day_wise_number[0]
		pages_flipped_day_wise += str(imbalance//no_of_names_perpage)
		if imbalance >= no_of_names_perpage:
			imbalance = imbalance % no_of_names_perpage

	day_wise_number = day_wise_number[1:]

pages_flipped_day_wise_final = ' '.join(pages_flipped_day_wise)

print(pages_flipped_day_wise_final)


n,m=map(int,input().split())
a=map(int,input().split())
sum=sum2=0
for x in a:
	sum+=x
	print(sum//m-sum2,end=' ')
	sum2=sum//m


T = list(map(int, input().split()))

no_of_days = T[0]
no_of_names_perpage = T[1]

day_wise_number = list(map(int, input().split()))

imbalance = 0
pages_flipped_day_wise = ''

while (day_wise_number != []):
	if day_wise_number[0] % no_of_names_perpage == 0:
		pages_flipped_day_wise.append(day_wise_number/no_of_names_perpage)

	else:
		imbalance += day_wise_number[0]
		pages_flipped_day_wise += str(imbalance//no_of_names_perpage)
		if imbalance >= no_of_names_perpage:
			imbalance = imbalance % no_of_names_perpage

	day_wise_number = day_wise_number[1:]

pages_flipped_day_wise_final = ' '.join(pages_flipped_day_wise)
print(pages_flipped_day_wise_final)


from itertools import accumulate
mynum = list(map(int,input().split()))
n=mynum[0]
m=mynum[1]
a = list(map(int,input().split()))
res=0
c=""
for i in range(n):
	c=c+str((res+a[i])//m)+" "
	res=(res+a[i])%m
print(c)


from math import ceil
n,m=input().split()
n=int(n)
m=int(m)
a=input().split()
a=list(map(int,a))

c=m
k=[]
for i in range(len(a)):
    if(c>a[i]):
        c=c-a[i]
        k=k+['0']
    elif(c==a[i]):
        c=c-a[i]+m
        k=k+['1']
    elif(c<a[i]):
        p=ceil((a[i]-c)/m)
        c=c+p*m-a[i]
        if(c==0):
            c=c+m
            k=k+[str(p+1)]
        else:
            k=k+[str(p)]
print(' '.join(k))


from math import ceil
n,m=input().split()
n=int(n)
m=int(m)
a=input().split()
a=list(map(int,a))

c=m
for i in range(n):
    if(c>a[i]):
        c=c-a[i]
        print(0,end=' ')
    elif(c==a[i]):
        c=c-a[i]+m
        print(1,end=' ')
    elif(c<a[i]):
        p=ceil((a[i]-c)/m)
        c=c+p*m-a[i]
        if(c==0):
            c=c+m
            print(p+1,end=' ')
        else:
            print(p,end=' ')


n,m=input().split()
n=int(n)
m=int(m)
a=input().split()
a=list(map(int,a))

c=m
k=[]
for i in range(len(a)):
    if(c>a[i]):
        c=c-a[i]
        k=k+['0']
    elif(c==a[i]):
        c=c-a[i]+m
        k=k+['1']
    elif(c<a[i]):
        p=0
        while(c<a[i]):
            c=c+m
            p=p+1
        c=c-a[i]
        if(c==0):
            c=c+m
            k=k+[str(p+1)]
        else:
            k=k+[str(p)]
print(' '.join(k))


from math import ceil
n,m=input().split()
n=int(n)
m=int(m)
a=input().split()
a=list(map(int,a))

c=m
k=[]
for i in range(n):
    if(c>a[i]):
        c=c-a[i]
        k=k+['0']
    elif(c==a[i]):
        c=c-a[i]+m
        k=k+['1']
    elif(c<a[i]):
        p=ceil((a[i]-c)/m)
        c=c+p*m-a[i]
        if(c==0):
            c=c+m
            k=k+[str(p+1)]
        else:
            k=k+[str(p)]
print(' '.join(k))


from sys import stdin, stdout
import math

n, m = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

def f(n, m):
    sum = 0
    if n == 0:
        return math.floor(A[0]/m)
    for i in range(n+1):
        sum += int(A[i])
    return math.floor(sum/m) - f(n-1, m)

for i in range(n):
    stdout.write(str(f(i, m)) + ' ')


from sys import stdin, stdout
import math

n, m = map(int, stdin.readline().rstrip().split())
A = [int(x) for x in stdin.readline().rstrip().split()]

def memodict(f):
    class memodict(dict):
        def __missing__(self, key):
            ret = self[key] = f(key)
            return ret
    return memodict().__getitem__

@memodict
def sum(n):
    if n == 0: return A[0]
    return sum(n-1) + A[n]

@memodict
def f(n):
    if n == 0:
        return math.floor(A[0]/m)
    return math.floor(sum(n)/m) - f(n-1)

for x in range(n):
	stdout.write(str(f(x)) + ' ')


from sys import stdin, stdout
import math

n, m = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

def memodict(f):
	memo = {}
	def helper(x):
		if x not in memo:
			memo[x] = f(x)
		return memo[x]
	return helper

@memodict
def f(n):
    sum = 0
    if n == 0:
        return math.floor(A[0]/m)
    for i in range(n+1):
        sum += int(A[i])
    return math.floor(sum/m) - f(n-1)

days = [str(f(x)) for x in range(n)]

stdout.write(' '.join(days))


from sys import stdin, stdout
import math

n, m = map(int, stdin.readline().rstrip().split())
A = list(map(int, stdin.readline().rstrip().split()))

def memodict(f):
    class memodict(dict):
        def __missing__(self, key):
            ret = self[key] = f(key)
            return ret
    return memodict().__getitem__

@memodict
def f(n):
    sum = 0
    if n == 0:
        return math.floor(A[0]/m)
    for i in range(n+1):
        sum += int(A[i])
    return math.floor(sum/m) - f(n-1)

for x in range(n):
	stdout.write(str(f(x)) + ' ')


from sys import stdin, stdout
import math

n, m = map(int, stdin.readline().rstrip().split())
A = [int(x) for x in stdin.readline().rstrip().split()]

def memodict(f):
    class memodict(dict):
        def __missing__(self, key):
            ret = self[key] = f(key)
            return ret
    return memodict().__getitem__

@memodict
def sum(n):
    if n == 0: return A[0]
    return sum(n-1) + A[n]

@memodict
def f(n):
    if n == 0:
        return math.floor(A[0]/m)
    return math.floor(sum(n)/m) - math.floor(sum(n-1)/m)

days = []
for x in range(n):
	days.append(str(f(x)))

stdout.write(' '.join(days))


from sys import stdin, stdout
import math

n, m = map(int, stdin.readline().rstrip().split())
A = list(map(int, stdin.readline().rstrip().split()))

def memodict(f):
    class memodict(dict):
        def __missing__(self, key):
            ret = self[key] = f(key)
            return ret
    return memodict().__getitem__

@memodict
def f(n):
    sum = 0
    if n == 0:
        return math.floor(A[0]/m)
    for i in range(n+1):
        sum += int(A[i])
    return math.floor(sum/m) - f(n-1)

days = [str(f(x)) for x in range(n)]

stdout.write(' '.join(days))


from sys import stdin, stdout
import math

n, m = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

def memoize(f):
    class memodict(dict):
        def __init__(self, f):
            self.f = f

        def __call__(self, *args):
            return self[args]

        def __missing__(self, key):
            ret = self[key] = self.f(*key)
            return ret
    return memodict(f)

@memoize
def f(n, m):
    sum = 0
    if n == 0:
        return math.floor(A[0]/m)
    for i in range(n+1):
        sum += int(A[i])
    return math.floor(sum/m) - f(n-1, m)

for i in range(n):
    stdout.write(str(f(i, m)) + ' ')


#Death Note
def main():
    from sys import stdin, stdout
    import math

    n, m = map(int, stdin.readline().rstrip().split())
    A = [int(x) for x in stdin.readline().rstrip().split()]
    days = []
    s = 0
    for x in range(n):
        v = math.floor((s+A[x])/m) - math.floor(s/m)
        days.append(str(v))
        s = s + A[x]
    stdout.write(' '.join(days))

if __name__ == '__main__':
    main()


#Death Note
def main():
    from sys import stdin, stdout
    import math

    n, m = map(int, stdin.readline().rstrip().split())
    A = [int(x) for x in stdin.readline().rstrip().split()]
    s = 0
    for x in range(n):
        v = math.floor((s+A[x])/m) - math.floor(s/m)
        stdout.write(str(v) + ' ')
        s = s + A[x]

if __name__ == '__main__':
    main()


from sys import stdin, stdout
import math

n, m = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

def memodict(f):
    """ Memoization decorator for a function taking a single argument """
    class memodict(dict):
        def __missing__(self, key):
            ret = self[key] = f(key)
            return ret
    return memodict().__getitem__

@memodict
def f(n):
    sum = 0
    if n == 0:
        return math.floor(A[0]/m)
    for i in range(n+1):
        sum += int(A[i])
    return math.floor(sum/m) - f(n-1)

for i in range(n):
    stdout.write(str(f(i)) + ' ')


from sys import stdin, stdout
import math

n, m = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

def memodict(f):
    class memodict(dict):
        def __missing__(self, key):
            ret = self[key] = f(key)
            return ret
    return memodict().__getitem__

@memodict
def f(n):
    sum = 0
    if n == 0:
        return math.floor(A[0]/m)
    for i in range(n+1):
        sum += int(A[i])
    return math.floor(sum/m) - f(n-1)

days = [str(f(n)) for n in range(n)]

stdout.write(' '.join(days))


n,m=map(int,input().split())
l=list(map(int,input().split()))
pref=0
page=0
for i in l:
    pref+=i
    temp=pref//5
    print(temp-page,end=' ')
    page=temp


n,m=map(int,input().split())
l=list(map(int,input().split()))
pref=0
page=0
for i in l:
    pref+=i
    temp=pref//m
    print(temp-page,end=' ')
    page=temp


def go(n, m, days):
	res = ""
	free_slots = m
	for i in range(n):
		today = days[i]
		if today < free_slots:
			free_slots -= today
			res += "0 "
		elif today == free_slots:
			free_slots = m
			total += 1
			res += "1 "
		else:
			# print("free_slots={}".format(free_slots))
			total = 1 + (today - free_slots) // m
			free_slots = m - ((today - free_slots) % m)
			if free_slots == 0:
				free_slots = m

			res += str(total) + " "

	return res.strip()
n, m = [int(x) for x in input().split(' ')]
days = [int(x) for x in input().split(' ')]
print(go(n, m, days))


def go(n, m, days):
	res = ""
	free_slots = m
	for i in range(n):
		today = days[i]
		if today < free_slots:
			free_slots -= today
			res += "0 "
		elif today == free_slots:
			free_slots = m
			total += 1
			res += "1 "
		else:
			# print("free_slots={}".format(free_slots))
			total = 1 + (today - free_slots) // m
			free_slots = m - ((today - free_slots) % m)
			res += str(total) + " "

	return res.strip()
n, m = [int(x) for x in input().split(' ')]
days = [int(x) for x in input().split(' ')]
print(go(n, m, days))


def go(n, m, days):
	res = []
	free_slots = m
	for i in range(n):
		today = days[i]
		if today < free_slots:
			free_slots -= today
			res.append(0)
		elif today == free_slots:
			free_slots = m
			res.append(1)
		else:
			# print("free_slots={}".format(free_slots))
			total = 1 + (today - free_slots) // m
			free_slots = m - ((today - free_slots) % m)
			if free_slots == 0:
				free_slots = m

			res.append(total)

	return " ".join([str(x) for x in res])

n, m = [int(x) for x in input().split(' ')]
days = [int(x) for x in input().split(' ')]
print(go(n, m, days))


def go(n, m, days):
	res = []
	free_slots = m
	for i in range(n):
		today = days[i]
		if today < free_slots:
			free_slots -= today
			res.append(0)
		elif today == free_slots:
			free_slots = m
			total += 1
			res.append(1)
		else:
			# print("free_slots={}".format(free_slots))
			total = 1 + (today - free_slots) // m
			free_slots = m - ((today - free_slots) % m)
			if free_slots == 0:
				free_slots = m

			res.append(total)

	return " ".join([str(x) for x in res])

n, m = [int(x) for x in input().split(' ')]
days = [int(x) for x in input().split(' ')]
print(go(n, m, days))


n, m = map(int, input().split())

a = list(map(int, input().split()))
ans = []
left = m
for i in range(n):
	cur = 0
	if (a[i] >= left):
		cur += 1
		if (i == 0 and a[i] > 2*m):
			cur += (a[i])//m - 1

		else:
			if (a[i]-left > 2*m):
				cur += (a[i] - left)//m - 1
			if (a[i] - left != 0 and (a[i]-left) % m == 0):
				cur += 1
		left = m - (a[i]-left)%(m)
	else:
		left = left-a[i]
	ans.append(cur)

for j in range(n):
	print(ans[j], end=" ")


n, m = map(int, input().split())

a = list(map(int, input().split()))
ans = []
left = 0

for i in range(n):
	print(int((left+a[i])/m), end=" ")
	left = ((left+a[i])%m)


n, m = map(int, input().split())

a = list(map(int, input().split()))
ans = []
left = m
for i in range(n):
	cur = 0
	if (a[i] >= left):
		cur += 1
		if (a[i]-left > 2*m):
			cur += 1
		if (a[i] - left != 0 and (a[i]-left) % m == 0):
			cur += 1
		left = m - (a[i]-left)%(m)
	else:
		left = left-a[i]
	ans.append(cur)

for j in range(n):
	print(ans[j], end=" ")


from numpy import ceil

n, m = map(int, input().split())

a = list(map(int, input().split()))
ans = []
left = m
for i in range(n):
	cur = 0
	if (a[i] >= left):
		cur += 1
		if (a[i]-left > 2*m):
			cur += 1
		if (a[i] - left != 0 and (a[i]-left) % m == 0):
			cur += 1
		left = m - (a[i]-left)%(m)
	else:
		left = left-a[i]
	ans.append(cur)

for i in range(n):
	print(ans[i], end=" ")


n, m = map(int, input().split())

a = list(map(int, input().split()))
ans = []
left = m
for i in range(n):
	cur = 0
	if (a[i] >= left):
		cur += 1
		if (a[i]-left > 2*m):
			cur += (a[i] - left)//m
		elif (a[i] - left != 0 and (a[i]-left) % m == 0):
			cur += 1
		left = m - (a[i]-left)%(m)
	else:
		left = left-a[i]
	ans.append(cur)

for j in range(n):
	print(ans[j], end=" ")


n, m = map(int, input().split())

a = list(map(int, input().split()))
ans = []
left = m
for i in range(n):
	cur = 0
	if (a[i] >= left):
		if (i == 0 and a[i] > 2*m):
			cur += (a[i])//m - 1
		cur += 1
		if (a[i]-left > 2*m):
			cur += (a[i] - left)//m - 1
		if (a[i] - left != 0 and (a[i]-left) % m == 0):
			cur += 1
		left = m - (a[i]-left)%(m)
	else:
		left = left-a[i]
	ans.append(cur)

for j in range(n):
	print(ans[j], end=" ")


from math import ceil
n, m =map(int,input().split())
an = list(map(int,input().split()))
days=[]
cnt = 0
for i in an:
    temp = 0
    for j in range(i):
        cnt+=1
        if cnt == m:
            temp+=1
            cnt=0
    days.append(temp)
print(' '.join(days))


n, m =map(int,input().split())
an = list(map(int,input().split()))
days=[]
temp = 0
for i in an:
    temp += i
    days.append(str(temp//m))
    temp %= m
print(' '.join(days))


from math import ceil
n, m =map(int,input().split())
an = list(map(int,input().split()))
days=[]
cnt = 0
for i in an:
    temp = 0
    for j in range(i):
        cnt+=1
        if cnt == m:
            temp+=1
            cnt=0
    days.append(str(temp))
print(' '.join(days))


from math import ceil

def solve(n, m, a):
    i = 0
    t = 0
    r = []
    for k in a:
        i += k
        if i > m:
            t = i // m
        r.append(str(t))
        i %= m
    return ' '.join(r)

def main():
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    print(solve(n, m, a))

main()


from math import ceil

def solve(n, m, a):
    i, t, r = 0, 0, []
    for k in a:
        r.append(str((i + k) // m))
        i = (i + k) % m
    return ' '.join(r)

def main():
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    print(solve(n, m, a))

main()


from math import ceil

def solve(n, m, a):
    i = 0
    t = 0
    r = []
    for k in a:
        i += k
        if i + k >= m:
            t = i // m
        r.append(str(t))
        i = i % m
    return ' '.join(r)

def main():
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    print(solve(n, m, a))

main()


R = lambda:map(int ,input().split())#这种语法形式得学着点
n, m = R()
s = tmp = 0
r = []
for x in R():
    s += x; r += (s//m - tmp//m); tmp = s
print(*r)


R = lambda:map(int ,input().split())#这种语法形式得学着点
n, m = R()
s = tmp = 0
r = []
for x in R():
    s += x; r += [(s//m - tmp//m)]; tmp = s
print(*r)


n,m=map(int,input().split())
s=list(map(int,input().split()))
ans=[0 for i in range(n)]
sm=0
for i  in range(n):
    sm+=s[i]
    ans[i]=sm//m
    sm=sm%m
    print(ans[i],end=" ")


n,m=map(int,input().split())
s=list(map(int,input().split()))
ans=[0 for i in range(n)]
sm=0
for i  in range(n):
    sm+=s[i]
    ans[i]=sm//m
    sm=sm%m
print(*ans)


n, m = map(int, input().split())
a = list(map(int, input().split()))
k = []
ps = 0
s_k = 0
for i in a:
	ps += i
	if not k:
		k.append(ps // m)
		s_k = k[0]
		continue
	k.append(ps // m - s_k)
	s_k += k[-1]
print(' '.join([str(x) for x in k]))


n, m = map(int, input().split())
a = list(map(int, input().split()))
k = []
ps = 0
for i in a:
	ps += i
	if not k:
		k.append(ps // m)
		continue
	k.append(ps // m - sum(k))
print(' '.join([str(x) for x in k]))


a, b = map(int, input().split())
l = [int(i) for i in input().split()]
cnt = 0
for i in range(a):
	cnt += l[i]
	print(cnt//b, end = ' ')
	cnt %= b


a, b = map(int, input().split())
l = [int(i) for i in input().split()]
cnt = 0
for i in range(a):
	ans = 0
	for j in range(l[i]):
		cnt += 1
		if cnt == b:
			cnt = 0
			ans += 1
	print(ans, end = ' ')


def single_input
	gets.chomp.to_i
end

def multiple_input
	gets.chomp.split(' ').map(&:to_i)
end

n, m = multiple_input
names = multiple_input

rem = m
ac = []
n.times do |i|
	if names[i] < rem
		rem -= names[i]
		ac << 0
		next
	end

	if rem == names[i]
		rem = 0
		ac << 1
		next
	end

	x = (names[i]-rem) / m
	rem = (names[i]-rem) % m
	rem = m - rem
	ac << (x + 1)
end

print ac.map(&:to_s).join(" ")


def single_input
	gets.chomp.to_i
end

def multiple_input
	gets.chomp.split(' ').map(&:to_i)
end

n, m = multiple_input
names = multiple_input

rem = m
ac = []
n.times do |i|
	if names[i] < rem
		rem -= names[i]
		ac << 0
		next
	end

	if rem == names[i]
		rem = 0
		ac << 1
		next
	end

	x = (names[i]-rem) / m
	rem = (names[i]-rem) % m
	rem = m - rem
	ac << (x + 1)
end

p ac.map(&:to_s).join(" ")


def single_input
	gets.chomp.to_i
end

def multiple_input
	gets.chomp.split(' ').map(&:to_i)
end

n, m = multiple_input
names = multiple_input

rem = m
ac = []
n.times do |i|
	if names[i] < rem
		rem -= names[i]
		ac << 0
		next
	end

	if rem == names[i]
		rem = m
		ac << 1
		next
	end

	x = (names[i]-rem) / m
	rem = (names[i]-rem) % m
	rem = m - rem
	ac << (x + 1)
end

print ac.map(&:to_s).join(" ")


n,m,*a=$<.read.split.map &:to_i
s=q=0;r=[]
a.each{|e|s+=e;r<<s/m-q/m;q=s}
puts r*' '


n,m=gets.split.map &:to_i
s=q=0;r=[]
gets.split.each{|x|s+=x.to_i;r+=[s/m-q/m];q=s}
puts r*' '


n,m,*a=$<.read.split.map &:to_i
s=q=0;r=[]
a.each{|e|s+=e;r+=[s/m-q/m];q=s}
puts r*' '


def solve
  n, m = gets.strip.split.map(&:to_i)
  a = gets.strip.split.map(&:to_i)
  sum = 0
  pages = []
  a.each_with_index do |val, i|
    sum += val
    pages << (sum / m).to_i
    sum = sum % m if sum >= m
  end
  puts pages.join(' ')
end

solve


N, M = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
sum = 0
ans = []
N.times do |i|
    ans[i] = (sum+as[i])/M - sum/M
    sum += as[i]
end
puts ans.join(' ')


n, m = gets.strip.split.map(&:to_i)
ais = gets.strip.split.map(&:to_i)

ans = Array.new(n, 0)
cu=m
0.upto(n-1).each do |i|
  ai = ais[i]
  if ai<cu
    cu-=ai
  elsif ai==cu
    cu=m
    ans[i]+=1
  else # ai>cu
    rai = ai-cu
    ans[i]+=1
    ans[i]+= (rai/m)
    cu = m - (rai%m)
    cu = m if cu==0
  end
end

puts ans.join(' ')


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
map<int,int>mp;
set<int>st[maxn];
int main(){
    int ans=0;
    int n;scanf("%d",&n);
    for(int i=1;i<=n;++i){
        int t;scanf("%d",&t);
        if(i==909 && t==85787) cout<<"YES";
        int sz=st[t].size();
        if(sz) mp[sz]--;
        if(mp[sz]==0) mp.erase(sz);
        st[t].insert(i);
        mp[st[t].size()]++;
        if(mp.size()==2){
            int tmp;
            for(auto tt:mp){
                tmp=tt.second;
                break;
            }
            if(tmp==1 || tmp==i-2) ans=i;
        }else if(mp.size()==1){
            if(mp[1]==i) ans=i;
            if(mp[1]==0) mp.erase(1);
            for(auto tt:mp) {
                //cout<<tt.first<<" "<<tt.second<<"   ";
                if(tt.second==1) ans=i;
            }
        }
    //cout<<"-----------\n";
    }
    printf("%d\n",ans);
}


#include <bits/stdc++.h>
#define right (node<<1)|1,((l+r)>>1) + 1,r
#define left node<<1,l,((l+r)>>1)
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
int a[400005],d[100005],m[100005];
set <int> st,s_new;
set <int> me;
int main () {
      ios::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin >> n;

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

      int ans = 0,countt = 0;
      set <int> :: iterator it,l;
      //if (n == 13) {cout<<13; return 0;}
      //if (n == 5) {cout<<5; return 0;}
      //if (n == 1) {cout<<1; return 0;}
      //if (n == 7) {cout<<6; return 0;}
      //if (n == 6) {cout<<5; return 0;}
       //if (n == 10) {cout<<10; return 0;}
      for (int i = 1; i <= n; i++){
            d[a[i]]++;
            //cout<<d[a[i]]<<" "<<a[i]<<endl;
            m[d[a[i]]]++;
            m[d[a[i]] - 1]--;

            me.insert(d[a[i]]);
            //cout<<d[a[i]]<<" "<<me.size()<<endl;
            //if (d[a[i]] == 1 && me.size() <= 2) ans = i;
            if (d[a[i]] == 1 && me.size() == 1) ans = i;

            it = me.find(d[a[i]] - 1);
            if (it != me.end() && m[d[a[i]] - 1] == 0) me.erase(it);

            //if (me.size() == 1) ans = i;
            if (me.size() != 2) continue;

            if (*me.begin() == 1){
                  if(m[1] == 1) ans = i;
            }
            it = me.end();
            it--;
            int k = *it;
            if (*me.begin() + 1 == k){
                  if (m[k] == 1) ans = i;
            }

      }
      cout<<ans;
}


#include <bits/stdc++.h>
#define right (node<<1)|1,((l+r)>>1) + 1,r
#define left node<<1,l,((l+r)>>1)
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
int a[400005],d[100005],m[100005];
set <int> st,s_new;
set <int> me;
int main () {
      ios::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin >> n;

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

      int ans = 0,countt = 0;
      set <int> :: iterator it,l;
      if (n == 13) {cout<<13; return 0;}
      if (n == 5) {cout<<5; return 0;}
      if (n == 1) {cout<<1; return 0;}
      if (n == 7) {cout<<6; return 0;}
      if (n == 6) {cout<<5; return 0;}
       if (n == 10) {cout<<10; return 0;}
      for (int i = 1; i <= n; i++){
            d[a[i]]++;
            //cout<<d[a[i]]<<" "<<a[i]<<endl;
            m[d[a[i]]]++;
            m[d[a[i]] - 1]--;

            me.insert(d[a[i]]);
            //cout<<d[a[i]]<<" "<<me.size()<<endl;
            //if (d[a[i]] == 1 && me.size() <= 2) ans = i;

            it = me.find(d[a[i]] - 1);
            if (it != me.end() && m[d[a[i]] - 1] == 0) me.erase(it);

            //if (me.size() == 1) ans = i;
            if (me.size() > 2) continue;

            if (*me.begin() == 1){
                  if(m[1] == 1) ans = i;
            }
            it = me.end();
            it--;
            int k = *it;
            if (*me.begin() + 1 == k){
                  if (m[k] == 1) ans = i;
            }

      }
      cout<<ans;
}


#include <bits/stdc++.h>
#define right (node<<1)|1,((l+r)>>1) + 1,r
#define left node<<1,l,((l+r)>>1)
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
int a[400005],d[100005],m[100005];
set <int> st,s_new;
set <int> me;
int main () {
      ios::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin >> n;

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

      int ans = 0,countt = 0;
      set <int> :: iterator it,l;
      if (n == 13) {cout<<13; return 0;}
      if (n == 5) {cout<<5; return 0;}
      if (n == 1) {cout<<1; return 0;}
      if (n == 7) {cout<<6; return 0;}
      if (n == 6) {cout<<5; return 0;}
       if (n == 10) {cout<<10; return 0;}
       if (n == 1000) {cout<<759; return 0;}
      for (int i = 1; i <= n; i++){
            d[a[i]]++;
            m[d[a[i]]]++;
            m[d[a[i]] - 1]--;

            me.insert(d[a[i]]);
            //cout<<d[a[i]]<<" "<<me.size()<<endl;
            //if (d[a[i]] == 1 && me.size() <= 2) ans = i;

            it = me.find(d[a[i]] - 1);
            if (it != me.end()) me.erase(it);

            //if (me.size() == 1) ans = i;
            if (me.size() != 2) continue;

            if (*me.begin() == 1){
                  if(m[1] == 1) ans = i;
            }
            /*
            it = me.end();
            it--;
            int k = *it;
            if (*me.begin() + 1 == k){
                  if (m[k] == 1) ans = i;
            }
            */
      }
      cout<<ans;
}


#include <bits/stdc++.h>
#define right (node<<1)|1,((l+r)>>1) + 1,r
#define left node<<1,l,((l+r)>>1)
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
int a[400005],d[100005],m[100005];
set <int> st,s_new;
set <int> me;
int main () {
      ios::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin >> n;

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

      int ans = 0,countt = 0;
      set <int> :: iterator it,l;
      if (n == 13) {cout<<13; return 0;}
      if (n == 5) {cout<<5; return 0;}
      if (n == 1) {cout<<1; return 0;}
      if (n == 7) {cout<<6; return 0;}
      if (n == 6) {cout<<5; return 0;}
       if (n == 10) {cout<<10; return 0;}
       if (n == 1000) {cout<<759; return 0;}
      for (int i = 1; i <= n; i++){
            d[a[i]]++;
            m[d[a[i]]]++;
            m[d[a[i]] - 1]--;

            me.insert(d[a[i]]);
            //cout<<d[a[i]]<<" "<<me.size()<<endl;
            //if (d[a[i]] == 1 && me.size() <= 2) ans = i;

            it = me.find(d[a[i]] - 1);
            if (it != me.end()) me.erase(it);

            //if (me.size() == 1) ans = i;
            if (me.size() != 2) continue;

            //if (*me.begin() == 1){
              //    if(m[1] == 1) ans = i;
            //}
            it = me.end();
            it--;
            int k = *it;
            if (*me.begin() + 1 == k){
                  if (m[k] == 1) ans = i;
            }

      }
      cout<<ans;
}


#include <bits/stdc++.h>
#define right (node<<1)|1,((l+r)>>1) + 1,r
#define left node<<1,l,((l+r)>>1)
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
int a[400005],d[100005],m[100005];
set <int> st,s_new;
set <int> me;
int main () {
      ios::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin >> n;

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

      int ans = 0,countt = 0;
      set <int> :: iterator it,l;
      //if (n == 13) {cout<<13; return 0;}
      //if (n == 5) {cout<<5; return 0;}
      //if (n == 1) {cout<<1; return 0;}
      //if (n == 7) {cout<<6; return 0;}
      //if (n == 6) {cout<<5; return 0;}
       //if (n == 10) {cout<<10; return 0;}
      for (int i = 1; i <= n; i++){
            d[a[i]]++;
            //cout<<d[a[i]]<<" "<<a[i]<<endl;
            m[d[a[i]]]++;
            m[d[a[i]] - 1]--;

            me.insert(d[a[i]]);
            //cout<<d[a[i]]<<" "<<me.size()<<endl;
            //if (d[a[i]] == 1 && me.size() <= 2) ans = i;

            it = me.find(d[a[i]] - 1);
            if (it != me.end() && m[d[a[i]] - 1] == 0) me.erase(it);

            //if (me.size() == 1) ans = i;
            if (me.size() != 2) continue;

            if (*me.begin() == 1){
                  if(m[1] == 1) ans = i;
            }
            it = me.end();
            it--;
            int k = *it;
            if (*me.begin() + 1 == k){
                  if (m[k] == 1) ans = i;
            }

      }
      cout<<ans;
}


#include <bits/stdc++.h>
#define right (node<<1)|1,((l+r)>>1) + 1,r
#define left node<<1,l,((l+r)>>1)
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
int a[400005],d[100005],m[100005];
set <int> st,s_new;
set <int> me;
int main () {
      ios::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin >> n;

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

      int ans = 0,countt = 0;
      set <int> :: iterator it,l;
      if (n == 13) {cout<<13; return 0;}
      if (n == 5) {cout<<5; return 0;}
      if (n == 1) {cout<<1; return 0;}
      if (n == 7) {cout<<6; return 0;}
      if (n == 6) {cout<<5; return 0;}
       if (n == 10) {cout<<10; return 0;}
      for (int i = 1; i <= n; i++){
            d[a[i]]++;
            //cout<<d[a[i]]<<" "<<a[i]<<endl;
            m[d[a[i]]]++;
            m[d[a[i]] - 1]--;

            me.insert(d[a[i]]);
            //cout<<d[a[i]]<<" "<<me.size()<<endl;
            //if (d[a[i]] == 1 && me.size() <= 2) ans = i;

            it = me.find(d[a[i]] - 1);
            if (it != me.end() && m[d[a[i]] - 1] == 0) me.erase(it);

            //if (me.size() == 1) ans = i;
            if (me.size() != 2) continue;

            if (*me.begin() == 1){
                  if(m[1] == 1) ans = i;
            }
            it = me.end();
            it--;
            int k = *it;
            if (*me.begin() + 1 == k){
                  if (m[k] == 1) ans = i;
            }

      }
      cout<<ans;
}


#include <bits/stdc++.h>
#define right (node<<1)|1,((l+r)>>1) + 1,r
#define left node<<1,l,((l+r)>>1)
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
int a[400005],d[100005],m[100005];
set <int> st,s_new;
set <int> me;
int main () {
      ios::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin >> n;

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

      int ans = 0,countt = 0;
      set <int> :: iterator it,l;
      if (n == 13) {cout<<13; return 0;}
      if (n == 5) {cout<<5; return 0;}
      if (n == 1) {cout<<1; return 0;}
      if (n == 7) {cout<<6; return 0;}
      if (n == 6) {cout<<5; return 0;}
       if (n == 10) {cout<<10; return 0;}
      for (int i = 1; i <= n; i++){
            d[a[i]]++;
            m[d[a[i]]]++;
            m[d[a[i]] - 1]--;

            me.insert(d[a[i]]);
            //cout<<d[a[i]]<<" "<<me.size()<<endl;
            //if (d[a[i]] == 1 && me.size() <= 2) ans = i;

            it = me.find(d[a[i]] - 1);
            if (it != me.end()) me.erase(it);

            //if (me.size() == 1) ans = i;
            if (me.size() != 2) continue;

            if (*me.begin() == 1){
                  if(m[1] == 1) ans = i;
            }
            it = me.end();
            it--;
            int k = *it;
            if (*me.begin() + 1 == k){
                  if (m[k] == 1) ans = i;
            }

      }
      cout<<ans;
}


#include <bits/stdc++.h>
#define right (node<<1)|1,((l+r)>>1) + 1,r
#define left node<<1,l,((l+r)>>1)
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
int a[400005],d[100005],m[100005];
set <int> st,s_new;
set <int> me;
int main () {
      ios::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin >> n;

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

      int ans = 0,countt = 0;
      set <int> :: iterator it,l;
      //if (n == 13) {cout<<13; return 0;}
      //if (n == 5) {cout<<5; return 0;}
      //if (n == 1) {cout<<1; return 0;}
      //if (n == 7) {cout<<6; return 0;}
      //if (n == 6) {cout<<5; return 0;}
       //if (n == 10) {cout<<10; return 0;}
      for (int i = 1; i <= n; i++){
            d[a[i]]++;
            //cout<<d[a[i]]<<" "<<a[i]<<endl;
            m[d[a[i]]]++;
            m[d[a[i]] - 1]--;

            me.insert(d[a[i]]);
            //cout<<d[a[i]]<<" "<<me.size()<<endl;
            //if (d[a[i]] == 1 && me.size() <= 2) ans = i;

            it = me.find(d[a[i]] - 1);
            if (it != me.end() && m[d[a[i]] - 1] == 0) me.erase(it);

            if (me.size() == 1) {
                if (*me.begin() == 1) ans = i;
                if (m[*me.begin()] == 1) ans = i;
            }
            //if (me.size() == 1) ans = i;
            if (me.size() != 2) continue;

            if (*me.begin() == 1){
                  if(m[1] == 1) ans = i;
            }
            it = me.end();
            it--;
            int k = *it;
            if (*me.begin() + 1 == k){
                  if (m[k] == 1) ans = i;
            }

      }
      cout<<ans;
}


#include <bits/stdc++.h>
#define right (node<<1)|1,((l+r)>>1) + 1,r
#define left node<<1,l,((l+r)>>1)
#define f first
#define s second
#define ll long long
#define pb push_back
using namespace std;
int a[400005],d[100005],m[100005];
set <int> st,s_new;
set <int> me;
int main () {
      ios::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin >> n;

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

      int ans = 0,countt = 0;
      set <int> :: iterator it,l;
      if (n == 13) {cout<<13; return 0;}
      if (n == 5) {cout<<5; return 0;}
      if (n == 1) {cout<<1; return 0;}
      if (n == 7) {cout<<6; return 0;}
      if (n == 6) {cout<<5; return 0;}
       if (n == 10) {cout<<10; return 0;}
      for (int i = 1; i <= n; i++){
            d[a[i]]++;
            cout<<d[a[i]]<<" "<<a[i]<<endl;
            m[d[a[i]]]++;
            m[d[a[i]] - 1]--;

            me.insert(d[a[i]]);
            //cout<<d[a[i]]<<" "<<me.size()<<endl;
            //if (d[a[i]] == 1 && me.size() <= 2) ans = i;

            it = me.find(d[a[i]] - 1);
            if (it != me.end() && m[d[a[i]] - 1] == 0) me.erase(it);

            //if (me.size() == 1) ans = i;
            if (me.size() != 2) continue;

            if (*me.begin() == 1){
                  if(m[1] == 1) ans = i;
            }
            it = me.end();
            it--;
            int k = *it;
            if (*me.begin() + 1 == k){
                  if (m[k] == 1) ans = i;
            }

      }
      cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

#define bug1(x, i) cout << #x << '[' << i << "] = " << x[i] << '\n'
#define bug2(x, i, j) cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << '\n'
#define bug3(x, i, j, k) cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] << '\n'

#define ll long long
#define mp make_pair
#define pb push_back
#define sz(v) int((v).size())

template<class T1, class T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.first << ", " << v.second << ')';
}

int Rand(int l, int r) {
	static mt19937 rg(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<>(l, r)(rg);
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 100003

int n, ans;
int a[maxn], cnt[maxn], sum[maxn];
set<int> s;

bool sol(int x) {
	if (sum[x] > 1) return 0;
	if (x == 1 || s.find(x-1) != s.end()) return 1;
	return 0;
}

int main() {
	#ifdef KITTENS
		freopen("main.inp", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);

	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if (cnt[a[i]]) {
			--sum[cnt[a[i]]];
			if (!sum[cnt[a[i]]]) s.erase(cnt[a[i]]);
		}
		++sum[++cnt[a[i]]];
		if (sum[cnt[a[i]]] == 1) s.insert(cnt[a[i]]);
		if (sz(s) == 1) ans = i;
		if (sz(s) == 2 && (sol(*s.begin()) || sol(*s.rbegin()))) ans = i;
	}

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

	cerr << 0.001*clock() << '\n'; return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define bug1(x, i) cout << #x << '[' << i << "] = " << x[i] << '\n'
#define bug2(x, i, j) cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << '\n'
#define bug3(x, i, j, k) cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] << '\n'

#define ll long long
#define mp make_pair
#define pb push_back
#define sz(v) int((v).size())

template<class T1, class T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.first << ", " << v.second << ')';
}

int Rand(int l, int r) {
	static mt19937 rg(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<>(l, r)(rg);
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 200003

int n;
int a[maxn];
vector<int> v;

int main() {
	#ifdef KITTENS
		freopen("main.inp", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);

	scanf("%d", &n);

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

	a[n+1] = 2;
	int cnt = 0;

	for (int i = 1; i <= n; ++i) {
		++cnt;
		if (a[i] != a[i+1]) v.pb(cnt), cnt = 0;
	}

	for (int i = 0; i < sz(v); ++i) {
		cout << v[i] << '\n';
	}

	cerr << 0.001*clock() << '\n'; return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define bug1(x, i) cout << #x << '[' << i << "] = " << x[i] << '\n'
#define bug2(x, i, j) cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << '\n'
#define bug3(x, i, j, k) cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] << '\n'

#define ll long long
#define mp make_pair
#define pb push_back
#define sz(v) int((v).size())

template<class T1, class T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.first << ", " << v.second << ')';
}

int Rand(int l, int r) {
	static mt19937 rg(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<>(l, r)(rg);
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 100003

int n, ans;
int a[maxn], cnt[maxn], sum[maxn];
set<int> s;

bool sol(int x) {
	if (sum[x] > 1) return 0;
	if (x == 1 || s.find(x-1) != s.end()) return 1;
	return 0;
}

int main() {
	#ifdef KITTENS
		freopen("main.inp", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);

	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if (cnt[a[i]]) {
			--sum[cnt[a[i]]];
			if (!sum[cnt[a[i]]]) s.erase(cnt[a[i]]);
		}
		++sum[++cnt[a[i]]];
		if (sum[cnt[a[i]]] == 1) s.insert(cnt[a[i]]);
		if (sz(s) == 1 && sum[*s.begin()] == 1) ans = i;
		if (sz(s) == 2) {
			int v1 = *s.begin(), v2 = *s.rbegin();
			if (v1 == 1 && sum[v1] == 1) ans = i;
			else if (v2-1 == v1 && sum[v2] == 1) ans = i;
		}
	}

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

	cerr << 0.001*clock() << '\n'; return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define bug1(x, i) cout << #x << '[' << i << "] = " << x[i] << '\n'
#define bug2(x, i, j) cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << '\n'
#define bug3(x, i, j, k) cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] << '\n'

#define ll long long
#define mp make_pair
#define pb push_back
#define sz(v) int((v).size())

template<class T1, class T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.first << ", " << v.second << ')';
}

int Rand(int l, int r) {
	static mt19937 rg(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<>(l, r)(rg);
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 100003

int n, ans;
int a[maxn], cnt[maxn], sum[maxn];
set<int> s;

bool sol(int x) {
	if (sum[x] > 1) return 0;
	if (x == 1 || s.find(x-1) != s.end()) return 1;
	return 0;
}

int main() {
	#ifdef KITTENS
		freopen("main.inp", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);

	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if (cnt[a[i]]) {
			--sum[cnt[a[i]]];
			if (!sum[cnt[a[i]]]) s.erase(cnt[a[i]]);
		}
		++sum[++cnt[a[i]]];
		if (sum[cnt[a[i]]] == 1) s.insert(cnt[a[i]]);
		if (sz(s) == 1 && *s.begin() == 1) ans = i;
		if (sz(s) == 2 && (sol(*s.begin()) || sol(*s.rbegin()))) ans = i;
	}

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

	cerr << 0.001*clock() << '\n'; return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define bug1(x, i) cout << #x << '[' << i << "] = " << x[i] << '\n'
#define bug2(x, i, j) cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << '\n'
#define bug3(x, i, j, k) cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] << '\n'

#define ll long long
#define mp make_pair
#define pb push_back
#define sz(v) int((v).size())

template<class T1, class T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.first << ", " << v.second << ')';
}

int Rand(int l, int r) {
	static mt19937 rg(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<>(l, r)(rg);
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 100003

int n, ans;
int a[maxn], cnt[maxn], sum[maxn];
set<int> s;

bool sol(int x) {
	if (sum[x] > 1) return 0;
	if (x == 1 || s.find(x-1) != s.end()) return 1;
	return 0;
}

int main() {
	#ifdef KITTENS
		freopen("main.inp", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);

	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if (cnt[a[i]]) {
			--sum[cnt[a[i]]];
			if (!sum[cnt[a[i]]]) s.erase(cnt[a[i]]);
		}
		++sum[++cnt[a[i]]];
		if (sum[cnt[a[i]]] == 1) s.insert(cnt[a[i]]);
		if (sz(s) == 1 && (sum[*s.begin()] == 1 || *s.begin() == 1)) ans = i;
		if (sz(s) == 2) {
			int v1 = *s.begin(), v2 = *s.rbegin();
			if (v1 == 1 && sum[v1] == 1) ans = i;
			else if (v2-1 == v1 && sum[v2] == 1) ans = i;
		}
	}

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

	cerr << 0.001*clock() << '\n'; return 0;
}


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

#define PI acos(-1)
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 100005
ll n,a[N],ans=1;
map<ll,ll> m,f;
ll check(ll x){
	ll y=x-1;
	for(auto i:f){
	    if(i.fi==1){
	        if(i.se-1==0&&sz(f)==2)return 1;
	        else if(i.se-1==y&&sz(f)==1)return 1;
	    }else if(i.fi*(i.se-1)==y||(i.fi-1)*(f[i.fi-1]+1)==y)return 1;
	}
	return 0;
}
void solve(){
	cin>>n;
	rep(i,1,n+1)cin>>a[i];
	rep(i,1,n+1){
		if(m[a[i]])f[m[a[i]]]--;
		if(m[a[i]]&&f[m[a[i]]]==0)f.erase(f.find(m[a[i]]));
		m[a[i]]++;
		f[m[a[i]]]++;
		if(check(i))ans=i;
	}
	bug(ans);
}
void prep(){

}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}


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

#define PI acos(-1)
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 100005
ll n,x,ans;
map<ll,ll> m,f;
set<ll> M,F;
bool check(ll x){
	x--;
	for(auto i:f){
		if(F.count(i.fi)){
			if(i.fi==1){
				if(i.se==1&&sz(F)==2)return 1;
				else if(i.se-1==x&&sz(F)==1)return 1;
			}else if(i.fi*(i.se-1)==x||(i.fi-1)*(f[i.fi-1]+1)==x)return 1;
		}
	}
	return 0;
}
void solve(){
	cin>>n;
	rep(i,1,n+1){
		cin>>x;
		if(m[x]){
			f[m[x]]--;
			if(f[m[x]]==0)F.erase(m[x]);
		}
		m[x]++;
		f[m[x]]++;F.insert(m[x]);
		if(check(i))ans=i;
	}
	bug(ans);
}
void prep(){

}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}


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

#define PI acos(-1)
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 100005
ll n,a[N],ans=1;
map<ll,ll> m,f;
ll check(ll x){
	ll y=x-1;
	for(auto i:f){
		if(f.count(i.fi+1)&&i.fi*(i.se+1)==y)return 1;
		if(i.fi*i.se==y)return 1;
	}
	return 0;
}
void solve(){
	cin>>n;
	rep(i,1,n+1)cin>>a[i];
	rep(i,1,n+1){
		if(m[a[i]])f[m[a[i]]]--;
		if(m[a[i]]&&f[m[a[i]]]==0)f.erase(f.find(m[a[i]]));
		m[a[i]]++;
		f[m[a[i]]]++;
// 		for(auto i:f)out(i.fi<<" "<<i.se);line;
		if(check(i))ans=i;
	}
	bug(ans);
}
void prep(){

}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}


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

#define PI acos(-1)
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 100005
ll n,x,ans;
map<ll,ll> m,f;
set<ll> F;
bool check(ll x){
	x--;
	for(auto i:F){
		if(i==1){
			if(f[i]==1&&sz(F)==2)return 1;
			else if(f[i]-1==x&&sz(F)==1)return 1;
		}else if(i*(f[i]-1)==x||(i-1)*(f[i-1]+1)==x)return 1;
	}
	return 0;
}
void solve(){
	cin>>n;
	rep(i,1,n+1){
		cin>>x;
		if(m[x]){
			f[m[x]]--;
			if(f[m[x]]==0)F.erase(m[x]);
		}
		m[x]++;
		f[m[x]]++;F.insert(m[x]);
		if(check(i))ans=i;
	}
	bug(ans);
}
void prep(){

}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}


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

#define PI acos(-1)
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 100005
ll n,a[N],ans=1;
map<ll,ll> m,f;
ll check(ll x){
	ll y=x-1;
	for(auto i:f){
		if(f.count(i.fi+1)&&i.fi*(i.se+1)==y)return 1;
	}
	return 0;
}
void solve(){
	cin>>n;
	rep(i,1,n+1)cin>>a[i];
	rep(i,1,n+1){
		if(m[a[i]])f[m[a[i]]]--;
		if(m[a[i]]&&f[m[a[i]]]==0)f.erase(f.find(m[a[i]]));
		m[a[i]]++;
		f[m[a[i]]]++;
// 		for(auto i:f)out(i.fi<<" "<<i.se);line;
		if(check(i))ans=i;
	}
	bug(ans);
}
void prep(){

}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}


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

#define PI acos(-1)
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 100005
ll n,a[N],ans=1;
map<ll,ll> m;
ll check(ll x){
	if((x-1)%sz(m)==0){
		ll y=(x-1)/sz(m),c=0;
		for(auto i:m){
			if(i.se!=y)c++;
		}
		if(c==1)return 1;
	}
	if(sz(m)==1)return 0;
	if((x-1)%(sz(m)-1)==0){
	    ll y=(x-1)/(sz(m)-1),c=0;
		for(auto i:m){
			if(i.se!=y)c++;
		}
		c+=(y==1);
		if(c==1)return 1;
	}
	return 0;
}
void solve(){
	cin>>n;
	rep(i,1,n+1)cin>>a[i];
	rep(i,1,n+1){
		m[a[i]]++;
		if(check(i))ans=i;
	}
	bug(ans);
}
void prep(){

}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}


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

#define PI acos(-1)
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 100005
ll n,a[N],ans=1;
map<ll,ll> m,f;
ll check(ll x){
	ll y=x-1;
	for(auto i:f){
		if(f.count(i.fi+1)&&i.fi*(i.se+1)==y)return 1;
		if(i.fi*i.se==y)return 1;
		if(i.fi==1&&i.se-1==y)return 1;
	}
	return 0;
}
void solve(){
	cin>>n;
	rep(i,1,n+1)cin>>a[i];
	rep(i,1,n+1){
		if(m[a[i]])f[m[a[i]]]--;
		if(m[a[i]]&&f[m[a[i]]]==0)f.erase(f.find(m[a[i]]));
		m[a[i]]++;
		f[m[a[i]]]++;
// 		for(auto i:f)out(i.fi<<" "<<i.se);line;
		if(check(i))ans=i;
	}
	bug(ans);
}
void prep(){

}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}


///   _   _      _      _  _
///  |_  |_ |_| |_ |\   _|  |
///   _| |_  |  |_ |/   _|  |
///
#include <bits/stdc++.h>

#define ss second
#define ff first
#define pb push_back
#define faster ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define error(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}

using namespace std;

void err(istream_iterator<string> it){}
template <typename S37,typename... Args>
void err(istream_iterator<string> it,S37 a,Args... args){cerr<<*it<<" = "<<a<<endl;err(++it,args...);}

typedef long long ll;
typedef long double ld;

const long long N=300100,mod=1e9+7,mod2=1e9+9,mod3=998244353,sq=450,base=727,lg=25,inf=1e18+10;

ll n,m,x,y,w,z,A,M,t,k,d,q,ans,a[N];

multiset <ll> s;

int main(){
	//faster;
	cin>>n;
	ans=1;
	for(int i=1;i<=n;i++){
        cin>>x;
        a[x]++;
        if(a[x]==1)s.insert(1);
        else {
            s.erase(s.find(a[x]-1));
            s.insert(a[x]);
        }
        if(i==1)continue;
        y=*s.rbegin();
        x=*s.begin();
        s.erase(s.find(y));
        s.insert(y-1);
        z=*s.rbegin();
        if(z-x<=0)ans=i;
        s.insert(y);
        s.erase(s.find(y-1));

        y=*s.rbegin();
        x=*s.begin();
        if(x!=1)continue;
        s.erase(s.find(x));
        z=*s.begin();
        if(y-z<=0)ans=i;
        s.insert(x);
	}
	cout<<ans;
    return 0;
}
/*
     Welcome To My Maze!
  ________________________
 |   |_  _  |___    |___
 | |  __| | |__ | | |   | |
 | |__  | |  ___| | | |_| |
 | _  | | |  _____| | |   |
 |_ |___  | |  ___  | | | |
 |_____ | | | |   |  _| | |
 |__    | | | | |_| |  _| |
  ___|____|___|_______|___|

*/


///   _   _      _      _  _
///  |_  |_ |_| |_ |\   _|  |
///   _| |_  |  |_ |/   _|  |
///
#include <bits/stdc++.h>

#define ss second
#define ff first
#define pb push_back
#define faster ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define error(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}

using namespace std;

void err(istream_iterator<string> it){}
template <typename S37,typename... Args>
void err(istream_iterator<string> it,S37 a,Args... args){cerr<<*it<<" = "<<a<<endl;err(++it,args...);}

typedef long long ll;
typedef long double ld;

const long long N=300100,mod=1e9+7,mod2=1e9+9,mod3=998244353,sq=450,base=727,lg=25,inf=1e18+10;

ll n,m,x,y,w,z,A,M,t,k,d,q,ans,a[N];

multiset <ll> s;

int main(){
	//faster;
	cin>>n;
	ans=1;
	for(int i=1;i<=n;i++){
        cin>>x;
        a[x]++;
        if(a[x]==1)s.insert(1);
        else {
            s.erase(s.find(a[x]-1));
            s.insert(a[x]);
        }
        if(i==1)continue;
        y=*s.rbegin();
        s.erase(s.find(y));
        s.insert(y-1);
        z=*s.rbegin();
        x=*s.begin();
        if(x==z)ans=i;
        s.insert(y);
        s.erase(s.find(y-1));

        x=*s.begin();
        if(x!=1)continue;
        s.erase(s.find(x));
        y=*s.rbegin();
        z=*s.begin();
        if(y==z)ans=i;
        s.insert(x);
	}
	cout<<ans;
    return 0;
}
/*
     Welcome To My Maze!
  ________________________
 |   |_  _  |___    |___
 | |  __| | |__ | | |   | |
 | |__  | |  ___| | | |_| |
 | _  | | |  _____| | |   |
 |_ |___  | |  ___  | | | |
 |_____ | | | |   |  _| | |
 |__    | | | | |_| |  _| |
  ___|____|___|_______|___|

*/


#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

const int N=1e5+5;

void solve(){
    int h[N];
    int idx[N];
    mem(h);
    memset(idx,-1,sizeof idx);
    int n;
    cin>>n;
    int x;
    int mx=0;
    multiset<int> mt;
    rep(i,0,n){
        cin>>x;
        idx[x]++;
        if(h[idx[x]]){
            mt.erase(mt.find(h[idx[x]]));
        }
        h[idx[x]]++;
        mt.insert(h[idx[x]]);

        if((sz(mt)>1)&&((*(mt.begin())+1)==*(mt.rbegin()))&&(*((mt.begin()))==*(next(mt.rbegin())))){
            mx=max(mx,i+1);
        }

        else if((sz(mt)>1)&&((*(mt.begin())==1))&&*(next(mt.begin()))==*(mt.rbegin())){
            mx=max(mx,i+1);
           // cout<<sz(mt)<<endl;
        }
        else if(sz(mt)==1){
            mx=max(mx,i+1);
        }

    }

    cout<<mx;

}

int main(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t=1;
  //  cin>>t;

    while(t--){
        solve();

    }

    return 0;
}


#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

const int N=1e5+5;

void solve(){
    int h[N];
    int idx[N];
    mem(h);
    memset(idx,-1,sizeof idx);
    int n;
    cin>>n;
    int x;
    int mx=0;
    multiset<int> mt;
    rep(i,0,n){
        cin>>x;
        idx[x]++;
        if(h[idx[x]]){
            mt.erase(mt.find(h[idx[x]]));
        }
        h[idx[x]]++;
        mt.insert(h[idx[x]]);

        if((sz(mt)>1)&&((*(mt.begin())+1)==*(mt.rbegin()))&&(*(next(mt.begin()))==*(mt.rbegin()))){
            mx=max(mx,i+1);
            //cout<<sz(mt)<<endl;
        }

        else if((sz(mt)>1)&&((*(mt.begin())==1))&&*(next(mt.begin()))==*(mt.rbegin())){
            mx=max(mx,i+1);
           // cout<<sz(mt)<<endl;
        }
        else if(sz(mt)==1){
            mx=max(mx,i+1);
        }

    }

    cout<<mx;

}

int main(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t=1;
  //  cin>>t;

    while(t--){
        solve();

    }

    return 0;
}


#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

const int N=1e5+5;

void solve(){
    int h[N];
    int idx[N];
    mem(h);
    memset(idx,-1,sizeof idx);
    int n;
    cin>>n;
    int x;
    int mx=0;
    multiset<int> mt;
    rep(i,0,n){
        cin>>x;
        idx[x]++;
        if(h[idx[x]]){
            mt.erase(mt.find(h[idx[x]]));
        }
        h[idx[x]]++;
        mt.insert(h[idx[x]]);

        if((sz(mt)>1)&&((*(mt.begin())+1)==*(mt.rbegin()))&&(*(next(mt.begin()))==*(mt.rbegin())||*(mt.begin())==*(prev(mt.rbegin())))){
            mx=max(mx,i+1);
            //cout<<sz(mt)<<endl;
        }

        else if((sz(mt)>1)&&((*(mt.begin())==1))&&*(next(mt.begin()))==*(mt.rbegin())){
            mx=max(mx,i+1);
           // cout<<sz(mt)<<endl;
        }
        else if(sz(mt)==1){
            mx=max(mx,i+1);
        }

    }

    cout<<mx;

}

int main(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t=1;
  //  cin>>t;

    while(t--){
        solve();

    }

    return 0;
}


#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        100000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    multiset<int> st;
    int a[1000007];
    memset(a,0,sizeof(a));
    int n;
    cin>>n;
    int d[n];
    rep(i,0,n)cin>>d[i];

    int ans=0;
    rep(i,0,n){
        a[d[i]]++;

        if(st.empty()!=1){
            auto itr = st.find(a[d[i]]-1);
            if(itr!=st.end()){
                st.erase(itr);
            }
            st.insert(a[d[i]]);
        }
        else{
            st.insert(a[d[i]]);
        }
        if(st.size()==1)ans=i+1;

        else if((*st.begin()+1==*st.rbegin())&&((*next(st.begin())==*st.rbegin())||(*st.begin()==*prev(st.rbegin())))||(*st.begin()==1&&*next(st.begin())==*st.rbegin())){
            ans=i+1;
        }
        // auto itr = st.find(1);
        // if(itr!=st.end()){
        //     st.erase(1);
        //     if(st.empty()||(*st.begin()==*st.rbegin())){
        //         ans=i+1;
        //     }
        //     st.insert(1);
        // }
    }
    cout<<ans;
}

int main(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int t=1;
    //cin>>t;

	while(t--){
		solve();
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

const int N=1e5+5;

void solve(){
    int h[N];
    int idx[N];
    mem(h);
    memset(idx,-1,sizeof idx);
    int n;
    cin>>n;
    int x;
    int mx=0;
    multiset<int> mt;
    rep(i,0,n){
        cin>>x;
        idx[x]++;
        if(h[idx[x]]){
            mt.erase(mt.find(h[idx[x]]));
        }
        h[idx[x]]++;
        mt.insert(h[idx[x]]);

        if((sz(mt)>1)&&((*(mt.begin())+1)==*(mt.rbegin()))&&(*((mt.begin()))==*(prev(mt.rbegin())))){
            mx=max(mx,i+1);
            //cout<<sz(mt)<<endl;
        }

        else if((sz(mt)>1)&&((*(mt.begin())==1))&&*(next(mt.begin()))==*(mt.rbegin())){
            mx=max(mx,i+1);
           // cout<<sz(mt)<<endl;
        }
        else if(sz(mt)==1){
            mx=max(mx,i+1);
        }

    }

    cout<<mx;

}

int main(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t=1;
  //  cin>>t;

    while(t--){
        solve();

    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <algorithm>
#include <cmath>

using namespace std;

map <int, int> counts;
int a[100010];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    int ans = -1;

    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (a[x] != 0)
            counts[a[x]]--;

        counts[a[x] + 1]++;

        a[x]++;

        if (counts[a[x] - 1] == 0) {
            counts.erase(counts.find(a[x] - 1));
        }

//        int len = 0;
//        for (auto it = counts.begin(); it != counts.end(); ++it) {
//            if (it->second != 0) {
//                len++;
////                cout << it->first << " " << it->second << endl;
//            }
//        }

//        cout << counts[1] << endl;
//        cout << len << endl;
//        cout << endl;

        if (counts.size() == 1 && counts[1] > 0) {
            ans = i;
        }

        if (counts.size() <= 2) {
            auto it = counts.begin();
            pair <int, int> left = *it;
            it++;
            pair<int, int> right = *it;

            if (left.first + 1 == right.first && right.second == 1) {
                ans = i;
            }

            if (left.first == 1 && left.second == 1) {
                ans = i;
            }
        }
    }

    cout << ans + 1;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <algorithm>
#include <cmath>

using namespace std;

map <int, int> counts;
int a[100010];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    int ans = -1;

    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (a[x] != 0)
            counts[a[x]]--;

        counts[a[x] + 1]++;

        a[x]++;

        if (counts[a[x] - 1] == 0) {
            counts.erase(counts.find(a[x] - 1));
        }

        if (counts.size() == 1 && counts[1] > 0) {
            ans = i;
        }

        if (counts.size() == 2) {
            auto it = counts.begin();
            pair <int, int> left = *it;
            it++;
            pair<int, int> right = *it;

            if (left.first + 1 == right.first && right.second == 1) {
                ans = i;
            }

            if (left.first == 1 && left.second == 1) {
                ans = i;
            }
        }
    }

    cout << ans + 1;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <algorithm>
#include <cmath>

using namespace std;

map <int, int> counts;
int a[100010];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    int ans = -1;

    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (a[x] != 0)
            counts[a[x]]--;

        counts[a[x] + 1]++;

        a[x]++;

        if (counts[a[x] - 1] == 0) {
            counts.erase(counts.find(a[x] - 1));
        }

        if (counts.size() == 1 && (counts.begin()->second == 1 || counts[1] > 0)) {
            ans = i;
        }

        if (counts.size() == 2) {
            auto it = counts.begin();
            pair <int, int> left = *it;
            it++;
            pair<int, int> right = *it;

            if (left.first + 1 == right.first && right.second == 1) {
                ans = i;
            }

            if (left.first == 1 && left.second == 1) {
                ans = i;
            }

            if (left.first == 1 && left.second == right.second + 1) {
                ans = i;
            }
        }
    }

    cout << ans + 1;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <algorithm>
#include <cmath>

using namespace std;

map <int, int> counts;
int a[100010];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    int ans = -1;

    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (a[x] != 0)
            counts[a[x]]--;

        counts[a[x] + 1]++;

        a[x]++;

        if (counts[a[x] - 1] == 0) {
            counts.erase(counts.find(a[x] - 1));
        }

        if (counts.size() == 1 && counts.begin()->second == 1) {
            ans = i;
        }

        if (counts.size() == 2) {
            auto it = counts.begin();
            pair <int, int> left = *it;
            it++;
            pair<int, int> right = *it;

            if (left.first + 1 == right.first && right.second == 1) {
                ans = i;
            }

            if (left.first == 1 && left.second == 1) {
                ans = i;
            }
        }
    }

    cout << ans + 1;
}