#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
using namespace std;

const int N=100010;
const int inf=0xfffffff;
long long n,m,h;
long long a[N];

int main(){
    long long i,j,k;
    scanf("%I64d%I64d%64d",&n,&h,&k);
    long long sum=0;
    for(i=0;i<n;++i){
    	scanf("%I64d",&a[i]);
    }
    sort(a,a+n);
    long long time=0;
    for(i=0;i<n;++i){

    	if(sum+a[i]<=h){
    		sum+=a[i];
    	}else{
    		sum=a[i];
    		time++;
    	}
    	long long chu=sum/k;
    	time+=chu;
    	sum-=chu*k;

    }
    if(sum) time++;
    printf("%I64d\n",time);

    return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
    queue<int> s;
    int h,k,n,x,t=0,l=0;
    cin>>n>>h>>k;
    for(int i=0; i<n; i++)
    {
    	cin>>x;
    	s.push(x);
    }
    do
    {
    	while(l+s.front()<=h && !s.empty())
    	{
    		l+=s.front();
    		s.pop();

    	}
    	l-=k;
    	if(l<0) l=0;
    	t++;
    }while(l || !s.empty());
    cout<<t<<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i,j,n,arr[100001];
	long long int h,k,rem,ans;
	cin >> n >> h >> k;
	for(i=0;i<n;i++)
		cin >> arr[i];
	i=rem=ans=0;
	while(i<n)
	{
		while( (rem+arr[i])<=h )
		{
			rem+=arr[i];
			i++;
		}
		if(rem>0)
		{
			ans+=1;
			rem-=k;
		}
		if(rem<0)
		{
			rem=0;
		}
	}
	while(rem>0)
	{
		ans+=1;
		rem=rem-k;
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i,j,n,arr[100001];
	long long int h,k,rem,ans;
     cin >> n >> h >> k;
	for(i=0;i<n;i++)
		cin >> arr[i];
	i=rem=ans=0;
	while(i<n)
	{
		if( (i<n) && ( rem + arr[i] > h) )
		{
			ans+=1;
			rem=0;
		}
		while( (rem+arr[i])<=h )
		{
			rem+=arr[i];
			i++;
		}
		ans+=(rem/k);
		rem=(rem%k);
	}
/*	if(rem)
	{
		ans+=(rem/k);
		rem=(rem%k);
	}  */
	if(rem)
		ans+=1;
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i,j,n,arr[100001];
	long long int h,k,rem,ans;
	scanf("%d %I64d %I64d",&n,&h,&k);
	for(i=0;i<n;i++)
		scanf("%I64d",&arr[i]);
	i=rem=ans=0;
	while(i<n)
	{
		while( (rem+arr[i])<=h )
		{
			rem+=arr[i];
			i++;
		}
		if(rem>0)
		{
			ans+=1;
			rem-=k;
		}
		if(rem<0)
		{
			rem=0;
		}
	}
	while(rem>0)
	{
		ans+=1;
		rem=rem-k;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,i,j,arr[100001];
	long long int h,k,rem,ans;
	cin >> n >> h >> k;
	for(i=0;i<n;i++)
		cin >> arr[i];
	rem=ans=0;
	for(i=0;i<n;i++)
	{
		if(rem+arr[i]>h)
		{
			ans+=1;
			rem=0;
		}
		rem+=arr[i];
		ans+=rem/k;
		rem=rem%k;
	}
	if(rem)
		ans+=1;
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i,j,n,arr[100001];
	long long int h,k,rem,ans;
     cin >> n >> h >> k;
	for(i=0;i<n;i++)
		cin >> arr[i];
	i=rem=ans=0;
	while(i<n)
	{
		if( (i<n) && ( rem + arr[i] > h) )
		{
			ans+=1;
			rem=0;
		}
		while( (rem+arr[i])<=h )
		{
			rem+=arr[i];
			i++;
		}
//		cout << "Taking " << rem << endl;
		ans+=(rem/k);
//		cout << "Answer : " << ans << endl;
		rem=(rem%k);
/*		if(rem)
		{
			rem=0;
			ans+=1;
		} */
	}
	if(rem)
	{
		ans+=(rem/k);
		rem=(rem%k);
	}
	if(rem)
		ans+=1;
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i,j,n,arr[100001];
	long long int h,k,rem,ans;
//	scanf("%d %I64d %I64d",&n,&h,&k);
//	for(i=0;i<n;i++)
//		scanf("%I64d",&arr[i]);
     cin >> n >> h >> k;
	for(i=0;i<n;i++)
		cin >> arr[i];
	i=rem=ans=0;
	while(i<n)
	{
		while( (rem+arr[i])<=h )
		{
			rem+=arr[i];
			i++;
		}
		if(rem>0)
		{
			ans+=1;
			rem-=k;
		}
		if(rem<0)
		{
			rem=0;
		}
	}
	if(rem)
	{
		ans+=(rem/k);
		rem=(rem%k);
	}
	if(rem)
		ans+=1;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    int n,h,k; cin >> n >> h >> k;
    int ans=0,x,rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<h)
        {
            rem += x; continue;
        }
        while(x+rem>h)
        {
            rem -= k;
            if(rem < 0) rem = 0;
            ans++;
        }
        rem += x; ans++; rem -= k;
    }
    while(rem>0)
    {
        ans++; rem -= k;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    int n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        while(x+rem>h)
        {
            rem -= k;
            if(rem < 0) rem = 0;
            ans++;
        }
        rem += x; ans++; rem -= k;
    }
    ans += rem/k;
    if(rem%k)
        ans++;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    ll n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        ll q = rem - (h-x);
        ans += (q+k-1)/k;

        rem -= ((q+k-1)/k)*k;

        if(rem<0) rem = 0;
        rem += x; ans++; rem -= k;
    }
    ans += (rem+k-1)/k;

    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    ll n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }

        if(rem+x>h){
        ll q = rem - (h-x);
        ans += (q+k-1)/k;

        rem -= ((q+k-1)/k)*k;

        if(rem<0) rem = 0;
        }
        else{
         ans++; rem -= k;
        if(rem<0) rem=0;
        }
    }
    ans += (rem+k-1)/k;

    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    ll n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }

        if(rem+x>h){
        ll q = rem - (h-x);
        ans += (q+k-1)/k;

        rem -= ((q+k-1)/k)*k;

        if(rem<0) rem = 0;
        }
        else{
        rem += x; ans++; rem -= k;
        if(rem<0) rem=0;
        }
    }
    ans += (rem+k-1)/k;

    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    int n,h,k,x; cin >> n >> h >> k;
    int ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        while(x+rem>h)
        {
            rem -= k;
            if(rem < 0) rem = 0;
            ans++;
        }
        rem += x; ans++; rem -= k;
    }
    while(rem>0)
    {
        ans++; rem -= k;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    int n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        ll q = rem - (h-x);
        ans += q/k;
        if(q%k==0)
            rem = h-x;
        else
        {
            ans++;
            rem = h-x - (k - q%k);
        }
        if(rem<0) rem = 0;
        rem += x; ans++; rem -= k;
    }
    ans += rem/k;
    if(rem%k)
        ans++;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    int n,h,k; cin >> n >> h >> k;
    int ans=0,x,rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        while(x+rem>h)
        {
            rem -= k;
            if(rem < 0) rem = 0;
            ans++;
        }
        rem += x; ans++; rem -= k;
    }
    while(rem>0)
    {
        ans++; rem -= k;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    ll n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        int q = rem - (h-x);
        ans += q/k;
        if(q%k==0)
            rem = h-x;
        else
        {
            ans++;
            rem = h-x - (k - q%k);
        }
        if(rem<0) rem = 0;
        rem += x; ans++; rem -= k;
    }
    ans += rem/k;
    if(rem%k)
        ans++;
    cout << ans;
    return 0;
}


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

long long a[100010];

int main()
{

int n;
cin>>n;
int i;

long long k,h;
cin>>h>>k;

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

i=0;
long long level=0;

long long ans=0;

while(i<n)
{

  while(i<n && level+a[i]<=h)
  {

  	level+=a[i];
    i++;
  }

if(i==n)
	break;

else
{
   long long q=(level+a[i]-h+k-1)/k;
   ans+=q;

   level-=q*k;
   if(level<0)
   	level=0;

}

}

if(level>0)
{
	ans+=(level+k-1)/k;
}

cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    ll n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        ll q = rem - (h-x);
        ans += (q+k-1)/k;

        rem -= ((q+k-1)/k)*k;

        if(rem<0) rem = 0;
        rem += x; ans++; rem -= k;
        if(rem<0) rem=0;
    }
    ans += (rem+k-1)/k;

    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    ll n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        int q = rem - (h-x);
        ans += (q+k-1)/k;

        rem -= ((q+k-1)/k)*k;

        if(rem<0) rem = 0;
        rem += x; ans++; rem -= k;
    }
    ans += (rem+k-1)/k;

    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    int n,h,k,x; cin >> n >> h >> k;
    int ans=0ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        while(x+rem>h)
        {
            rem -= k;
            if(rem < 0) rem = 0;
            ans++;
        }
        rem += x; ans++; rem -= k;
    }
    while(rem>0)
    {
        ans++; rem -= k;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    int n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        ll q = rem - (h-x);
        ans += q/k;
        if(q%k)
            ans++;
        rem = h-x - (q%k);
        rem += x; ans++; rem -= k;
    }
    ans += rem/k;
    if(rem%k)
        ans++;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    int n,h,k,x; cin >> n >> h >> k;
    int ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        while(x+rem>h)
        {
            rem -= k;
            if(rem < 0) rem = 0;
            ans++;
        }
        rem += x; ans++; rem -= k;
    }
    ans += rem/k;
    if(rem%k)
        ans++;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    int n,h,k; cin >> n >> h >> k;
    ll ans=0,x,rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }
        while(x+rem>h)
        {
            rem -= k;
            if(rem < 0) rem = 0;
            ans++;
        }
        rem += x; ans++; rem -= k;
    }
    while(rem>0)
    {
        ans++; rem -= k;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 100005
int main()
{
    ll n,h,k,x; cin >> n >> h >> k;
    ll ans=0; ll rem=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(rem+x<=h)
        {
            rem += x; continue;
        }

        ll q = rem - (h-x);
        ans += (q+k-1)/k;

        rem -= ((q+k-1)/k)*k;

        if(rem<0) rem = 0;
      rem+=x;

    }
    ans += (rem+k-1)/k;

    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int n,h,k;
	cin>>n;
	cin>>h;
	cin>>k;
	long long int arr[n];
	for(long long int i=0;i<n;i++){
		cin>>arr[i];
	}
	long long int t=0;
	long long int sheight = arr[0];
	long long int idx = 1;
	while(idx<n){
		if(sheight+arr[idx]<=h){
			sheight = sheight + arr[idx];
			idx++;
			continue;
		}
		if(sheight>=k){
			sheight = sheight - k;
			t++;
		}
		else{
			sheight = 0;
			t++;
		}

	}
	if(sheight>0){
		long long int div = sheight/k;
		if(sheight%k==0)
		t = t+div;
		else
		t = t+ div +1;
	}
	cout<<t<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int n,h,k;
	scanf("%lld",&n);
	scanf("%lld",&h);
	scanf("%lld",&k);
	long long int arr[n];
	for(long long int i=0;i<n;i++){
		scanf("%lld",&arr[i]);
	}
	long long int t=0;
	long long int sheight = arr[0];
	long long int idx = 1;
	while(idx<n){
		if(sheight+arr[idx]<=h){
			sheight = sheight + arr[idx];
			idx++;
			continue;
		}
		if(sheight>=k){
			sheight = sheight - k;
			t++;
		}
		else{
			sheight = 0;
			t++;
		}

	}
	if(sheight>0){
		long long int div = sheight/k;
		if(sheight%k==0)
		t = t+div;
		else
		t = t+ div +1;
	}
	cout<<t<<endl;

}


#include<bits/stdc++.h>
using namespace std;
bool wayToSort(int i, int j) { return i > j; }
int main()
{
    long long int n,h,k;
    cin>>n>>h>>k;
    long long int arr[n];
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n,wayToSort);
    long long int heightinside=arr[0];
    long long int point=1;
    long long int ans=0;
    while(1)
    {
        while(heightinside<h &&point!=n)
        {
            heightinside+=arr[point];
            point++;

        }

        if (heightinside>h)
        {
            point--;
            heightinside-=arr[point];
        }
        if(point==n)
        {
            break;
        }
        while(heightinside+arr[point]>h )
        {
            if (heightinside<=k)
                heightinside=0;
            else
            heightinside-=k;
            ans++;

        }

    }
    while(heightinside>0)
        {
            heightinside-=k;
            ans++;
        }
    cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int n,h,k;
	scanf("%lld",&n);
	scanf("%lld",&h);
	scanf("%lld",&k);
	long long int arr[n];
	for(long long int i=0;i<n;i++){
		scanf("%lld",&arr[i]);
	}
	long long int t=0;
	long long int sheight = arr[0];
	long long int idx = 1;
	while(idx<n){
		//cout<<"sheight "<<sheight<<endl;
		//cout<<"idx "<<idx<<endl;
		if(sheight+arr[idx]<=h){
			sheight = sheight + arr[idx];
			idx++;
			continue;
		}
		if(sheight>=k){
			double rem = arr[idx]/(double)k;

			if(rem<1 && rem>0){
				rem = 1.0;
			}
			int add = (int)rem;
			int divisor  = (sheight-h)/k + rem ;
			sheight = sheight - divisor*k;
			t+=divisor;
		}
		else{
			sheight = 0;
			t++;
		}
	}
	if(sheight>0){
		long long int div = sheight/k;
		if(sheight%k==0)
		t = t+div;
		else
		t = t+ div +1;
	}
	cout<<t<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,h,k;
    cin>>n>>h>>k;
    long long int arr[n];
    cin>>arr[0];
    long long int chop=0;
    long long int heightinside=arr[0];
    for (int i=1;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]+heightinside>h)
        {
            if(!((arr[i]+heightinside-h)%k))
            {
              chop+=(arr[i]+heightinside-h)/k;
              if (heightinside<((arr[i]+heightinside-h)/k)*k)
                    heightinside=0;
              else
              heightinside-=((arr[i]+heightinside-h)/k)*k;
            }
            else
            {
                chop+=((arr[i]+heightinside-h)/k+1);
                if (heightinside<k*((arr[i]+heightinside-h)/k+1))
                    heightinside=0;
                else
                heightinside-=k*((arr[i]+heightinside-h)/k+1);
            }

        }

            heightinside+=arr[i];

    }
    if (heightinside)
    {
        if (!((heightinside)%k))
        {
            chop+=heightinside/k;
        }
        else
        {
            chop+=(heightinside/k)+1;
        }
    }
    cout<<chop;

}


#include<bits/stdc++.h>
using namespace std;
bool wayToSort(int i, int j) { return i > j; }
int main()
{
    long long int n,h,k;
    cin>>n>>h>>k;
    long long int arr[n];
    cin>>arr[0];
    int chop=0;
    int heightinside=arr[0];
    for (int i=1;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]+heightinside>h)
        {
            if(!((arr[i]+heightinside-h)%k))
            {
              chop+=(arr[i]+heightinside-h)/k;
              if (heightinside<((arr[i]+heightinside-h)/k)*k)
                    heightinside=0;
              else
              heightinside-=((arr[i]+heightinside-h)/k)*k;
            }
            else
            {
                chop+=((arr[i]+heightinside-h)/k+1);
                if (heightinside<k*((arr[i]+heightinside-h)/k+1))
                    heightinside=0;
                else
                heightinside-=k*((arr[i]+heightinside-h)/k+1);
            }

        }

            heightinside+=arr[i];

    }
    if (heightinside)
    {
        if (!((heightinside)%k))
        {
            chop+=heightinside/k;
        }
        else
        {
            chop+=(heightinside/k)+1;
        }
    }
    cout<<chop;

}


#include<bits/stdc++.h>
using namespace std;
bool wayToSort(int i, int j) { return i > j; }
int main()
{
    long long int n,h,k;
    cin>>n>>h>>k;
    long long int arr[n];
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    long long int heightinside=arr[0];
    long long int point=1;
    long long int ans=0;
    while(1)
    {
        while(heightinside<h &&point!=n)
        {
            heightinside+=arr[point];
            point++;

        }

        if (heightinside>h)
        {
            point--;
            heightinside-=arr[point];
        }
        if(point==n)
        {
            break;
        }
        while(heightinside+arr[point]>h )
        {
            if (heightinside<=k)
                heightinside=0;
            else
            heightinside-=k;
            ans++;

        }

    }
    while(heightinside>0)
        {
            heightinside-=k;
            ans++;
        }
    cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int n,h,k;
	cin>>n;
	cin>>h;
	cin>>k;
	long long int arr[n];
	for(long long int i=0;i<n;i++){
		cin>>arr[i];
	}
	long long int t=0;
	long long int sheight = arr[0];
	long long int idx = 1;
	while(idx<n){
		if(sheight>=k){
			sheight = sheight - k;
			t++;
		}
		else{
			sheight = 0;
			t++;
		}
		if(sheight+arr[idx]<=h){
			sheight = sheight + arr[idx];
			idx++;
		}

	}
	if(sheight>0){
		long long int div = sheight/k;
		if(sheight%k==0)
		t = t+div;
		else
		t = t+ div +1;
	}
	cout<<t<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,h,k;
    cin>>n>>h>>k;
    long long int arr[n];
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    long long int heightinside=arr[0];
    long long int point=1;
    long long int ans=0;
    while(1)
    {
        while(heightinside<h &&point!=n)
        {
            heightinside+=arr[point];
            point++;

        }

        if (heightinside>h)
        {
            point--;
            heightinside-=arr[point];
        }
        if(point==n)
        {
            break;
        }
        while(heightinside+arr[point]>h )
        {
            if (heightinside<=k)
                heightinside=0;
            else
            heightinside-=k;
            ans++;

        }

    }
    while(heightinside>0)
        {
            heightinside-=k;
            ans++;
        }
    cout<<ans;

}


#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main()
{
	int n, h, k, ans = 0, p = 0;
	vi a;
	scanf("%d %d %d ", &n, &h, &k);

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

	int i = 0;
	while(i < n || p != 0)
	{
		while(i < n && p + a[i] < h)
			p += a[i++];

		p -= k;
		if(p < 0) p = 0;
		ans++;
	}

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

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main()
{
	int n, h, k, ans = 0, p = 0;
	vi a;
	scanf("%d %d ", &n, &h, &k);

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

	int i = 0;
	while(i < n || p != 0)
	{
		while(i < n && p + a[i] < h)
			p += a[i++];

		p -= k;
		if(p < 0) p = 0;
		ans++;
	}

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

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;
#define INF 1000000000

vector< vector<ii> > adjList;
vi dist;

int distan(ii a, ii b)
{
	return abs(a.first - b.first) + abs(a.second - b.second);
}

void Dijkstra(int n, int m, int s)
{
	dist = vi(n*m, INF); dist[s] = 0;
	priority_queue< ii, vector<ii>, greater<ii> > pq; pq.push(ii(0, s));
	while(!pq.empty())
	{
		ii front = pq.top(); pq.pop();
		int d = front.first, u = front.second;
		if(d > dist[u]) continue;
		for(size_t j = 0; j < adjList[u].size(); j++)
		{
			ii v = adjList[u][j];
			if(dist[u] + v.second < dist[v.first])
			{
				dist[v.first] = dist[u] + v.second;
				pq.push(ii(dist[v.first], v.first));
			}
		}
	}
}

int main()
{
	int data[305][305];
	vector< vector<ii> > chests;
	int n, m, p;

	scanf("%d %d %d ", &n, &m, &p);

	chests.resize(p+2);
	adjList.resize(n*m + 2);
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			scanf(" %d", &data[i][j]);
			chests[data[i][j]].push_back(ii(i, j));
		}
	}

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			int pAux = data[i][j]-1;
			if(data[i][j] > 1)
			for(size_t k = 0; k < chests[pAux].size(); k++)
			{
				int v = chests[pAux][k].first * m + chests[pAux][k].second;
				adjList[i*m + j].push_back( ii (v, distan( ii(i, j), chests[pAux][k] )) );
			}
		}
	}

	int source = (chests[p][0].first * m + chests[p][0].second);

	Dijkstra(n, m, source);
	int ans = INF;
	for(size_t k = 0; k < chests[1].size(); k++)
	{
		int d = dist[chests[1][k].first * m + chests[1][k].second];
		d += distan(ii(0, 0), chests[1][k]);
		if(d < ans)
			ans = d;
	}

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

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main()
{
	long long int n, h, k, ans = 0, p = 0;
	vector<long long int> a;
	cin >> n >> h >> k;

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

	int i = 0;
	while(i < n || p != 0)
	{
		while(i < n && p + a[i] <= h)
			p += a[i++];

		p -= k;
		if(p < 0) p = 0;
		ans++;
	}

	cout << ans << endl;

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main()
{
	int n, h, k, ans = 0, p = 0, aux;
	vi a;
	scanf("%d %d %d ", &n, &h, &k);

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

	int i = 0;
	while(i < n || p != 0)
	{
		while(i < n && p + a[i] <= h)
			p += a[i++];

		if(i == n)
			aux = ceil(double(p) / k);
		else
			aux = p / k;
		p -= aux * k;
		ans += aux;
		if(i < n && p + a[i] > h)
		{
			p = 0;
			ans++;
		}
		if(p < 0) p = 0;
	}

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

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main()
{
	int n, h, k, aux;
	long long int p = 0, ans = 0;
	vi a;
	scanf("%d %d %d ", &n, &h, &k);

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

	int i = 0;
	while(i < n || p != 0)
	{
		while(i < n && p + a[i] <= h)
			p += a[i++];

		if(i == n)
			aux = ceil(p / (double)k);
		else
			aux = p / k;
		p -= aux * k;
		ans += aux;
		if(i < n && p + a[i] > h)
		{
			p = 0;
			ans++;
		}
		if(p < 0) p = 0;
	}

	cout << ans << endl;

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main()
{
	int n, h, k, ans = 0, aux;
	long long int p = 0;
	vi a;
	scanf("%d %d %d ", &n, &h, &k);

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

	int i = 0;
	while(i < n || p != 0)
	{
		while(i < n && p + a[i] <= h)
			p += a[i++];

		if(i == n)
			aux = ceil(double(p) / k);
		else
			aux = p / k;
		p -= aux * k;
		ans += aux;
		if(i < n && p + a[i] > h)
		{
			p = 0;
			ans++;
		}
		if(p < 0) p = 0;
	}

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

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main()
{
	int n, h, k, ans = 0, p = 0;
	vi a;
	scanf("%d %d %d ", &n, &h, &k);

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

	int i = 0;
	while(i < n || p != 0)
	{
		while(i < n && p + a[i] <= h)
			p += a[i++];

		p -= k;
		if(p < 0) p = 0;
		ans++;
	}

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

	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;

int a[100010];
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int n,m,k;
	int sum=0;
	int sec=0;
	cin>>n>>m>>k;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	int j=0;
	while(1){
		if(j==n){
			if(sum>0){
				sec+=sum%k?sum/k+1:sum/k;
			}
			break;
		}
		if(sum+a[j]>m){
			if(sum>k)sec+=sum/k,sum%=k;
			else sec++,sum=0;
		}
		else {
			sum+=a[j];
			j++;
		}
	}
	cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;

int a[100010];
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int n,m,k;
	int sum=0;
	int sec=0;
	cin>>n>>m>>k;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	int j=0;
	while(1){
		if(j==n){
			if(sum>0){
				sec+=sum%k?sum/k+1:sum/k;
			}
			break;
		}
		if(sum+a[j]>m){
			if(sum>k)sec+=sum/k,sum%=k;
			else sec++,sum=0;

		}
		else {
			sum+=a[j];

		}
		j++;
	}
	cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;

int a[100010];
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int n,m,k;
	int sum=0;
	int sec=0;
	cin>>n>>m>>k;
	queue<int>q1;
	rep(i,n){
		cin>>a[i];
		q1.push(a[i]);
	}
	int j=0;

	while(1){
		if(q1.empty()){
			if(sum!=0)sec+=sum%k?sum/k+1:sum/k;
			break;
		}
		while(1){
			if(q1.empty())break;
			int flag=q1.front();
			if(sum+flag>m)break;
			q1.pop();
			sum+=flag;
		}
		sec+=1;
		sum=max(0,sum-k);
	}
	cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;

int a[100010];
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int n,m,k;
	int sum=0;
	int sec=0;
	cin>>n>>m>>k;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	int j=0;
	while(1){
		if(j==n){
			if(sum>0){
				sec+=sum%k?sum/k+1:sum/k;
			}
			break;
		}
		if(sum+a[j]>m){
			sec+=1;
			sum=max(0,sum-k);
		}
		else {
			sum+=a[j];
			j++;
		}
	}
	cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;

int a[100010];
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int n,m,k;
	int sum=0;
	int sec=0;
	cin>>n>>m>>k;
	rep(i,n){
		scanf("%d",a[i]);
	}
	int j=0;
	while(1){
		if(j==n){
			if(sum>0){
				sec+=sum%k?sum/k+1:sum/k;
			}
			break;
		}
		if(sum+a[j]>m){
			sec+=1;
			sum=max(0,sum-k);
		}
		else {
			sum+=a[j];
			j++;
		}
	}
	cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;

int a[100010];
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int n,m,k;
	int sum=0;
	int sec=0;
	cin>>n>>m>>k;
	queue<int>q1;
	rep(i,n){
		cin>>a[i];
		q1.push(a[i]);
	}
	int j=0;
	while(1){
		if(j==n){
			if(sum>0){
				sec+=sum%k?sum/k+1:sum/k;
			}
			break;
		}
		if(sum+a[j]>m){
			sec+=1;
			sum=max(0,sum-k);
		}
		else {
			sum+=a[j];
			j++;
		}
	}

	cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;

long long a[100010];
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	long long n,m,k;
	long long sum=0;
	long long sec=0;
	cin>>n>>m>>k;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	int j=0;
	while(1){
		if(j==n){
			sec+=sum%k?sum/k+1:sum/k;
			break;
		}
		if(sum+a[j]>m){
			if(sum>k)sec+=sum/k,sum%=k;
			else sec++,sum=0;

		}
		else {
			sum+=a[j];
			j++;
		}
	}
	cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;

int a[100010];
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	long long n,m,k;
	long long sum=0;
	long long sec=0;
	cin>>n>>m>>k;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	int j=0;
	while(1){
		if(j==n){
			if(sum>0){
				sec+=(sum-1+k)/k;
			}
			break;
		}
		if(sum+a[j]>m){
			if(sum>k)sec+=sum/k,sum%=k;
			else sec++,sum=0;

		}
		else {
			sum+=a[j];
			j++;
		}
	}
	cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;

int a[100010];
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int n,m,k;
	int sum=0;
	int sec=0;
	cin>>n>>m>>k;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	int j=0;
	while(1){
		if(j==n){
			if(sum>0){
				sec+=(sum-1+k)/k;
			}
			break;
		}
		if(sum+a[j]>m){
			if(sum>k)sec+=sum/k,sum%=k;
			else sec++,sum=0;

		}
		else {
			sum+=a[j];
			j++;
		}
	}
	cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,h,k;
    cin>>n>>h>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int counter=0,x=0;
    for(int i=0;i<n;i++)
    {
        while(x+a[i]<=h)
        {
            x+=a[i];
            i++;
        }
        if(x+a[i]>h)
        i--;
        int d;
        d=x/k;
        int q=(d-1)*k,j=i+1,flag=0;
/*        while(q>0)
        {
            if(q>=a[j])
            {
                q-=a[j];
                j++;
                flag=1;
            }
            else
            {
                break;
            }

        }*/
        if(d==0)
        {
            counter++;
            x=0;
        }
        else
        {
            counter+=d;
            x=x%k;
            if(flag==1)
                i=j-1;
        }
    }
    if(x%k==0)
        counter+x/k;
    else
        counter+=x/k+1;
    cout<<counter<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  n,h,k;
    cin>>n>>h>>k;
    long long a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long counter=0,x=0;
    for(int i=0;i<n;i++)
    {
        while(x+a[i]<=h)
        {
            x+=a[i];
            i++;
        }
        if(x+a[i]>h)
        i--;
        long long d;
        d=x/k;
/*        while(q>0)
        {
            if(q>=a[j])
            {
                q-=a[j];
                j++;
                flag=1;
            }
            else
            {
                break;
            }

        }*/
        if(d==0)
        {
            counter++;
            x=0;
        }
        else
        {
            counter+=d;
            x=x%k;
        }
    }
    if(x%k==0)
        counter+x/k;
    else
        counter+=x/k+1;
    cout<<counter<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  n,h,k;
    cin>>n>>h>>k;
    long long a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long counter=0,x=0;
    for(int i=0;i<n;i++)
    {
        while(x+a[i]<=h)
        {
            x+=a[i];
            i++;
        }
        if(x+a[i]>h)
        i--;
        long long d;
        d=x/k;
        int q=(d-1)*k,j=i+1,flag=0;
/*        while(q>0)
        {
            if(q>=a[j])
            {
                q-=a[j];
                j++;
                flag=1;
            }
            else
            {
                break;
            }

        }*/
        if(d==0)
        {
            counter++;
            x=0;
        }
        else
        {
            counter+=d;
            x=x%k;
            if(flag==1)
                i=j-1;
        }
    }
    if(x%k==0)
        counter+x/k;
    else
        counter+=x/k+1;
    cout<<counter<<endl;
}


    #include<bits/stdc++.h>
    using namespace std;
    long long a[100005]={0};
    int main()
    {
        long long  n,h,k;
        cin>>n>>h>>k;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        long long counter=0,x=0;
        for(int i=0;i<n;i++)
        {
            while(x+a[i]<=h)
            {
                x+=a[i];
                i++;
            }
            if(x+a[i]>h)
            i--;
            long long d;
            d=x/k;
    /*        while(q>0)
            {
                if(q>=a[j])
                {
                    q-=a[j];
                    j++;
                    flag=1;
                }
                else
                {
                    break;
                }

            }*/
            if(d==0)
            {
                counter++;
                x=0;
            }
            else
            {
                counter+=d;
                x=x%k;
            }
        }
        if(x%k==0)
            counter+=x/k;
        else
            counter+=x/k+1;
        cout<<counter<<endl;
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,h,k;
    cin>>n>>h>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int counter=0,x=0;
    for(int i=0;i<n;i++)
    {
        while(x+a[i]<=h)
        {
            x+=a[i];
            i++;
        }
        if(x+a[i]>h)
        i--;
        int d;
        d=x/k;
        int q=(d-1)*k,j=i+1,flag=0;
        while(q>0)
        {
            if(q>=a[j])
            {
                q-=a[j];
                j++;
                flag=1;
                counter++;
            }
            else
            {
                break;
            }

        }
        if(d==0)
        {
            counter++;
            x=0;
        }
        else
        {
            counter+=d;
            x=x%k;
            if(flag==1)
                i=j-1;
        }
    }
    if(x%k==0)
        counter+x/k;
    else
        counter+=x/k+1;
    cout<<counter<<endl;
}


    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        long long  n,h,k,a[100005]={0};
        cin>>n>>h>>k;
        for(long long i=0;i<n;i++)
        {
            cin>>a[i];
        }
        long long counter=0,x=0;
        for(long long i=0;i<n;i++)
        {
            while(x+a[i]<=h)
            {
                x+=a[i];
                i++;
            }
            if(x+a[i]>h)
            i--;
            long long d;
            d=x/k;
    /*        while(q>0)
            {
                if(q>=a[j])
                {
                    q-=a[j];
                    j++;
                    flag=1;
                }
                else
                {
                    break;
                }

            }*/
            if(d==0)
            {
                counter++;
                x=0;
            }
            else
            {
                counter+=d;
                x=x%k;
            }
        }
        if(x%k==0)
            counter+=x/k;
        else
            counter+=x/k+1;
        cout<<counter<<endl;
    }


    #include<bits/stdc++.h>
    using namespace std;
    long long a[1000005]={0};
    int main()
    {
        long long  n,h,k;
        cin>>n>>h>>k;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        long long counter=0,x=0;
        for(int i=0;i<n;i++)
        {
            while(x+a[i]<=h)
            {
                x+=a[i];
                i++;
            }
            if(x+a[i]>h)
            i--;
            long long d;
            d=x/k;
    /*        while(q>0)
            {
                if(q>=a[j])
                {
                    q-=a[j];
                    j++;
                    flag=1;
                }
                else
                {
                    break;
                }

            }*/
            if(d==0)
            {
                counter++;
                x=0;
            }
            else
            {
                counter+=d;
                x=x%k;
            }
        }
        if(x%k==0)
            counter+=x/k;
        else
            counter+=x/k+1;
        cout<<counter<<endl;
    }


    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        long long  n,h,k;
        cin>>n>>h>>k;
        long long a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        long long counter=0,x=0;
        for(int i=0;i<n;i++)
        {
            while(x+a[i]<=h)
            {
                x+=a[i];
                i++;
            }
            if(x+a[i]>h)
            i--;
            long long d;
            d=x/k;
    /*        while(q>0)
            {
                if(q>=a[j])
                {
                    q-=a[j];
                    j++;
                    flag=1;
                }
                else
                {
                    break;
                }

            }*/
            if(d==0)
            {
                counter++;
                x=0;
            }
            else
            {
                counter+=d;
                x=x%k;
            }
        }
        if(x%k==0)
            counter+=x/k;
        else
            counter+=x/k+1;
        cout<<counter<<endl;
    }


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

int main()
{
    ll n,h,k;
    cin>>n>>h>>k;
    ll ans=0,a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];

    ll inside=0;
    for(int i=0;i<n;i++)
    {
        while(inside+a[i]<=h && i<n)
        {
            inside=inside+a[i];
            i++;
        }

        i--;
        ans++;
        if(inside<k)
            inside=0;
        else
            inside-=k;
    }

    ans+=ceil((float)inside/k);

    cout<<ans;
    return 0;
}


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

int main()
{
    ll n,h,k;
    scanf("%lld %lld %lld",&n,&h,&k);
    ll ans=0,a[n];
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);

    ll inside=0;

    int i=0;
    while(1)
    {
        while(inside+a[i]<=h && i<n)
        {
            inside=inside+a[i];
            i++;
        }

        if(i==n)
            break;

        ll sec=ceil((float)(a[i]-h+inside)/k);
        ll remove=k*sec;

        inside-=remove;
        ans+=sec;
    }

    ans+=ceil((float)inside/k);

    printf("%lld",ans);
    return 0;
}


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

int main()
{
    ll n,h,k;
    scanf("%lld %lld %lld",&n,&h,&k);
    ll ans=0,a[n];
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);

    ll inside=0;

    int i=0;
    while(1)
    {
        while(inside+a[i]<=h && i<n)
        {
            inside=inside+a[i];
            i++;
        }

        if(i==n)
            break;

        ll sec=ceil((long double)(a[i]-h+inside)/k);
        ll remove=k*sec;

        if(inside>remove)
            inside-=remove;
        else
            inside=0;

        ans+=sec;
    }

    ans+=ceil((float)inside/k);

    printf("%lld",ans);
    return 0;
}


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

int main()
{
    ll n,h,k;
    cin>>n>>h>>k;
    ll ans=0,a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];

    ll inside=0;

    int i=0;
    while(i<n)
    {
        while(inside+a[i]<=h && i<n)
        {
            inside=inside+a[i];
            i++;
        }

        ans++;
        if(inside<k)
            inside=0;
        else
            inside-=k;
    }

    ans+=ceil((float)inside/k);

    cout<<ans;
    return 0;
}


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

int main()
{
    ll n,h,k;
    scanf("%I64d %I64d %I64d",&n,&h,&k);
    ll ans=0,a[n];
    for(int i=0;i<n;i++)
        scanf("%I64d",&a[i]);

    ll inside=0;

    int i=0;
    while(i<n)
    {
        while(inside+a[i]<=h && i<n)
        {
            inside=inside+a[i];
            i++;
        }

        ans++;
        if(inside<k)
            inside=0;
        else
            inside-=k;
    }

    ans+=ceil((float)inside/k);

    printf("%I64d",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
#define makefast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define comp(x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin())
#define lc (v * 2)
#define rc (v * 2 + 1)
long long M = 1e9 + 7;
//>>>>>>>>>>>>>>>>>>>>>>>

const int N = 2e5 + 77, R =  100 + 7;
int r = 1420;
vector < pair <int, pair <int, int> > > qr;
int n;
int ar[N];
vector <int> vec;
int seg[R][N * 6];
int cnt[R][N];

void add(int pk, int p, int val) {
	p += (1 << 18);
	while (p) {
		seg[pk][p] += val;
		p /= 2;
	}
}
int get(int pk, int l, int r) {
	 l += (1 << 18);
	 r += (1 << 18) - 1;
	 if (r < l)
		 return 0;
	 if (l == r)
		 return seg[pk][l];
	 int res = seg[pk][l] + seg[pk][r];
	 while (l / 2 != r / 2) {
	 	if (l % 2 == 0)
			res += seg[pk][l + 1];
		if (r % 2 == 1)
			res += seg[pk][r - 1];
		l /= 2, r /= 2;
	 }
	 return res;
}
void upd(int p, int x, int val) {
	for (int pk = p / r + 1; pk <= n / R; pk++) {
		add(pk, cnt[x][pk], -1);
		cnt[x][pk] += val;
		add(pk, cnt[x][pk], +1);
	}
}
int geteven(int p) {
	int res = 0;
	int pk = p / r;
	res += cnt[pk][ar[p]];
	for (int i = max(1, pk * r); i <= p; i++) {
		if (ar[i] == ar[p])
			res++;
//		cout << " >> " << i << " " << ar[i] << ' ' << ar[p] << ' ' << cnt[pk][ar[p]] << endl;
	}
	return res;
}
int getodd(int p) {
	int t = geteven(p);
//	cout << " ODD : " << t << endl;
	int pk = p / r;
	int res = get(pk, t, n + 1);
//	cout << " ? " << res << endl;
	for (int i = max(1, pk * r); i <= p; i++) {
		cnt[pk][ar[i]]++;
		if (cnt[pk][ar[i]] == t) {
			res++;
		//	cout << " : " << i << ' ' << ar[i] << endl;
		}
	}
	for (int i = max(1, pk * r); i <= p; i++)
		cnt[pk][ar[i]]--;
	return res;
}
int main() {
	makefast;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> ar[i];
		vec.push_back(ar[i]);
	}
	int q;
	cin >> q;
	while (q--) {
		int t, a, b;
		cin >> t >> a >> b;
		if (t == 1)
			vec.push_back(a);
		qr.push_back({t, {a, b}});
	}
	sort (vec.begin(), vec.end());
	vec.resize (unique(vec.begin(), vec.end()) - vec.begin());
	for (int i = 1; i <= n; i++)
		ar[i] = comp(ar[i]);
	for (int i = 0; i < qr.size(); i++)
		if (qr[i].first == 1)
			qr[i].second.first = comp(qr[i].second.first);
	for (int i = 1; i <= n; i++)
		upd(i, ar[i], +1);
	for (auto p: qr) {
		int tp = p.first;
		int a = p.second.first;
		int b = p.second.second;
		if (tp == 1) {
			upd(b, ar[b], -1);
			ar[b] = a;
			upd(b, ar[b], +1);
		}
		else {
			if (a == 1)
				cout << ar[b];
			else
			if (a % 2)
				cout << getodd(b);
			else
				cout << geteven(b);
			cout << '\n';
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Table_va_fast_up {
    private BufferedReader br;
    private StringTokenizer st;
    private PrintWriter out;

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public class Query {
        int type, x, y;

        public Query(int type, int x, int y) {
            this.type = type;
            this.x = x;
            this.y = y;
        }
    }

    final int MAXV = 10000;
    final int MAXN = 100000;
    final int MAXM = 100000;

    public void add(int[] fen, int i, int x) {
        for (; i < fen.length; i = i | (i + 1))
            fen[i] += x;
    }

    public int get(int[] fen, int i) {
        int ans = 0;
        for (; i >= 0; i = (i & (i + 1)) - 1)
            ans += fen[i];
        return ans;
    }

    public void solve() throws IOException {
        int n = nextInt();

        int[] values = new int[MAXN + MAXM];

        Query[] queries = new Query[MAXM];

        int l = 0;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            values[l++] = a[i];
        }

        int m = nextInt();
        for (int i = 0; i < m; i++) {
            int type = nextInt();
            if (type == 1) {
                queries[i] = new Query(1, nextInt(), nextInt() - 1);
                values[l++] = queries[i].x;
            } else {
                queries[i] = new Query(2, nextInt(), nextInt() - 1);
            }
        }

        values = Arrays.copyOf(values, l);
        Arrays.sort(values);
        l = 1;
        for (int i = 1; i < values.length; i++) {
            if (values[i] != values[i - 1]) {
                values[l++] = values[i];
            }
        }
        values = Arrays.copyOf(values, l);

        for (int i = 0; i < n; i++) {
            a[i] = Arrays.binarySearch(values, a[i]);
        }
        for (int i = 0; i < m; i++) {
            if (queries[i].type == 1)
                queries[i].x = Arrays.binarySearch(values, queries[i].x);
        }

        int LEN = (int) Math.ceil(Math.sqrt(n * Math.log(n) / Math.log(2)));
        int CNT = (n + LEN - 1) / LEN;// 50
        int[][] cnt = new int[CNT + 1][values.length];
        int[][] fen = new int[CNT + 1][n + 1];
        for (int i = 1; i < cnt.length; i++) {
            cnt[i] = Arrays.copyOf(cnt[i - 1], cnt[i - 1].length);
            fen[i] = Arrays.copyOf(fen[i - 1], fen[i - 1].length);

            for (int j = (i - 1) * LEN; j < Math.min(i * LEN, n); j++) {
                add(fen[i], cnt[i][a[j]], -1);
                cnt[i][a[j]]++;
                add(fen[i], cnt[i][a[j]], 1);
            }
        }

        // ������ m(n/LEN * log(n) + LEN + log(n))
        for (int i = 0; i < m; i++) {
            if (queries[i].type == 1) {
                int part = queries[i].y / LEN + 1;
                while (part < cnt.length) {
                    add(fen[part], cnt[part][a[queries[i].y]], -1);
                    cnt[part][a[queries[i].y]]--;
                    add(fen[part], cnt[part][a[queries[i].y]], 1);

                    add(fen[part], cnt[part][queries[i].x], -1);
                    cnt[part][queries[i].x]++;
                    add(fen[part], cnt[part][queries[i].x], 1);

                    part++;
                }

                a[queries[i].y] = queries[i].x;
            } else {
                int part = queries[i].y / LEN;
                int sc = cnt[part][a[queries[i].y]];
                for (int j = part * LEN; j <= queries[i].y; j++) {
                    if (a[j] == a[queries[i].y])
                        sc++;
                }

                int tc = 0;
                for (int j = part * LEN; j <= queries[i].y; j++) {
                    cnt[part][a[j]]++;
                    if (cnt[part][a[j]] == sc)
                        tc++;
                }
                for (int j = part * LEN; j <= queries[i].y; j++) {
                    cnt[part][a[j]]--;
                }

                tc += get(fen[part], fen[part].length - 1)
                        - get(fen[part], sc - 1);

                if (queries[i].x == 1) {
                    out.println(values[a[queries[i].y]]);
                } else {
                    if (queries[i].x % 2 == 1) {
                        out.println(tc);
                    } else {
                        out.println(sc);
                    }
                }
            }
        }
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public static void main(String[] args) {
        new Table_va_fast_up().run();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Table_va_fast_up {
	private BufferedReader br;
	private StringTokenizer st;
	private PrintWriter out;

	public String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public class Query {
		int type, x, y;

		public Query(int type, int x, int y) {
			this.type = type;
			this.x = x;
			this.y = y;
		}
	}

	final int MAXV = 10000;
	final int MAXN = 100000;
	final int MAXM = 100000;

	public void add(int[] fen, int i, int x) {
		for (; i < fen.length; i = i | (i + 1))
			fen[i] += x;
	}

	public int get(int[] fen, int i) {
		int ans = 0;
		for (; i >= 0; i = (i & (i + 1)) - 1)
			ans += fen[i];
		return ans;
	}

	public void solve() throws IOException {
		int n = nextInt();

		int[] values = new int[MAXN + MAXM];

		Query[] queries = new Query[MAXM];

		int l = 0;
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
			values[l++] = a[i];
		}

		int m = nextInt();
		for (int i = 0; i < m; i++) {
			int type = nextInt();
			if (type == 1) {
				queries[i] = new Query(1, nextInt(), nextInt() - 1);
				values[l++] = queries[i].x;
			} else {
				queries[i] = new Query(2, nextInt(), nextInt() - 1);
			}
		}

		values = Arrays.copyOf(values, l);
		Arrays.sort(values);
		l = 1;
		for (int i = 1; i < values.length; i++) {
			if (values[i] != values[i - 1]) {
				values[l++] = values[i];
			}
		}
		values = Arrays.copyOf(values, l);

		for (int i = 0; i < n; i++) {
			a[i] = Arrays.binarySearch(values, a[i]);
		}
		for (int i = 0; i < m; i++) {
			if (queries[i].type == 1)
				queries[i].x = Arrays.binarySearch(values, queries[i].x);
		}

		int LEN = (int) Math.ceil(Math.sqrt(n * Math.log(n) / Math.log(2)));
		int CNT = (n + LEN - 1) / LEN;// 50
		int[][] cnt = new int[CNT + 1][values.length];
		int[][] fen = new int[CNT + 1][n + 1];
		for (int i = 1; i < cnt.length; i++) {
			cnt[i] = Arrays.copyOf(cnt[i - 1], cnt[i - 1].length);
			fen[i] = Arrays.copyOf(fen[i - 1], fen[i - 1].length);

			for (int j = (i - 1) * LEN; j < Math.min(i * LEN, n); j++) {
				add(fen[i], cnt[i][a[j]], -1);
				cnt[i][a[j]]++;
				add(fen[i], cnt[i][a[j]], 1);
			}
		}

		// ������ m(n/LEN * log(n) + LEN + log(n))
		for (int i = 0; i < m; i++) {
			if (queries[i].type == 1) {
				int part = queries[i].y / LEN + 1;
				while (part < cnt.length) {
					add(fen[part], cnt[part][a[queries[i].y]], -1);
					cnt[part][a[queries[i].y]]--;
					add(fen[part], cnt[part][a[queries[i].y]], 1);

					add(fen[part], cnt[part][queries[i].x], -1);
					cnt[part][queries[i].x]++;
					add(fen[part], cnt[part][queries[i].x], 1);

					part++;
				}

				a[queries[i].y] = queries[i].x;
			} else {
				int part = queries[i].y / LEN;
				int sc = cnt[part][a[queries[i].y]];
				for (int j = part * LEN; j <= queries[i].y; j++) {
					if (a[j] == a[queries[i].y])
						sc++;
				}

				int tc = 0;
				for (int j = part * LEN; j <= queries[i].y; j++) {
					cnt[part][a[j]]++;
					if (cnt[part][a[j]] == sc)
						tc++;
				}
				for (int j = part * LEN; j <= queries[i].y; j++) {
					cnt[part][a[j]]--;
				}

				tc += get(fen[part], fen[part].length - 1)
						- get(fen[part], sc - 1);

				if (queries[i].x == 1) {
					out.println(values[a[queries[i].y]]);
				} else {
					if (queries[i].x % 2 == 1) {
						out.println(tc);
					} else {
						out.println(sc);
					}
				}
			}
		}
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public static void main(String[] args) {
		new Table_va_fast_up().run();
	}
}


import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    public void run() {
        try {
            int n = reader.nextInt();
            List <Integer> values = new ArrayList <Integer>();
            int[] a = new int[n];
            for (int i = 0; i < n; ++ i) {
                a[i] = reader.nextInt();
                values.add(a[i]);
            }
            int q = reader.nextInt();
            Query[] queries = new Query[q];
            for (int i = 0; i < q; ++ i) {
                int t = reader.nextInt();
                int x = reader.nextInt();
                int y = reader.nextInt();
                queries[i] = new Query(t, x, y);
                if (t == 1) {
                    values.add(x);
                }
            }
            values = unique(values);
            int m = values.size();
            Map <Integer, Integer> newValues = new HashMap <Integer, Integer>();
            for (int i = 0; i < m; ++ i) {
                newValues.put(values.get(i), i);
            }
            int size = Math.max((int)Math.sqrt(n * Math.log(n)), 1);
            int block = (n + size - 1) / size;
            int[][] count = new int[block + 1][m];
            for (int i = 0; i < n; ++ i) {
                if (i % size == 0) {
                    for (int j = 0; j < m; ++ j) {
                        count[i / size + 1][j] += count[i / size][j];
                    }
                }
                a[i] = newValues.get(a[i]);
                count[i / size + 1][a[i]] ++;
            }
            int[][] stats = new int[block + 1][n + 1];
            for (int i = 1; i <= block; ++ i) {
                for (int j = 0; j < m; ++ j) {
                    add(stats[i], count[i][j], 1);
                }
            }
            for (Query query : queries) {
                int k = query.index;
                int id = k / size;
                if (query.type == 2) {
                    if (query.value == 0) {
                        writer.println(values.get(a[k]));
                    } else {
                        int rank = 0;
                        rank += count[id][a[k]];
                        for (int i = k / size * size; i <= k; ++ i) {
                            if (a[i] == a[k]) {
                                rank ++;
                            }
                        }
                        if (query.value % 2 == 1) {
                            writer.println(rank);
                        } else {
                            int result = 0;
                            for (int i = rank; i <= n; i += ~i & i + 1) {
                                result += stats[id][i];
                            }
                            for (int i = k / size * size; i <= k; ++ i) {
                                count[id][a[i]] ++;
                                if (count[id][a[i]] == rank) {
                                    result ++;
                                }
                            }
                            for (int i = k / size * size; i <= k; ++ i) {
                                count[id][a[i]] --;
                            }
                            writer.println(result);
                        }
                    }
                } else {
                    int newA = newValues.get(query.value);
                    for (int i = id + 1; i <= block; ++ i) {
                        add(stats[i], count[i][a[k]], -1);
                        count[i][a[k]] --;
                        add(stats[i], count[i][a[k]], +1);
                        add(stats[i], count[i][newA], -1);
                        count[i][newA] ++;
                        add(stats[i], count[i][newA], +1);
                    }
                    a[k] = newA;
                }
            }
        } catch (IOException ex) {
        }
        writer.close();
    }

    void add(int[] stat, int k, int v) {
        for (; k >= 0; k -= ~k & k + 1) {
            stat[k] += v;
        }
    }

    List <Integer> unique(List <Integer> array) {
        Set <Integer> set = new HashSet <Integer>();
        set.addAll(array);
        array = new ArrayList <Integer>();
        array.addAll(set);
        return array;
    }

    class Query {
        Query(int t, int x, int y) {
            this.type = t;
            this.value = x - (t - 1);
            this.index = y - 1;
        }

        int type, value, index;
    }

    Main() {
        reader = new InputReader(System.in);
        writer = new PrintWriter(System.out);
    }

    public static void main(String[] args) {
        new Main().run();
    }

    private void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    private InputReader reader;
    private PrintWriter writer;
}

class InputReader {
    InputReader(InputStream in) {
        reader    = new BufferedReader(new InputStreamReader(in));
        //try {
        //    reader    = new BufferedReader(new FileReader("E.in"));
        //} catch (FileNotFoundException ex) {
        //}
        tokenizer = new StringTokenizer("");
    }

    private String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private BufferedReader  reader;
    private StringTokenizer tokenizer;
}


import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    public void run() {
        try {
            int n = reader.nextInt();
            List <Integer> values = new ArrayList <Integer>();
            int[] a = new int[n];
            for (int i = 0; i < n; ++ i) {
                a[i] = reader.nextInt();
                values.add(a[i]);
            }
            int q = reader.nextInt();
            Query[] queries = new Query[q];
            for (int i = 0; i < q; ++ i) {
                int t = reader.nextInt();
                int x = reader.nextInt();
                int y = reader.nextInt();
                queries[i] = new Query(t, x, y);
                if (t == 1) {
                    values.add(x);
                }
            }
            values = unique(values);
            int m = values.size();
            Map <Integer, Integer> newValues = new HashMap <Integer, Integer>();
            for (int i = 0; i < m; ++ i) {
                newValues.put(values.get(i), i);
            }
            int size = Math.max((int)Math.sqrt(n * Math.log(n)), 1);
            int block = (n + size - 1) / size;
            int[][] count = new int[block + 1][m];
            for (int i = 0; i < n; ++ i) {
                if (i % size == 0) {
                    for (int j = 0; j < m; ++ j) {
                        count[i / size + 1][j] += count[i / size][j];
                    }
                }
                a[i] = newValues.get(a[i]);
                count[i / size + 1][a[i]] ++;
            }
            int[][] stats = new int[block + 1][n + 1];
            for (int i = 1; i <= block; ++ i) {
                for (int j = 0; j < m; ++ j) {
                    add(stats[i], count[i][j], 1);
                }
            }
            for (Query query : queries) {
                int k = query.index;
                int id = k / size;
                if (query.type == 2) {
                    if (query.value == 0) {
                        writer.println(a[k]);
                    } else {
                        int rank = 0;
                        rank += count[id][a[k]];
                        for (int i = k / size * size; i <= k; ++ i) {
                            if (a[i] == a[k]) {
                                rank ++;
                            }
                        }
                        if (query.value % 2 == 1) {
                            writer.println(rank);
                        } else {
                            int result = 0;
                            for (int i = rank; i <= n; i += ~i & i + 1) {
                                result += stats[id][i];
                            }
                            for (int i = k / size * size; i <= k; ++ i) {
                                count[id][a[i]] ++;
                                if (count[id][a[i]] == rank) {
                                    result ++;
                                }
                            }
                            for (int i = k / size * size; i <= k; ++ i) {
                                count[id][a[i]] --;
                            }
                            writer.println(result);
                        }
                    }
                } else {
                    int newA = newValues.get(query.value);
                    for (int i = id + 1; i <= block; ++ i) {
                        add(stats[i], count[i][a[k]], -1);
                        count[i][a[k]] --;
                        add(stats[i], count[i][a[k]], +1);
                        add(stats[i], count[i][newA], -1);
                        count[i][newA] ++;
                        add(stats[i], count[i][newA], +1);
                    }
                    a[k] = newA;
                }
            }
        } catch (IOException ex) {
        }
        writer.close();
    }

    void add(int[] stat, int k, int v) {
        for (; k >= 0; k -= ~k & k + 1) {
            stat[k] += v;
        }
    }

    List <Integer> unique(List <Integer> array) {
        Set <Integer> set = new HashSet <Integer>();
        set.addAll(array);
        array = new ArrayList <Integer>();
        array.addAll(set);
        return array;
    }

    class Query {
        Query(int t, int x, int y) {
            this.type = t;
            this.value = x - (t - 1);
            this.index = y - 1;
        }

        int type, value, index;
    }

    Main() {
        reader = new InputReader(System.in);
        writer = new PrintWriter(System.out);
    }

    public static void main(String[] args) {
        new Main().run();
    }

    private void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    private InputReader reader;
    private PrintWriter writer;
}

class InputReader {
    InputReader(InputStream in) {
        reader    = new BufferedReader(new InputStreamReader(in));
        //try {
        //    reader    = new BufferedReader(new FileReader("E.in"));
        //} catch (FileNotFoundException ex) {
        //}
        tokenizer = new StringTokenizer("");
    }

    private String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private BufferedReader  reader;
    private StringTokenizer tokenizer;
}


import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    public void run() {
        try {
            int n = reader.nextInt();
            List <Integer> values = new ArrayList <Integer>();
            int[] a = new int[n];
            for (int i = 0; i < n; ++ i) {
                a[i] = reader.nextInt();
                values.add(a[i]);
            }
            int q = reader.nextInt();
            Query[] queries = new Query[q];
            for (int i = 0; i < q; ++ i) {
                int t = reader.nextInt();
                int x = reader.nextInt();
                int y = reader.nextInt();
                queries[i] = new Query(t, x, y);
                if (t == 1) {
                    values.add(x);
                }
            }
            values = unique(values);
            int m = values.size();
            Map <Integer, Integer> newValues = new HashMap <Integer, Integer>();
            for (int i = 0; i < m; ++ i) {
                newValues.put(values.get(i), i);
            }
            int size = Math.max((int)Math.sqrt(n), 1);
            //int size = Math.max((int)Math.sqrt(n * Math.log(n)), 1);
            int block = (n + size - 1) / size;
            int[][] count = new int[block + 1][m];
            for (int i = 0; i < n; ++ i) {
                if (i % size == 0) {
                    for (int j = 0; j < m; ++ j) {
                        count[i / size + 1][j] += count[i / size][j];
                    }
                }
                a[i] = newValues.get(a[i]);
                count[i / size + 1][a[i]] ++;
            }
            int[][] stats = new int[block + 1][n + 1];
            for (int i = 1; i <= block; ++ i) {
                for (int j = 0; j < m; ++ j) {
                    add(stats[i], count[i][j], 1);
                }
            }
            for (Query query : queries) {
                int k = query.index;
                int id = k / size;
                if (query.type == 2) {
                    if (query.value == 0) {
                        writer.println(values.get(a[k]));
                    } else {
                        int rank = 0;
                        rank += count[id][a[k]];
                        for (int i = k / size * size; i <= k; ++ i) {
                            if (a[i] == a[k]) {
                                rank ++;
                            }
                        }
                        if (query.value % 2 == 1) {
                            writer.println(rank);
                        } else {
                            int result = 0;
                            for (int i = rank; i <= n; i += ~i & i + 1) {
                                result += stats[id][i];
                            }
                            for (int i = k / size * size; i <= k; ++ i) {
                                count[id][a[i]] ++;
                                if (count[id][a[i]] == rank) {
                                    result ++;
                                }
                            }
                            for (int i = k / size * size; i <= k; ++ i) {
                                count[id][a[i]] --;
                            }
                            writer.println(result);
                        }
                    }
                } else {
                    int newA = newValues.get(query.value);
                    for (int i = id + 1; i <= block; ++ i) {
                        add(stats[i], count[i][a[k]], -1);
                        count[i][a[k]] --;
                        add(stats[i], count[i][a[k]], +1);
                        add(stats[i], count[i][newA], -1);
                        count[i][newA] ++;
                        add(stats[i], count[i][newA], +1);
                    }
                    a[k] = newA;
                }
            }
        } catch (IOException ex) {
        }
        writer.close();
    }

    void add(int[] stat, int k, int v) {
        for (; k >= 0; k -= ~k & k + 1) {
            stat[k] += v;
        }
    }

    List <Integer> unique(List <Integer> array) {
        Set <Integer> set = new HashSet <Integer>();
        set.addAll(array);
        array = new ArrayList <Integer>();
        array.addAll(set);
        return array;
    }

    class Query {
        Query(int t, int x, int y) {
            this.type = t;
            this.value = x - (t - 1);
            this.index = y - 1;
        }

        int type, value, index;
    }

    Main() {
        reader = new InputReader(System.in);
        writer = new PrintWriter(System.out);
    }

    public static void main(String[] args) {
        new Main().run();
    }

    private void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    private InputReader reader;
    private PrintWriter writer;
}

class InputReader {
    InputReader(InputStream in) {
        reader    = new BufferedReader(new InputStreamReader(in));
        //try {
        //    reader    = new BufferedReader(new FileReader("E.in"));
        //} catch (FileNotFoundException ex) {
        //}
        tokenizer = new StringTokenizer("");
    }

    private String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private BufferedReader  reader;
    private StringTokenizer tokenizer;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;
const int B = 1000;
int m, k, cnt, tot, a[100001], f[101][200001], g[101][200001], val[200001];
map<int, int> mp;
int get_id(int x)
{
    if (!mp.count(x))
    {
        val[++cnt] = x;
        return mp[x] = cnt;
    }
    return mp[x];
}
int main(int argc, char const *argv[])
{
    scanf("%d", &m);
    tot = (m - 1) / B + 1;
    for (int i = 0; i < m; i++)
    {
        int x;
        scanf("%d", &x);
        a[i] = get_id(x);
    }
    for (int i = 0; i < m; i += B)
    {
        int id = i / B + 1, r = min(i + B - 1, m);
        memcpy(f[id], f[id - 1], sizeof(f[id - 1]));
        memcpy(g[id], g[id - 1], sizeof(g[id - 1]));
        for (int j = i; j <= r; j++)
        {
            f[id][a[j]]++;
            g[id][f[id][a[j]]]++;
        }
    }
    scanf("%d", &k);
    for (int i = 1; i <= k; i++)
    {
        int op, x, y;
        scanf("%d%d%d", &op, &x, &y);
        y--;
        if (op == 1)
        {
            for (int j = y / B + 1; j <= tot; j++)
            {
                g[j][f[j][a[y]]]--;
                f[j][a[y]]--;
            }
            a[y] = get_id(x);
            for (int j = 1; j <= tot; j++)
            {
                f[j][a[y]]++;
                g[j][f[j][a[y]]]++;
            }
        }
        else
        {
            if (x == 1)
            {
                printf("%d\n", val[a[y]]);
            }
            else
            {
                int id = y / B;
                for (int j = id * B; j <= y; j++)
                {
                    f[id][a[j]]++;
                    g[id][f[id][a[j]]]++;
                }
                if (x & 1)
                {
                    printf("%d\n", g[id][f[id][a[y]]]);
                }
                else
                {
                    printf("%d\n", f[id][a[y]]);
                }
                for (int j = y; j >= id * B; j--)
                {
                    g[id][f[id][a[j]]]--;
                    f[id][a[j]]--;
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;
const int B = 1000;
int m, k, cnt, tot, a[100001], f[101][200001], g[101][200001], val[200001];
map<int, int> mp;
int get_id(int x)
{
    if (!mp.count(x))
    {
        val[++cnt] = x;
        return mp[x] = cnt;
    }
    return mp[x];
}
int main(int argc, char const *argv[])
{
    scanf("%d", &m);
    tot = (m - 1) / B + 1;
    for (int i = 0; i < m; i++)
    {
        int x;
        scanf("%d", &x);
        a[i] = get_id(x);
    }
    for (int i = 0; i < m; i += B)
    {
        int id = i / B + 1, r = min(i + B - 1, m - 1);
        memcpy(f[id], f[id - 1], sizeof(f[id - 1]));
        memcpy(g[id], g[id - 1], sizeof(g[id - 1]));
        for (int j = i; j <= r; j++)
        {
            f[id][a[j]]++;
            g[id][f[id][a[j]]]++;
        }
    }
    scanf("%d", &k);
    for (int i = 1; i <= k; i++)
    {
        int op, x, y;
        scanf("%d%d%d", &op, &x, &y);
        y--;
        if (op == 1)
        {
            for (int j = y / B + 1; j <= tot; j++)
            {
                g[j][f[j][a[y]]]--;
                f[j][a[y]]--;
            }
            a[y] = get_id(x);
            for (int j = 1; j <= tot; j++)
            {
                f[j][a[y]]++;
                g[j][f[j][a[y]]]++;
            }
        }
        else
        {
            if (x == 1)
            {
                printf("%d\n", val[a[y]]);
            }
            else
            {
                int id = y / B;
                for (int j = id * B; j <= y; j++)
                {
                    f[id][a[j]]++;
                    g[id][f[id][a[j]]]++;
                }
                if (x & 1)
                {
                    printf("%d\n", g[id][f[id][a[y]]]);
                }
                else
                {
                    printf("%d\n", f[id][a[y]]);
                }
                for (int j = y; j >= id * B; j--)
                {
                    g[id][f[id][a[j]]]--;
                    f[id][a[j]]--;
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;
const int B = 1000;
int m, k, cnt, tot, a[100001], f[101][200001], g[101][200001], val[200001];
map<int, int> mp;
int get_id(int x)
{
    if (!mp.count(x))
    {
        val[++cnt] = x;
        return mp[x] = cnt;
    }
    return mp[x];
}
int main(int argc, char const *argv[])
{
    scanf("%d", &m);
    tot = (m - 1) / B + 1;
    for (int i = 0; i < m; i++)
    {
        int x;
        scanf("%d", &x);
        a[i] = get_id(x);
    }
    for (int i = 1; i <= tot; i++)
    {
        int r = min(i * B - 1, m - 1);
        memcpy(f[i], f[i - 1], sizeof(f[i - 1]));
        memcpy(g[i], g[i - 1], sizeof(g[i - 1]));
        for (int j = B * (i - 1); j <= r; j++)
        {
            f[i][a[j]]++;
            g[i][f[i][a[j]]]++;
        }
    }
    scanf("%d", &k);
    for (int i = 1; i <= k; i++)
    {
        int op, x, y;
        scanf("%d%d%d", &op, &x, &y);
        y--;
        if (op == 1)
        {
            for (int j = y / B + 1; j <= tot; j++)
            {
                g[j][f[j][a[y]]]--;
                f[j][a[y]]--;
            }
            a[y] = get_id(x);
            for (int j = y / B + 1; j <= tot; j++)
            {
                f[j][a[y]]++;
                g[j][f[j][a[y]]]++;
            }
        }
        else
        {
            if (x == 1)
            {
                printf("%d\n", val[a[y]]);
            }
            else
            {
                int id = y / B;
                for (int j = id * B; j <= y; j++)
                {
                    f[id][a[j]]++;
                    g[id][f[id][a[j]]]++;
                }
                if (x & 1)
                {
                    printf("%d\n", g[id][f[id][a[y]]]);
                }
                else
                {
                    printf("%d\n", f[id][a[y]]);
                }
                for (int j = y; j >= id * B; j--)
                {
                    g[id][f[id][a[j]]]--;
                    f[id][a[j]]--;
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int magic = 333;

int n, m, a[maxn], q[maxn][3], rc[maxn],
    f[maxn], ff[maxn], g[maxn], res[maxn];
pair<int, int> c[maxn]; int csz;

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        c[csz++] = {a[i], i};
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> q[i][0] >> q[i][1] >> q[i][2];
        if (q[i][0] == 1) {
            --q[i][2];
            c[csz++] = {q[i][1], n + i};
        } else {
            --q[i][1];
            --q[i][2];
        }
    }
}

void compress() {
    sort(c, c + csz);
    int idx = 0;
    rc[idx] = c[0].first;
    for (int i = 0; i < csz; i++) {
        if (0 < i && c[i - 1].first < c[i].first) {
            ++idx;
            rc[idx] = c[i].first;
        }

        pair<int, int> cur = c[i];
        if (cur.second < n) {
            a[cur.second] = idx;
        } else {
            q[cur.second - n][1] = idx;
        }
    }
}

inline void add(int val) {
    ++ff[++f[val]];
}

inline void rem(int val) {
    --ff[f[val]--];
}

void compute(int b, int e) { //[b, e)
    memset(f, 0, sizeof(f));
    memset(ff, 0, sizeof(ff));
    memcpy(g, a, sizeof(g));
    for (int i = 0; i < b; i++) {
        add(g[i]);
    }

    for (int i = 0; i < m; i++) {
        int t = q[i][0], x = q[i][1], y = q[i][2];
        if (y < e) {
            if (t == 1) {
                if (y < b) {
                    rem(g[y]);
                    add(x);
                }
                g[y] = x;
            } else if (b <= y) {
                if (x == 0) {
                    res[i] = rc[g[y]];
                } else if (x % 2 == 1) {
                    int cur = f[g[y]], tar = g[y];
                    for (int j = b; j <= y; j++) {
                        if (g[j] == tar) {
                            ++cur;
                        }
                    }
                    res[i] = cur;
                } else {
                    for (int j = b; j <= y; j++) {
                        add(g[j]);
                    }
                    res[i] = ff[f[g[y]]];
                    for (int j = b; j <= y; j++) {
                        rem(g[j]);
                    }
                }
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    input();
    compress();

    for (int i = 0; i < n;) {
        compute(i, min(i + magic, n));
        i += magic;
    }

    for (int i = 0; i < m; i++) {
        if (q[i][0] == 2) {
            cout << res[i] << '\n';
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>
void read(T &x)
{
    x=0;char c=getchar();bool p=0;
    for(;c<'0'||c>'9';c=getchar())if(c=='-')p=1;
    for(;c>='0'&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);
    if(p)x=-x;
}
unordered_map<int,int>mp;
const int N=100005;
int a[N],f[105][N<<1],g[105][N<<1];
int val[N<<1],cnt,blk[N];
int st[505],ed[505];
int n,m;
int sz,tot;
int find(int x)
{
    if(!mp[x])
    {
        mp[x]=++cnt;
        val[cnt]=x;
    }
    return cnt;
}
int main()
{
    /*read(n),*/read(n)/*,read(m)*/;
    sz=1000;
    for(int i=1,x;i<=n;++i)
    {
        blk[i]=(i-1)/sz+1;
        if(blk[i]!=blk[i-1])
        {
            st[blk[i]]=i;
            ed[blk[i]-1]=i-1;
        }
        read(x);
        a[i]=find(x);
    }
    ed[blk[n]]=n;
    tot=blk[n];
    st[tot+1]=n+1;
    for(int i=1;i<=tot;++i)
    {
        for(int j=1;j<=cnt;++j)
        {
            f[i][j]=f[i-1][j];
            g[i][j]=g[i-1][j];
        }
        for(int j=st[i];j<=ed[i];++j)
        {
            ++f[i][a[j]];
            ++g[i][f[i][a[j]]];
        }
    }
    read(m);
    for(int i=1,opt,x,y;i<=m;++i)
    {
        read(opt);read(x);read(y);
        if(/*!opt*/opt==2)
        {
            if(x==1)
            {
                printf("%d\n",val[a[y]]);
            }
            else
            {
                int pos=upper_bound(ed+1,ed+tot+1,y)-ed-1;
                for(int j=st[pos+1];j<=y;++j)
                {
                    ++f[pos][a[j]];
                    ++g[pos][f[pos][a[j]]];
                }
                //cout<<pos<<' '<<a[y]<<' '<<f[pos][a[y]]<<endl;
                if(x&1)printf("%d\n",g[pos][f[pos][a[y]]]);else printf("%d\n",f[pos][a[y]]);
                for(int j=st[pos+1];j<=y;++j)
                {
                    --g[pos][f[pos][a[j]]];
                    --f[pos][a[j]];
                }
            }
        }
        else
        {
            swap(x,y);
            for(int j=blk[x];j<=tot;++j)
            {
                --g[j][f[j][a[x]]];
                --f[j][a[x]];
            }
            a[x]=find(y);
            for(int j=blk[x];j<=tot;++j)
            {
                ++f[j][a[x]];
                ++g[j][f[j][a[x]]];
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>
void read(T &x)
{
    x=0;char c=getchar();bool p=0;
    for(;c<'0'||c>'9';c=getchar())if(c=='-')p=1;
    for(;c>='0'&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);
    if(p)x=-x;
}
unordered_map<int,int>mp;
const int N=100005;
int a[N],f[105][N<<1],g[105][N<<1];
int val[N<<1],cnt,blk[N];
int st[505],ed[505];
int n,m;
int sz,tot;
int find(int x)
{
    if(!mp[x])
    {
        mp[x]=++cnt;
        val[cnt]=x;
    }
    return cnt;
}
int main()
{
    /*read(n),*/read(n)/*,read(m)*/;
    sz=1000;
    for(int i=1,x;i<=n;++i)
    {
        blk[i]=(i-1)/sz+1;
        if(blk[i]!=blk[i-1])
        {
            st[blk[i]]=i;
            ed[blk[i]-1]=i-1;
        }
        read(x);
        a[i]=find(x);
    }
    ed[blk[n]]=n;
    tot=blk[n];
    st[tot+1]=n+1;
    for(int i=1;i<=tot;++i)
    {
        for(int j=0;j<(N<<1);++j)
        {
            f[i][j]=f[i-1][j];
            g[i][j]=g[i-1][j];
        }
        for(int j=st[i];j<=ed[i];++j)
        {
            ++f[i][a[j]];
            ++g[i][f[i][a[j]]];
        }
    }
    read(m);
    for(int i=1,opt,x,y;i<=m;++i)
    {
        read(opt);read(x);read(y);
        if(/*!opt*/opt==2)
        {
            if(x==1)
            {
                printf("%d\n",val[a[y]]);
            }
            else
            {
                int pos=upper_bound(ed+1,ed+tot+1,y)-ed-1;
                for(int j=st[pos+1];j<=y;++j)
                {
                    ++f[pos][a[j]];
                    ++g[pos][f[pos][a[j]]];
                }
                //cout<<pos<<' '<<a[y]<<' '<<f[pos][a[y]]<<endl;
                if(x&1)printf("%d\n",g[pos][f[pos][a[y]]]);else printf("%d\n",f[pos][a[y]]);
                for(int j=st[pos+1];j<=y;++j)
                {
                    --g[pos][f[pos][a[j]]];
                    --f[pos][a[j]];
                }
            }
        }
        else
        {
            swap(x,y);
            for(int j=blk[x];j<=tot;++j)
            {
                --g[j][f[j][a[x]]];
                --f[j][a[x]];
            }
            a[x]=find(y);
            for(int j=blk[x];j<=tot;++j)
            {
                ++f[j][a[x]];
                ++g[j][f[j][a[x]]];
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>
void read(T &x)
{
    x=0;char c=getchar();bool p=0;
    for(;c<'0'||c>'9';c=getchar())if(c=='-')p=1;
    for(;c>='0'&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);
    if(p)x=-x;
}
unordered_map<int,int>mp;
const int N=100005;
int a[N],f[105][N<<1],g[105][N<<1];
int val[N<<1],cnt,blk[N];
int st[505],ed[505];
int n,m;
int sz,tot;
int find(int x)
{
    if(!mp[x])
    {
        ++cnt;
        mp[x]=cnt;
        val[cnt]=x;
    }
    return mp[x];
}
int main()
{
    read(n);
    sz=1000;
    for(int i=1,x;i<=n;++i)
    {
        blk[i]=(i-1)/sz+1;
        if(blk[i]!=blk[i-1])
        {
            st[blk[i]]=i;
            ed[blk[i]-1]=i-1;
        }
        read(x);
        a[i]=find(x);
    }
    ed[blk[n]]=n;
    tot=blk[n];
    st[tot+1]=n+1;
    for(int i=1;i<=tot;++i)
    {
        for(int j=0;j<(N<<1);++j)
        {
            f[i][j]=f[i-1][j];
            g[i][j]=g[i-1][j];
        }
        for(int j=st[i];j<=ed[i];++j)
        {
            ++f[i][a[j]];
            ++g[i][f[i][a[j]]];
        }
    }
    read(m);
    for(int i=1,opt,x,y;i<=m;++i)
    {
        read(opt);read(x);read(y);
        if(/*!opt*/opt==2)
        {
            if(x==1)
            {
                printf("%d\n",val[a[y]]);
            }
            else
            {
                int pos=upper_bound(ed+1,ed+tot+1,y)-ed-1;
                for(int j=st[pos+1];j<=y;++j)
                {
                    ++f[pos][a[j]];
                    ++g[pos][f[pos][a[j]]];
                }
                if(x&1)printf("%d\n",g[pos][f[pos][a[y]]]);else printf("%d\n",f[pos][a[y]]);
                for(int j=st[pos+1];j<=y;++j)
                {
                    --g[pos][f[pos][a[j]]];
                    --f[pos][a[j]];
                }
            }
        }
        else
        {
            swap(x,y);
            for(int j=blk[x];j<=tot;++j)
            {
                --g[j][f[j][a[x]]];
                --f[j][a[x]];
            }
            a[x]=find(y);
            for(int j=blk[x];j<=tot;++j)
            {
                ++f[j][a[x]];
                ++g[j][f[j][a[x]]];
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>
void read(T &x)
{
    x=0;char c=getchar();bool p=0;
    for(;c<'0'||c>'9';c=getchar())if(c=='-')p=1;
    for(;c>='0'&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);
    if(p)x=-x;
}
unordered_map<int,int>mp;
const int N=100005;
int a[N],f[105][N<<1],g[105][N<<1];
int val[N<<1],cnt,blk[N];
int st[505],ed[505];
int n,m;
int sz,tot;
int find(int x)
{
    if(!mp[x])
    {
        ++cnt;
        mp[x]=cnt;
        val[cnt]=x;
    }
    return mp[x];
}
int main()
{
    read(n);
    sz=1000;
    for(int i=1,x;i<=n;++i)
    {
        blk[i]=(i-1)/sz+1;
        if(blk[i]!=blk[i-1])
        {
            st[blk[i]]=i;
            ed[blk[i]-1]=i-1;
        }
        read(x);
        a[i]=find(x);
    }
    ed[blk[n]]=n;
    tot=blk[n];
    st[tot+1]=n+1;
    for(int i=1;i<=tot;++i)
    {
        for(int j=1;j<=cnt;++j)
        {
            f[i][j]=f[i-1][j];
            g[i][j]=g[i-1][j];
        }
        for(int j=st[i];j<=ed[i];++j)
        {
            ++f[i][a[j]];
            ++g[i][f[i][a[j]]];
        }
    }
    read(m);
    for(int i=1,opt,x,y;i<=m;++i)
    {
        read(opt);read(x);read(y);
        if(/*!opt*/opt==2)
        {
            if(x==1)
            {
                printf("%d\n",val[a[y]]);
            }
            else
            {
                int pos=upper_bound(ed+1,ed+tot+1,y)-ed-1;
                for(int j=st[pos+1];j<=y;++j)
                {
                    ++f[pos][a[j]];
                    ++g[pos][f[pos][a[j]]];
                }
                if(x&1)printf("%d\n",g[pos][f[pos][a[y]]]);else printf("%d\n",f[pos][a[y]]);
                for(int j=st[pos+1];j<=y;++j)
                {
                    --g[pos][f[pos][a[j]]];
                    --f[pos][a[j]];
                }
            }
        }
        else
        {
            swap(x,y);
            for(int j=blk[x];j<=tot;++j)
            {
                --g[j][f[j][a[x]]];
                --f[j][a[x]];
            }
            a[x]=find(y);
            for(int j=blk[x];j<=tot;++j)
            {
                ++f[j][a[x]];
                ++g[j][f[j][a[x]]];
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i ++)
const int N = 100000;
const int B = 333;

int a[N];
int cnt[N / B + 1][N + N + 1];
int C[N / B + 1][N + 1];

struct QQ {
	int typ, x, y;
	void Scan() {
		scanf("%d%d%d", &typ, &x, &y);
	}
}queries[N];

struct San: vector<int> {
	void prepare() {
		sort(begin(), end());
		erase(unique(begin(), end()), end());
	}
	int get(int x) const {
		return lower_bound(begin(), end(), x) - begin() + 1;
	}
}ly;

int length;
void add(int *C, int x, int value) {
	if(x == 0)	return;
	for(; x <= length; x += x & -x) {
		C[x] += value;
	}
}
int query(int *C, int x) {
	int ret = 0;
	for(; x; x -= x & -x) {
		ret += C[x];
	}
	return ret;
}
int main() {
	int n, q, B;
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", a + i);
		ly.push_back(a[i]);
	}
	B = sqrt(n*ceil(log(n)));
	scanf("%d", &q);
	rep(i, q) {
		queries[i].Scan();
		if(queries[i].typ == 1) {
			ly.push_back(queries[i].x);
		}
	}
	ly.prepare();
	length = n;
	rep(i, n) {
		int part = i / B + 1, v = ly.get(a[i]);
		a[i] = v;
		if(i % B == 0) {
			memcpy(cnt[part], cnt[part - 1], sizeof cnt[part]);
			memcpy(C[part], C[part - 1], sizeof C[part]);
		}
		cnt[part][v] ++;
		add(C[part], cnt[part][v] - 1, -1);
		add(C[part], cnt[part][v], 1);
	}
	rep(i, q) {
		if(queries[i].typ == 1) {
			swap(queries[i].x, queries[i].y);
			queries[i].x --;
			int v = a[queries[i].x];
			for(int j = queries[i].x / B + 1; j <= (n - 1) / B + 1; j ++) {
				cnt[j][v] --;
				add(C[j], cnt[j][v] + 1, -1);
				add(C[j], cnt[j][v], 1);
			}
			a[queries[i].x] = v = ly.get(queries[i].y);
			for(int j = queries[i].x / B + 1; j <= (n - 1) / B + 1; j ++) {
				cnt[j][v] ++;
				add(C[j], cnt[j][v] - 1, -1);
				add(C[j], cnt[j][v], 1);
			}
		} else {
			queries[i].y --;
			int part = queries[i].y / B + 1, v;
			if(queries[i].x == 1) {
				printf("%d\n", ly[a[queries[i].y] - 1]);
				continue;
			}
			int c = 0, s = 0;
			for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
				if(a[j] == a[queries[i].y])
					c ++;
			}
			v = a[queries[i].y];
			c += cnt[part - 1][v];
			if(queries[i].x & 1 ^ 1) {
				printf("%d\n", c);
			} else {
				for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
					v = a[j];
					cnt[part - 1][v] ++;
					if(cnt[part - 1][v] == c) {
						s ++;
					}
				}
				for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
					v = a[j];
					cnt[part - 1][v] --;
				}
				s += query(C[part - 1], length) - query(C[part - 1], c - 1);
				printf("%d\n", s);
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i ++)
const int N = 100000;
const int B = 1000;

int a[N];
int cnt[N / B + 1][N + N + 1];
int C[N / B + 1][N + 1];

struct QQ {
	int typ, x, y;
	void Scan() {
		scanf("%d%d%d", &typ, &x, &y);
	}
}queries[N];

struct San: vector<int> {
	void prepare() {
		sort(begin(), end());
		erase(unique(begin(), end()), end());
	}
	int get(int x) const {
		return lower_bound(begin(), end(), x) - begin() + 1;
	}
}ly;

int length;
void add(int *C, int x, int value) {
	if(x == 0)	return;
	for(; x <= length; x += x & -x) {
		C[x] += value;
	}
}
int query(int *C, int x) {
	int ret = 0;
	for(; x; x -= x & -x) {
		ret += C[x];
	}
	return ret;
}
int main() {
	int n, q, B;
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", a + i);
		ly.push_back(a[i]);
	}
	B = sqrt(n*ceil(log(n)));
	scanf("%d", &q);
	rep(i, q) {
		queries[i].Scan();
		if(queries[i].typ == 1) {
			ly.push_back(queries[i].y);
		}
	}
	ly.prepare();
	length = n;
	rep(i, n) {
		int part = i / B + 1, v = ly.get(a[i]);
		a[i] = v;
		if(i % B == 0) {
			memcpy(cnt[part], cnt[part - 1], sizeof cnt[part]);
			memcpy(C[part], C[part - 1], sizeof C[part]);
		}
		cnt[part][v] ++;
		add(C[part], cnt[part][v] - 1, -1);
		add(C[part], cnt[part][v], 1);
	}
	rep(i, q) {
		if(queries[i].typ == 1) {
			swap(queries[i].x, queries[i].y);
			queries[i].x --;
			int v = a[queries[i].x];
			for(int j = queries[i].x / B + 1; j <= (n - 1) / B + 1; j ++) {
				cnt[j][v] --;
				add(C[j], cnt[j][v] + 1, -1);
				add(C[j], cnt[j][v], 1);
			}
			a[queries[i].x] = v = ly.get(queries[i].y);
			for(int j = queries[i].x / B + 1; j <= (n - 1) / B + 1; j ++) {
				cnt[j][v] ++;
				add(C[j], cnt[j][v] - 1, -1);
				add(C[j], cnt[j][v], 1);
			}
		} else {
			queries[i].y --;
			int part = queries[i].y / B + 1, v;
			if(queries[i].x == 1) {
				printf("%d\n", ly[a[queries[i].y] - 1]);
				continue;
			}
			int c = 0, s = 0;
			for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
				if(a[j] == a[queries[i].y])
					c ++;
			}
			v = a[queries[i].y];
			c += cnt[part - 1][v];
			if(queries[i].x & 1 ^ 1) {
				printf("%d\n", c);
			} else {
				for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
					v = a[j];
					cnt[part - 1][v] ++;
					if(cnt[part - 1][v] == c) {
						s ++;
					}
				}
				for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
					v = a[j];
					cnt[part - 1][v] --;
				}
				s += query(C[part - 1], length) - query(C[part - 1], c - 1);
				printf("%d\n", s);
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i ++)
const int N = 100000;
const int B = 333;

int a[N];
int cnt[N / B + 1][N + N + 1];
int C[N / B + 1][N + 1];

struct QQ {
	int typ, x, y;
	void Scan() {
		scanf("%d%d%d", &typ, &x, &y);
	}
}queries[N];

struct San: vector<int> {
	void prepare() {
		sort(begin(), end());
		erase(unique(begin(), end()), end());
	}
	int get(int x) const {
		return lower_bound(begin(), end(), x) - begin() + 1;
	}
}ly;

int length;
void add(int *C, int x, int value) {
	if(x == 0)	return;
	for(; x <= length; x += x & -x) {
		C[x] += value;
	}
}
int query(int *C, int x) {
	int ret = 0;
	for(; x; x -= x & -x) {
		ret += C[x];
	}
	return ret;
}
int main() {
	int n, q, B;
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", a + i);
		ly.push_back(a[i]);
	}
	B = sqrt(n*ceil(log(n)));
	scanf("%d", &q);
	rep(i, q) {
		queries[i].Scan();
		if(queries[i].typ == 1) {
			ly.push_back(queries[i].y);
		}
	}
	ly.prepare();
	length = n;
	rep(i, n) {
		int part = i / B + 1, v = ly.get(a[i]);
		a[i] = v;
		if(i % B == 0) {
			memcpy(cnt[part], cnt[part - 1], sizeof cnt[part]);
			memcpy(C[part], C[part - 1], sizeof C[part]);
		}
		cnt[part][v] ++;
		add(C[part], cnt[part][v] - 1, -1);
		add(C[part], cnt[part][v], 1);
	}
	rep(i, q) {
		if(queries[i].typ == 1) {
			swap(queries[i].x, queries[i].y);
			queries[i].x --;
			int v = a[queries[i].x];
			for(int j = queries[i].x / B + 1; j <= (n - 1) / B + 1; j ++) {
				cnt[j][v] --;
				add(C[j], cnt[j][v] + 1, -1);
				add(C[j], cnt[j][v], 1);
			}
			a[queries[i].x] = v = ly.get(queries[i].y);
			for(int j = queries[i].x / B + 1; j <= (n - 1) / B + 1; j ++) {
				cnt[j][v] ++;
				add(C[j], cnt[j][v] - 1, -1);
				add(C[j], cnt[j][v], 1);
			}
		} else {
			queries[i].y --;
			int part = queries[i].y / B + 1, v;
			if(queries[i].x == 1) {
				printf("%d\n", ly[a[queries[i].y] - 1]);
				continue;
			}
			int c = 0, s = 0;
			for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
				if(a[j] == a[queries[i].y])
					c ++;
			}
			v = a[queries[i].y];
			c += cnt[part - 1][v];
			if(queries[i].x & 1 ^ 1) {
				printf("%d\n", c);
			} else {
				for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
					v = a[j];
					cnt[part - 1][v] ++;
					if(cnt[part - 1][v] == c) {
						s ++;
					}
				}
				for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
					v = a[j];
					cnt[part - 1][v] --;
				}
				s += query(C[part - 1], length) - query(C[part - 1], c - 1);
				printf("%d\n", s);
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i ++)
const int N = 100000;
const int B = 1000;

int a[N];
int cnt[N / B + 1][N + N + 1];
int C[N / B + 1][N + N + 1];

struct QQ {
	int typ, x, y;
	void Scan() {
		scanf("%d%d%d", &typ, &x, &y);
	}
}queries[N];

struct San: vector<int> {
	void prepare() {
		sort(begin(), end());
		erase(unique(begin(), end()), end());
	}
	int get(int x) const {
		return lower_bound(begin(), end(), x) - begin() + 1;
	}
}ly;

int length;
void add(int *C, int x, int value) {
	if(x == 0)	return;
	for(; x <= length; x += x & -x) {
		C[x] += value;
	}
}
int query(int *C, int x) {
	int ret = 0;
	for(; x; x -= x & -x) {
		ret += C[x];
	}
	return ret;
}
int main() {
	int n, q;
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", a + i);
		ly.push_back(a[i]);
	}
	scanf("%d", &q);
	rep(i, q) {
		queries[i].Scan();
		if(queries[i].typ == 1) {
			ly.push_back(queries[i].y);
		}
	}
	ly.prepare();
	length = ly.size();
	rep(i, n) {
		int part = i / B + 1, v = ly.get(a[i]);
		if(i % B == 0) {
			memcpy(cnt[part], cnt[part - 1], sizeof cnt[part]);
			memcpy(C[part], C[part - 1], sizeof C[part]);
		}
		cnt[part][v] ++;
		add(C[part], cnt[part][v] - 1, -1);
		add(C[part], cnt[part][v], 1);
	}
	rep(i, q) {
		if(queries[i].typ == 1) {
			queries[i].x --;
			int v = ly.get(a[queries[i].x]);
			for(int j = queries[i].x / B + 1; j <= (n - 1) / B + 1; j ++) {
				cnt[j][v] --;
				add(C[j], cnt[j][v] + 1, -1);
				add(C[j], cnt[j][v], 1);
			}
			a[queries[i].x] = queries[i].y;
			v = ly.get(queries[i].y);
			for(int j = queries[i].x / B + 1; j <= (n - 1) / B + 1; j ++) {
				cnt[j][v] ++;
				add(C[j], cnt[j][v] - 1, -1);
				add(C[j], cnt[j][v], 1);
			}
		} else {
			queries[i].y --;
			int part = queries[i].y / B + 1, v;
			if(queries[i].x == 1) {
				printf("%d\n", a[queries[i].y]);
				continue;
			}
			int c = 0, s = 0;
			for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
				if(a[j] == a[queries[i].y])
					c ++;
			}
			v = ly.get(a[queries[i].y]);
			c += cnt[part - 1][v];
			if(queries[i].x & 1 ^ 1) {
				printf("%d\n", c);
			} else {
				for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
					v = ly.get(a[j]);
					cnt[part - 1][v] ++;
					if(cnt[part - 1][v] == c) {
						s ++;
					}
				}
				for(int j = queries[i].y / B * B; j <= queries[i].y; j ++) {
					v = ly.get(a[j]);
					cnt[part - 1][v] --;
				}
				s += query(C[part - 1], length) - query(C[part - 1], c - 1);
				printf("%d\n", s);
			}
		}
	}
	return 0;
}