///....................SUBRATO MOLLICK....................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///........................BETCH-10.......................///
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define REP2(i,n) for(__typeof(n) i=1; i<=(n); i++)
#define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define INF (1<<30)
#define PI 3.14159265358979323846264338327950
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ size()
#define eps 1e-9
#define VI vector<int>
#define VS vector<string>
#define LL long long
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define CLEAR(x) memset(x,0,sizeof(x));
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define all(x) x.begin(),x.end()

/*long long c[201]={0};
bool p[205]={0};
void sieve()
{
   long long i,j;
    j=4;
     while(j<=201)
     {
         p[j]=1;
         j+=2;
     }
     long k=1;
     for(i=3;i<=(201);i+=2)
     {
        if(p[i]==0)
        {
            j=i;
            while(j+i<=201)
            {
                p[j+i]=1;j+=i;
            }
            if(p[i+2]==0)
            c[k++]=i;
        }
    }
}*/
/*long long npr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   ret*=(n-i+1);
   return ret;
}*/
/*long long ncr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   {
       ret*=(n-i+1);
       ret/=i;
   }
   return ret;
}*/
/*long long fact(long n)
{
    long long ret=1,i;
    for(i=1;i<=n;i++)
    ret*=i;
    return ret;
}*/
/*long long gcd(long n,long m)
{
  while(m>0)
  {
    n=n%m;
    n=n^m;
    m=m^n;
    n=n^m;
  }
  return n;
}*/
/*long long lcm(long n,long m)
{
    long long x=(n*m)/gcd(n,m);
    return x;
}*/
/*long is_prime(long n)
{
	long long ii;
	if(n == 1)
	return 0;
	if(n == 2)
	return 1;
	if(n%2 == 0)
	return 0;
	for(ii=3;ii*ii<=n;ii=ii+2)
        if(n%ii == 0)
        return 0;
        return 1;
}*/
/*double area_triangle(double x1,double y1,double x2,double y2,double x3,double y3)
{
    double a;
    a=x1*(y2-y3)+y1*(x3-x2)+((x2*y3)-(y2*x3))+eps;
    a=a/2+eps;
    return a;
}*/
/*double dist_2point(double x1,double y1,double x2,double y2)
{
    double d;
    d=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
    return d;
}*/
/*int binary_search(int a[],int n,int l,int u)
{
	int mid;
	if(l>u)
    return 0;
    mid=floor(l+u)/2;
    if(a[mid]==n)
    return mid;
    else if(a[mid]>n)
    binary_search(a,n,l,mid-1);
    else
    binary_search(a,n,mid+1,u);
}*/
/*bool is_palindrome(const string &s, int start, int end)
{
    int siz=end-start+1;
    if(siz%2==0)
    {
        int middle=start+siz/2;
        int i;
        for(i =0;middle-1-i>=0&&middle+i<=end&&s[middle-1-i]==s[middle+i];i++);
        if(middle-i-1<0||middle+i>end)
        return true;
    }
    else
    {
        int middle = start + siz/2;
        int i;
        for (i=1;middle-i>=0&&middle+i<=end&&s[middle-i]==s[middle+i];i++);
        if (middle-i<0||middle+i>end)
        return true;
    }
    return false;
}*/
int main()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a,flag=0,flag2=0,flag3=0,flag4=0,prev=1000000000;
    mp[1]=1;
    for(i=1;;i++)
    {
        p=p*2;
        mp[p]=1;
        if(p>1000000000000)break;
    }
    cin>>n;
    {
        p=0;
        rep(i,n)
        {
            cin>>a;
            if(mp[a]==0)
            {
                if(flag==0)
                cnt++;
                flag=1;
                flag2=0;
                prev=a;
            }
            else if(mp[a]==1)
            {
                if(prev==a)continue;
                else
                {
                    if(flag2==0)
                    cnt++;
                    flag2=1;
                }
                flag=0;
                prev=a;
            }
        }

        cout<<cnt<<endl;
    }
    return 0;
}


///....................SUBRATO MOLLICK....................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///........................BETCH-10.......................///
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define REP2(i,n) for(__typeof(n) i=1; i<=(n); i++)
#define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define INF (1<<30)
#define PI 3.14159265358979323846264338327950
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ size()
#define eps 1e-9
#define VI vector<int>
#define VS vector<string>
#define LL long long
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define CLEAR(x) memset(x,0,sizeof(x));
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define all(x) x.begin(),x.end()

/*long long c[201]={0};
bool p[205]={0};
void sieve()
{
   long long i,j;
    j=4;
     while(j<=201)
     {
         p[j]=1;
         j+=2;
     }
     long k=1;
     for(i=3;i<=(201);i+=2)
     {
        if(p[i]==0)
        {
            j=i;
            while(j+i<=201)
            {
                p[j+i]=1;j+=i;
            }
            if(p[i+2]==0)
            c[k++]=i;
        }
    }
}*/
/*long long npr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   ret*=(n-i+1);
   return ret;
}*/
/*long long ncr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   {
       ret*=(n-i+1);
       ret/=i;
   }
   return ret;
}*/
/*long long fact(long n)
{
    long long ret=1,i;
    for(i=1;i<=n;i++)
    ret*=i;
    return ret;
}*/
/*long long gcd(long n,long m)
{
  while(m>0)
  {
    n=n%m;
    n=n^m;
    m=m^n;
    n=n^m;
  }
  return n;
}*/
/*long long lcm(long n,long m)
{
    long long x=(n*m)/gcd(n,m);
    return x;
}*/
/*long is_prime(long n)
{
	long long ii;
	if(n == 1)
	return 0;
	if(n == 2)
	return 1;
	if(n%2 == 0)
	return 0;
	for(ii=3;ii*ii<=n;ii=ii+2)
        if(n%ii == 0)
        return 0;
        return 1;
}*/
/*double area_triangle(double x1,double y1,double x2,double y2,double x3,double y3)
{
    double a;
    a=x1*(y2-y3)+y1*(x3-x2)+((x2*y3)-(y2*x3))+eps;
    a=a/2+eps;
    return a;
}*/
/*double dist_2point(double x1,double y1,double x2,double y2)
{
    double d;
    d=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
    return d;
}*/
/*int binary_search(int a[],int n,int l,int u)
{
	int mid;
	if(l>u)
    return 0;
    mid=floor(l+u)/2;
    if(a[mid]==n)
    return mid;
    else if(a[mid]>n)
    binary_search(a,n,l,mid-1);
    else
    binary_search(a,n,mid+1,u);
}*/
/*bool is_palindrome(const string &s, int start, int end)
{
    int siz=end-start+1;
    if(siz%2==0)
    {
        int middle=start+siz/2;
        int i;
        for(i =0;middle-1-i>=0&&middle+i<=end&&s[middle-1-i]==s[middle+i];i++);
        if(middle-i-1<0||middle+i>end)
        return true;
    }
    else
    {
        int middle = start + siz/2;
        int i;
        for (i=1;middle-i>=0&&middle+i<=end&&s[middle-i]==s[middle+i];i++);
        if (middle-i<0||middle+i>end)
        return true;
    }
    return false;
}*/
int main()
{
    long n,ar;
    scanf("%ld",&n);
    priority_queue<long>q;
    long u,v,cnt=0;
    rep(i,n)
    {
        scanf("%ld",&ar);
        ar=ar*(-1);
        q.push(ar);
    }
    while(q.size()>1)
    {
        u=q.top();q.pop();
        v=q.top();q.pop();
        //cout<<u<<" "<<v<<endl;
        if(u==v)q.push((u-1));
        else
        {
            cnt++;
            q.push(v);
        }
    }
    if(q.size()>0)cnt++;
    printf("%ld\n",cnt);
    return 0;
}


///....................SUBRATO MOLLICK....................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///........................BETCH-10.......................///
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define REP2(i,n) for(__typeof(n) i=1; i<=(n); i++)
#define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define INF (1<<30)
#define PI 3.14159265358979323846264338327950
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ size()
#define eps 1e-9
#define VI vector<int>
#define VS vector<string>
#define LL long long
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define CLEAR(x) memset(x,0,sizeof(x));
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define all(x) x.begin(),x.end()

/*long long c[201]={0};
bool p[205]={0};
void sieve()
{
   long long i,j;
    j=4;
     while(j<=201)
     {
         p[j]=1;
         j+=2;
     }
     long k=1;
     for(i=3;i<=(201);i+=2)
     {
        if(p[i]==0)
        {
            j=i;
            while(j+i<=201)
            {
                p[j+i]=1;j+=i;
            }
            if(p[i+2]==0)
            c[k++]=i;
        }
    }
}*/
/*long long npr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   ret*=(n-i+1);
   return ret;
}*/
/*long long ncr(long n,long m)
{
   long long ret=1,i;
   for(i=1;i<=m;i++)
   {
       ret*=(n-i+1);
       ret/=i;
   }
   return ret;
}*/
/*long long fact(long n)
{
    long long ret=1,i;
    for(i=1;i<=n;i++)
    ret*=i;
    return ret;
}*/
/*long long gcd(long n,long m)
{
  while(m>0)
  {
    n=n%m;
    n=n^m;
    m=m^n;
    n=n^m;
  }
  return n;
}*/
/*long long lcm(long n,long m)
{
    long long x=(n*m)/gcd(n,m);
    return x;
}*/
/*long is_prime(long n)
{
	long long ii;
	if(n == 1)
	return 0;
	if(n == 2)
	return 1;
	if(n%2 == 0)
	return 0;
	for(ii=3;ii*ii<=n;ii=ii+2)
        if(n%ii == 0)
        return 0;
        return 1;
}*/
/*double area_triangle(double x1,double y1,double x2,double y2,double x3,double y3)
{
    double a;
    a=x1*(y2-y3)+y1*(x3-x2)+((x2*y3)-(y2*x3))+eps;
    a=a/2+eps;
    return a;
}*/
/*double dist_2point(double x1,double y1,double x2,double y2)
{
    double d;
    d=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
    return d;
}*/
/*int binary_search(int a[],int n,int l,int u)
{
	int mid;
	if(l>u)
    return 0;
    mid=floor(l+u)/2;
    if(a[mid]==n)
    return mid;
    else if(a[mid]>n)
    binary_search(a,n,l,mid-1);
    else
    binary_search(a,n,mid+1,u);
}*/
/*bool is_palindrome(const string &s, int start, int end)
{
    int siz=end-start+1;
    if(siz%2==0)
    {
        int middle=start+siz/2;
        int i;
        for(i =0;middle-1-i>=0&&middle+i<=end&&s[middle-1-i]==s[middle+i];i++);
        if(middle-i-1<0||middle+i>end)
        return true;
    }
    else
    {
        int middle = start + siz/2;
        int i;
        for (i=1;middle-i>=0&&middle+i<=end&&s[middle-i]==s[middle+i];i++);
        if (middle-i<0||middle+i>end)
        return true;
    }
    return false;
}*/
long a[1000006];
int main()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,flag=0,flag2=0;
    mp[1]=1;
    for(i=1;;i++)
    {
        p=p*2;
        mp[p]=1;
        if(p>1000000000000)break;
    }
    cin>>n;
    {
        p=0;
        rep(i,n)
        {
            cin>>a[i];
            if(mp[a[i]]==0)
            {
                if(flag==0)
                cnt++;
                flag=1;
                flag2=0;
            }
            else if(mp[a[i]]==1)
            {
                if(i>0)
                if(a[i-1]==a[i])continue;
                if(i>1)
                if(a[i-1]==1&&a[i-2]==1&&a[i]==2)continue;
                cnt++;
                flag=0;
            }
            //cout<<cnt<<endl;

        }

        cout<<cnt<<endl;
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

#define BUF 1048576
//#define BUF 262144
//#define BUF 65536

#define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
typedef long long lld;

class SignedReader
{
	char arr[BUF];
	char *p, *e;
	int s, val;
	bool neg;

	void getTok()
	{
		p = arr;
		s = fread(arr, 1, BUF, stdin);
		e = arr + s;
	}

	void skip()
	{
		while (true)
		{
			if (p == e)
				getTok();
			if (*p == '-' || ISDIGIT(*p))
				return;
			p++;
		}
	}
public:

	SignedReader()
	{
		getTok();
	}

	int nextInt()
	{
		neg = false;
		skip();
		if (*p == '-')
			neg = true, p++;
		val = 0;
		while (true)
		{
			if (p == e)
				getTok();
			if (p == e)
				break;
			if (ISDIGIT(*p))
				val = 10 * val + *p - 48, p++;
			else
				break;
		}
		if (neg)
			val = -val;
		return val;
	}

	lld nextLong()
	{
		lld value;
		neg = false;
		skip();
		if (*p == '-')
			neg = true, p++;
		value = 0;
		while (true)
		{
			if (p == e)
				getTok();
			if (p == e)
				break;
			if (ISDIGIT(*p))
				value = 10 * value + *p - 48, p++;
			else
				break;
		}
		if (neg)
			value = -value;
		return value;
	}
};

#define MAX 1000200

int arr[MAX];

int main()
{
	SignedReader in;

	int n = in.nextInt();

	int v, maxm = -1;

	for (int i = 0; i < n; i++)
	{
		v = in.nextInt();
		arr[v]++;
		maxm = max(maxm, v);
	}

	int moves = 0;

	for (int i = 0; i <= maxm; i++)
	{
		if (arr[i] >= 2)
		{
			maxm = max(maxm, i + 1);
			arr[i + 1] += arr[i] / 2;
			arr[i] -= (arr[i] / 2) * 2;
		}
		if (arr[i] == 1)
			moves++;
	}

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

	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

#define INF (1 << 29)
#define MAX 1000005
typedef long long lld;

int main()
{
	priority_queue<int> pq;

	int n;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int w;
		cin >> w;
		pq.push(-w);
	}

	int moves = 1;

	while (pq.size() >= 2)
	{
		int t1 = -pq.top();
		pq.pop();
		int t2 = -pq.top();
		pq.pop();

		if (t1 == t2)
			pq.push(-t1 - 1);
		else
		{
			pq.push(-t2);
			moves++;
		}
	}

	cout << moves << "\n";

	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

#define INF (1 << 29)
#define MAX 1000005
typedef long long lld;

int main()
{
	priority_queue<int> pq;

	int n;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int w;
		cin >> w;
		pq.push(-w);
	}

	int moves = 1;

	while (pq.size() >= 2)
	{
		int t1 = -pq.top();
		pq.pop();
		int t2 = -pq.top();
//		pq.pop();

		if (t1 == t2)
		{
			pq.pop();
			pq.push(-t1 - 1);
		}
		else
			moves++;
	}

	cout << moves << "\n";

	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

#define INF (1 << 29)
#define MAX 1000005
typedef long long lld;

vector<lld> arr;

int main()
{
	priority_queue<int> pq;

	int n;

	cin >> n;

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

	sort(arr.begin(), arr.end());

	int moves = 1;
	lld onHand = arr[0];

	for (int i = 1; i < arr.size(); i++)
	{
		if (onHand == arr[i])
			onHand = arr[i] + 1;
		else
		{
			onHand = max(onHand, arr[i]);
			moves++;
		}
	}

	cout << moves << "\n";

	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

//#define BUF 1048576
#define BUF 262144
//#define BUF 65536

#define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
typedef long long lld;

class SignedReader
{
	char arr[BUF];
	char *p, *e;
	int s, val;
	bool neg;

	void getTok()
	{
		p = arr;
		s = fread(arr, 1, BUF, stdin);
		e = arr + s;
	}

	void skip()
	{
		while (true)
		{
			if (p == e)
				getTok();
			if (*p == '-' || ISDIGIT(*p))
				return;
			p++;
		}
	}
public:

	SignedReader()
	{
		getTok();
	}

	int nextInt()
	{
		neg = false;
		skip();
		if (*p == '-')
			neg = true, p++;
		val = 0;
		while (true)
		{
			if (p == e)
				getTok();
			if (p == e)
				break;
			if (ISDIGIT(*p))
				val = 10 * val + *p - 48, p++;
			else
				break;
		}
		if (neg)
			val = -val;
		return val;
	}

	lld nextLong()
	{
		lld value;
		neg = false;
		skip();
		if (*p == '-')
			neg = true, p++;
		value = 0;
		while (true)
		{
			if (p == e)
				getTok();
			if (p == e)
				break;
			if (ISDIGIT(*p))
				value = 10 * value + *p - 48, p++;
			else
				break;
		}
		if (neg)
			value = -value;
		return value;
	}
};

#define MAX 1000200

int arr[MAX];

int main()
{
	SignedReader in;

	int n = in.nextInt();

	int v, maxm = -1;

	for (int i = 0; i < n; i++)
	{
		v = in.nextInt();
		arr[v]++;
		maxm = max(maxm, v);
	}

	int moves = 0;

	for (int i = 0; i <= maxm; i++)
	{
		if (arr[i] >= 2)
		{
			maxm = max(maxm, i + 1);
			arr[i + 1] += arr[i] / 2;
			arr[i] -= (arr[i] / 2) * 2;
		}
		if (arr[i] == 1)
			moves++;
	}

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

	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

#define INF (1 << 29)
#define MAX 1000005
typedef long long lld;

int main()
{
	priority_queue<int> pq;

	int n;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int w;
		cin >> w;
		pq.push(-w);
	}

	int moves = 1;

	while (pq.size() >= 2)
	{
		int t1 = -pq.top();
		pq.pop();
		int t2 = -pq.top();
		pq.pop();

		if (t1 == t2)
			pq.push(-t1 - 1);
		else
		{
			pq.push(t2);
			moves++;
		}
	}

	cout << moves << "\n";

	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

#define INF (1 << 29)
#define MAX 1000005
typedef long long lld;

int main()
{
	priority_queue<int> pq;

	int n, w;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &w);
		pq.push(-w);
	}

	int moves = 1;

	while (pq.size() >= 2)
	{
		int t1 = -pq.top();
		pq.pop();
		int t2 = -pq.top();

		if (t1 == t2)
		{
			pq.pop();
			pq.push(-t1 - 1);
		}
		else
			moves++;
	}

	cout << moves << "\n";

	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

#define INF (1 << 29)
#define MAX 1000005
typedef long long lld;

vector<lld> arr;

int main()
{
	priority_queue<int> pq;

	int n;

	cin >> n;

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

	sort(arr.begin(), arr.end());

	int moves = 1;
	priority_queue<lld> coll;
	coll.push(-arr[0]);

	int v;

	for (int i = 1; i < arr.size(); i++)
	{
		while (!coll.empty() && -coll.top() < arr[i])
			coll.pop();

		if (!coll.empty() && (v = -coll.top()) == arr[i])
		{
			coll.pop();
			coll.push(-v - 1);
		}
		else
		{
			coll.push(-arr[i]);
			moves++;
		}
	}

	cout << moves << "\n";

	return 0;
}


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

int n, a[1000001], f[1001001];

int main() {
    ios::sync_with_stdio(0);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        f[a[i]]++;
    }
    int ans = 0;
    for (int i = 0; i <= 1e6 + 1e3; ++i) {
        f[i + 1] += f[i] / 2;
        f[i] %= 2;
        ans += (f[i] != 0);
    }
    printf("%d", ans);
    return 0;
}


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

int n, a[1000001], d[1000001];

int main() {
    ios::sync_with_stdio(0);
    cin >> n;
    priority_queue<int> heap;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        heap.push(a[i]);
    }
    sort(a, a + n);
    int ans = 1;
    for (int i = 1; i < n; ++i) {
        if (a[i] == a[i - 1]) {
            a[i] += a[i - 1];
        } else
            ans++;
    }
    cout << ans;
    return 0;
}


/*
Author : lifecodemohit
*/

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define MOD 			1000000007
#define ll 				long long

int cnt[1001010];

int main()
{
	int n;
	scanf("%d", &n);
	int a;
	for (int i = 0; i <= 1001005; i++)
		cnt[i] = 0;

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

	ll res = 0;
	for (int i = 0; i <= 1001005; i++) {
			res = res + (cnt[i]&1);
			cnt[i+1] = cnt[i+1] + cnt[i]/2;
	}
	printf("%I64d\n",res);
	return 0;
}


/*
Author : lifecodemohit
*/

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define MOD 			1000000007
#define ll 				long long

int cnt[1000010];

int main()
{
	int n;
	scanf("%d", &n);
	int a;
	for (int i = 0; i <= 1000005; i++)
		cnt[i] = 0;

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

	ll res = 0;
	for (int i = 0; i <= 1000005; i++) {
			res = res + (cnt[i]&1);
			cnt[i+1] = cnt[i+1] + cnt[i]/2;
	}
	printf("%I64d\n",res);
	return 0;
}


/*
Author : lifecodemohit
*/

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define MOD 			1000000007
#define ll 				long long

int cnt[1000010];

int main()
{
	int n;
	scanf("%d", &n);
	int a;
	for (int i = 0; i <= 1000005; i++)
		cnt[i] = 0;

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

	ll res = 0;
	for (int i = 0; i <= 1000005; i++) {
			res = res + (cnt[i]&1);
			cnt[i+1] = cnt[i+1] + cnt[i]/2;
	}
	printf("%I64d\n",res);
	return 0;
}


/*
Author : lifecodemohit
*/

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define MOD 			1000000007
#define ll 				long long

ll cnt[4000010];

int main()
{
	ll n;
	cin >> n;
	ll a;
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0;i < n; i++) {
		cin >> a;
		cnt[a]++;
	}
	ll res = 0;
	for (int i = 0; i <= 4000000; i++) {
			res = res + (cnt[i]%2);
			cnt[i+1] = cnt[i+1] + cnt[i]/2;
	}
	cout << res << endl;
	return 0;
}


/*
Author : lifecodemohit
*/

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define MOD 			1000000007
#define ll 				long long

ll cnt[1000010];

int main()
{
	ll n;
	cin >> n;
	ll a;
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0;i < n; i++) {
		cin >> a;
		cnt[a]++;
	}
	ll res = 0;
	for (int i = 0; i <= 1000005; i++) {
			res = res + (cnt[i]%2);
			cnt[i+1] = cnt[i+1] + cnt[i]/2;
	}
	cout << res << endl;
	return 0;
}


/*
Author : lifecodemohit
*/

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define MOD 			1000000007
#define ll 				long long

ll cnt[4000010];

int main()
{
	ll n;
	cin >> n;
	ll a;
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0;i < n; i++) {
		cin >> a;
		cnt[a]++;
	}
	ll res = 0;
	for (int i = 0; i <= 4000000; i++) {
		if (cnt[i] < 2)
			res = res + cnt[i];
		else if (cnt[i] > 0) {
			ll x = log2(cnt[i]);
			ll y = cnt[i] - (ll)pow(2, x);
			res = res + y;
			cnt[i + x]++;
		}
	}
	cout << res << endl;
	return 0;
}


/*
Author : lifecodemohit
*/

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define MOD 			1000000007
#define ll 				long long

ll cnt[4000010];

int main()
{
	ll n;
	cin >> n;
	ll a;
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0;i < n; i++) {
		cin >> a;
		cnt[a]++;
	}
	ll res = 0;
	for (int i = 0; i <= 4000000; i++) {
		if (cnt[i] < 2)
			res = res + cnt[i];
		else if (cnt[i] > 0) {
			ll x = log2(cnt[i]);
			ll y = cnt[i] - (ll)pow(2, x);
			if (y > 0) {
				res = res + 1;
			}
			cnt[i+x]++;
		}
	}
	cout << res << endl;
	return 0;
}


/*
Author : lifecodemohit
*/

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define MOD 			1000000007
#define ll 				long long

ll cnt[1000010];

int main()
{
	ll n;
	cin >> n;
	ll a;
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0;i < n; i++) {
		cin >> a;
		cnt[a]++;
	}
	ll res = 0;
	for (int i = 0; i <= 1000000; i++) {
		if (cnt[i] < 2)
			res = res + cnt[i];
		else if (cnt[i] > 0) {
			ll x = log2(cnt[i]);
			ll y = cnt[i] - (ll)pow(2, x);
			res = res + y;
			cnt[i + x]++;
		}
	}
	cout << res << endl;
	return 0;
}


/*
Author : lifecodemohit
*/

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define MOD 			1000000007
#define ll 				long long

int cnt[1000010];

int main()
{
	int n;
	cin >> n;
	int a;
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0;i < n; i++) {
		cin >> a;
		cnt[a] += 1;
	}
	ll res = 0;
	for (int i = 0; i <= 1000005; i++) {
			res = res + (cnt[i]%2);
			cnt[i+1] = cnt[i+1] + cnt[i]/2;
	}
	cout << res << endl;
	return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int n, a[1000013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    sort (a, a + n);

    int cursum = a[0], ans = n;

    for (int i = 1; i < n; i++) {
        if (cursum == a[i]) {
            ans--;
            cursum += a[i];
        } else {
            cursum = a[i];
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int n;
long long a[10100013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    int ans = 0;
    for (int i = 0; i < 1000102; i++) {
        if (a[i] == 0) {
            continue;
        }

        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            if (a[i] & 1) {
                a[i]--;
                ans++;
            }
            a[i + 1] += (a[i] / 2);
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 1000000000 + 13

using namespace std;

const double EPS = 1E-9;

int n;
int a[10100013];

int main()
{
//  freopen("in", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    scanf("%d", &n);

    int x;
    int minx = -1, maxx = -1;
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        a[x]++;
        if (minx == -1 || minx < x) minx = x;
    }

    int ans = 0;

    for (int i = minx; i < 1010002; i++) {
        if (a[i] == 0) {
            continue;
        }
        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            if (a[i] & 1) {
                a[i]--;
                ans++;
            }
            a[i + 1] += (a[i] >> 1);
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 1000000000 + 13

using namespace std;

const double EPS = 1E-9;

int n;
int a[10100013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    int ans = 0;
    for (int i = 0; i < 1000102; i++) {
        if (a[i] == 0) {
            continue;
        }

        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            if (a[i] & 1) {
                a[i]--;
                ans++;
            }
            a[i + 1] += (a[i] >> 1);
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int n;
long long a[1010013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    int ans = 0;
    for (int i = 0; i < 1000102; i++) {
        if (a[i] == 0) {
            continue;
        }

        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            if (a[i] & 1) {
                a[i]--;
                ans++;
            }
            a[i + 1] += (a[i] / 2ll);
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int n, a[1000013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    int ans = 0;
    for (int i = 0; i < 1000010; i++) {
        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            while(a[i] > 1) {
                x = a[i] / 2;
                a[i + 1] += x;
                a[i] -= 2 * x;
            }
            if (a[i] == 1) ans++;
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 1000000000 + 13

using namespace std;

const double EPS = 1E-9;

int n;
int a[10100013];

int main()
{
    freopen("in", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    scanf("%d", &n);

    int x;
    int minx = -1, maxx = -1;
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        a[x]++;
        if (minx == -1 || minx < x) minx = x;
    }

    int ans = 0;

    for (int i = minx; i < 1010002; i++) {
        if (a[i] == 0) {
            continue;
        }
        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            if (a[i] & 1) {
                a[i]--;
                ans++;
            }
            a[i + 1] += (a[i] >> 1);
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int n, a[1000013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    int ans = 0;
    for (int i = 0; i < 1000010; i++) {
        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            while(a[i] > 1) {
                a[i] -= 2;
                a[i + 1]++;
            }
            if (a[i] == 1) ans++;
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 1000000000 + 13

using namespace std;

const double EPS = 1E-9;

int n;
int a[10100013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    int ans = 0;
    for (int i = 0; i < 10000102; i++) {
        if (a[i] == 0) {
            continue;
        }

        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            if (a[i] & 1) {
                a[i]--;
                ans++;
            }
            a[i + 1] += (a[i] >> 1);
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 1000000000 + 13

using namespace std;

const double EPS = 1E-9;

int n;
int a[10100013];

int main()
{
//  freopen("in", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    scanf("%d", &n);

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

    int ans = 0;

    for (int i = 0; i < 1010002; i++) {
        if (a[i] == 0) {
            continue;
        }
        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            if (a[i] & 1) {
                a[i]--;
                ans++;
            }
            a[i + 1] += (a[i] >> 1);
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int n;
long long a[1010013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    int ans = 0;
    for (int i = 0; i < 1000002; i++) {
        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            if (a[i] & 1) {
                a[i]--;
                ans++;
            }
            a[i + 1] += (a[i] / 2ll);
            a[i] -= (2ll * (a[i] / 2ll));
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int n, a[1000013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    int ans = 0;
    for (int i = 0; i < 1000010; i++) {
        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            x = a[i] / 2;
            a[i] -= 2 * x;
            a[i + 1] += x;
            if (a[i] == 1) {
                ans++;
            }
        }
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 1000000000 + 13

using namespace std;

const double EPS = 1E-9;

int n;
long long a[10100013];

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
//  cout << "Hello world";

    cin >> n;

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

    int ans = 0;
    for (int i = 0; i < 1000102; i++) {
        if (a[i] == 0) {
            continue;
        }

        assert(a[i] < INF);

        if (a[i] == 1) {
            ans++;
        } else if (a[i] > 1) {
            if (a[i] & 1) {
                a[i]--;
                ans++;
            }
            a[i + 1] += (a[i] / 2);
        }
    }

    cout << ans;

    return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

int w[1000006];

int main()
{
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		cin >> tmp;
		w[tmp]++;
		m = max(tmp,m);
	}
	m++;
	LL ans = 0;
	F(i,m-1)
	{
		if (i<m && w[i] == 0)
			continue;
		// while (w[i] != 0)
		// {
			if (w[i]%2)
				ans++;
			w[i+1] += w[i]/2;
			// i++;
		// }
	}
	ans += __builtin_popcount(w[m-1]);
	cout << ans;
	return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

int w[1000506];

int main()
{
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		scanf("%d", &tmp);
		w[tmp]++;
		m = max(tmp,m);
	}
	LL ans = 0;
	F(i,1000500)
	{
		if (w[i] == 0)
			continue;
		if (w[i]%2)
			ans++;
		w[i+1] += w[i]/2;
	}
	printf("%lld\n", ans);;
	return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

int w[1000506];

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		cin >> tmp;
		w[tmp]++;
		m = max(tmp,m);
	}
	LL ans = 0;
	F(i,1000500)
	{
		if (w[i] == 0)
			continue;
		if (w[i]%2)
			ans++;
		w[i+1] += w[i]/2;
	}
	cout << ans;
	return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

int w[1000506];

int main()
{
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		cin >> tmp;
		w[tmp]++;
		m = max(tmp,m);
	}
	m++;
	// sort(w,w+m);
	LL ans = 0;
	LL check = 0;
	F(i,m-1)
	{
		while (i<m && w[i] == 0)
			i++;
		// while (w[i] != 0)
		// {
			if (w[i]%2)
				ans++;
			w[i+1] += w[i]/2;
			// i++;
		// }
	}
	ans += __builtin_popcount(w[m-1]);
	cout << ans;
	return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

int w[1000006];

int main()
{
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		cin >> tmp;
		w[tmp]++;
		m = max(tmp,m);
	}
	m++;
	// sort(w,w+m);
	LL ans = 0;
	LL check = 0;
	F(i,m)
	{
		while (i<m && w[i] == 0)
			i++;
		while (w[i] != 0)
		{
			if (w[i]%2)
				ans++;
			w[i+1] += w[i]/2;
			i++;
		}
	}
	cout << ans;
	return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

int w[1000006];

int main()
{
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		cin >> tmp;
		w[tmp]++;
		m = max(tmp,m);
	}
	m++;
	LL ans = 0;
	F(i,m)
	{
		if (i<m && w[i] == 0)
			continue;
		while (w[i] != 0)
		{
			if (w[i]%2)
				ans++;
			w[i+1] += w[i]/2;
			i++;
		}
	}
	cout << ans;
	return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

int w[1000506];

int main()
{
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		cin >> tmp;
		w[tmp]++;
		m = max(tmp,m);
	}
	LL ans = 0;
	F(i,1000500)
	{
		if (w[i] == 0)
			continue;
		if (w[i]%2)
			ans++;
		w[i+1] += w[i]/2;
	}
	ans += __builtin_popcount(w[m]);
	cout << ans;
	return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

int w[1000506];

int main()
{
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		cin >> tmp;
		w[tmp]++;
		m = max(tmp,m);
	}
	LL ans = 0;
	F(i,1000500)
	{
		if (w[i] == 0)
			continue;
		if (w[i]%2)
			ans++;
		w[i+1] += w[i]/2;
	}
	// ans += __builtin_popcount(w[m]);
	cout << ans;
	return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

int w[1000506];

int main()
{
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		cin >> tmp;
		w[tmp]++;
		m = max(tmp,m);
	}
	LL ans = 0;
	F(i,m)
	{
		while (i<m && w[i] == 0)
			i++;
		if (w[i]%2)
			ans++;
		w[i+1] += w[i]/2;
	}
	ans += __builtin_popcount(w[m]);
	cout << ans;
	return 0;
}


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

#define R(i,a,b) for(int i=a;i<b;i++)
#define RE(i,a,b) for(int i=a;i<=b;i++)
#define RR(i,a,b) for(int i=a;i>b;i--)
#define RRE(i,a,b) for(int i=a;i>=b;i--)
#define F(i,n) for(int i=0;i<n;i++)
#define FE(i,n) for(int i=0;i<=n;i++)
#define FR(i,n) for(int i=n;i>0;i--)
#define FRE(i,n) for(int i=n;i>=0;i--)
#define mp(a,b) make_pair(a,b)
#define pii pair <int, int>
#define pb push_back
#define ft first
#define sd second
#define LL long long
#define gc getchar_unlocked
#define pc putchar_unlocked

inline void get(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int w[1000006];

int main()
{
	int n;
	cin >> n;
	int tmp;
	int m = -1;
	F(i,n)
	{
		cin >> tmp;
		w[tmp]++;
		m = max(tmp,m);
	}
	m++;
	// sort(w,w+m);
	LL ans = 0;
	LL check = 0;
	F(i,m)
	{
		while (i<m && w[i] == 0)
			i++;
		while (w[i] != 0)
		{
			if (w[i]%2)
				ans++;
			w[i+1] += w[i]/2;
			i++;
		}
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <queue>
#include <cmath>
using namespace std;

int main()
{
	int n;
	cin>>n;
	//priority_queue<int> q;
	int ans=0;
	int w[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>w[i];
	}
	for (int i = 0; i < n-1; ++i)
	{
		if (w[i]==w[i+1]){
			w[i+1]++;
		}
		else {
			ans++;
			if (i==n-2)ans++;
		}
	}
	/*while (!q.empty()){
		m=q.top();
		q.pop();
		if (!q.empty() && m==q.top()){
			q.pop();
			q.push((-1*m+1)*-1);
		}
		else {
			ans++;
		}
	}*/
	cout<<ans<<endl;
	return 0;
}


#include <iostream>

using namespace std;
int times[1000300];
int main()
{
	int n;
	cin>>n;
	int k;
	int ans=0;
	int ma=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>k;
		times[k]++;
		ma=max(ma,k);
	}
	for (int i = 0; i <= ma; ++i)
	{
		times[i+1]+=times[i]/2;
		if (i==ma && times[i]/2>0)ma++;
		if (times[i]%2)ans++;
	}

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


#include <iostream>
#include <queue>
#include <cmath>
using namespace std;

int main()
{
	int n;
	cin>>n;
	priority_queue<int> q;
	int ans=0;
	int w[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>w[i];
		q.push(w[i]);
	}
	/*for (int i = 0; i < n-1; ++i)
	{
		if (w[i]==w[i+1]){
			w[i+1]++;
		}
		else {
			ans++;
			if (i==n-2)ans++;
		}
	}*/
	int m;
	while (!q.empty()){
		m=q.top();
		q.pop();
		if (!q.empty() && m==q.top()){
			q.pop();
			q.push((-1*m+1)*-1);
		}
		else {
			ans++;
		}

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


#include <iostream>

using namespace std;
int times[1000005];
int main()
{
	int n;
	cin>>n;
	int k;
	int ans=0;
	int ma=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>k;
		times[k]++;
		ma=max(ma,k);
	}
	for (int i = 0; i <= ma; ++i)
	{
		times[i+1]+=times[i]/2;

		if (times[i]%2)ans++;
	}

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


#include <iostream>
#include <queue>
#include <cmath>
using namespace std;

int main()
{
	int n;
	cin>>n;
	priority_queue<int> q;
	int k;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>k;
		q.push(-1*k);
	}
	int m;
	while (!q.empty()){
		m=q.top();
		q.pop();
		if (!q.empty() && m==q.top()){
			q.pop();
			q.push((-1*m+1)*-1);
		}
		else {
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <queue>
#include <cmath>
using namespace std;
int times[1000005];
int main()
{
	int n;
	cin>>n;
	int k;
	int ans=n;
	for (int i = 0; i < n; ++i)
	{
		cin>>k;
		times[k]++;
		while (times[k]>1){
			times[k]-=2;
			times[k+1]++;
			ans--;
			k=k+1;
		}
	}

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


#include <iostream>
#include <queue>
using namespace std;
int times[1000300];
priority_queue<int> q;
int main()
{
	int n;
	cin>>n;
	int k;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>k;
		times[k]++;
		if(times[k]==1){q.push(-1*k);}
	}
	int z;
	while (!q.empty())
	{
		z=-1*q.top();
		if (times[z]>1){
			if (times[z+1]==0)q.push(-1*(z+1));
			times[z+1]+=times[z]/2;

		}
		if (times[z]%2)ans++;
		q.pop();
	}

	cout<<ans<<endl;
	//cin>>n;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int times[1000300];
priority_queue<int> q;
int main()
{
	int n;
	scanf("%d",&n);
	int k;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&k);
		times[k]++;
		if(times[k]==1){q.push(-1*k);}
	}
	int z;
	while (!q.empty())
	{
		z=-1*q.top();
		if (times[z]>1){
			if (times[z+1]==0)q.push(-1*(z+1));
			times[z+1]+=times[z]/2;

		}
		if (times[z]%2)ans++;
		q.pop();
	}

	cout<<ans<<endl;
	//cin>>n;
	return 0;
}


#include <iostream>

using namespace std;
int times[1000005];
int main()
{
	int n;
	cin>>n;
	int k;
	int ans=0;
	int ma=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>k;
		times[k]++;
		ma=max(ma,k);
	}
	for (int i = 0; i <= ma; ++i)
	{
		times[i+1]+=times[i]/2;
		if (i==ma && times[i]/2>0)ma++;
		if (times[i]%2)ans++;
	}

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


#include <bits/stdc++.h>

using namespace std;
const int N = 3000;

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
int a[N];
struct contest
{
    int M;
    int D;
    int P;
    int T;
    bool const operator <(const contest &c) const
    {
        return M < c.M || (M == c.M && D < c.D) || (M == c.M && D == c.D && T < c.T);
    }
};
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int arr[16] = {30, 31 , 30, 31, 31, 28, 31, 30, 31, 30, 31 , 31 , 30, 31 , 30, 31};
    vector < contest > v;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int m, d, p, t;
        cin >> m >> d >> p >> t;
        v.push_back(contest {m,d,p,t});
    }
    sort(v.begin(), v.end());
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        int m = v[i].M, d = v[i].D, t = v[i].T, p = v[i].P;
        int actual = d + 101 ;
        for (int j = 4; j < m + 3; j++)
            actual += arr[j];

        int ihave = 0;
        for (int j = actual - 1; j >= 1; j--)
        {
            ihave += a[j];
            if (a[j]){
                if (ihave + a[j] < p){
                    a[j] = 0;
                }else
                    a[j] = (p - ihave);
                ihave += a[j];
                if (ihave >= p)
                    break;
            }
        }
        int add = 0;
        if (ihave < p)
            res += (p - ihave),add += p - ihave ;

        a[actual] += add;
    }
    cout << res;
}
/*
CDBABC
ADCABD
*/


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    int months[12] = {1, 32, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};

    map <int, int> starts, ends;

    int n; cin >> n;
    int m, d, p, t;

    FILE *fp;
    fp = fopen("input.txt", "r");
    fscanf(fp, "%d", &n);

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

        fscanf(fp, "%d %d %d %d", &m, &d, &p, &t);
        // cin >> m >> d >> p >> t;

        date = months[m-1] + d - 1;
        ends[date] += p;

        date -= t;
        starts[date] += p;
    }

    int total = 0;
    int idle = 0;

    map <int, int> :: iterator startitr = starts.begin();
    map <int, int> :: iterator enditr = ends.begin();

    int currday = startitr->first;

    while (startitr != starts.end()) {

        while (enditr != ends.end() && currday >= enditr->first) {
            idle += enditr->second;
            enditr++;
        }

        if (idle < startitr->second) {
            total += startitr->second - idle;
            idle = 0;
        } else {
            idle -= startitr->second;
        }

        startitr++;
        currday = startitr->first;
    }

    fclose(fp);
    fp = fopen("output.txt", "w");
    fprintf(fp, "%d\n", total);
    fclose(fp);
    return 0;

    // cout << total << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    int months[12] = {1, 32, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};

    map <int, int> starts, ends;

    int n; cin >> n;
    int m, d, p, t;

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

        cin >> m >> d >> p >> t;

        date = months[m-1] + d - 1;
        ends[date] += p;

        date -= t;
        starts[date] += p;
    }

    int total = 0;
    int idle = 0;

    map <int, int> :: iterator startitr = starts.begin();
    map <int, int> :: iterator enditr = ends.begin();

    int currday = startitr->first;

    while (startitr != starts.end()) {

        while (enditr != ends.end() && currday >= enditr->first) {
            idle += enditr->second;
            enditr++;
        }

        if (idle < startitr->second) {
            total += startitr->second - idle;
            idle = 0;
        } else {
            idle -= startitr->second;
        }

        startitr++;
        currday = startitr->first;
    }

    cout << total << endl;

}


#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<queue>
#include<stack>
#include<string>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cstring>
#include<sstream>
#include<fstream>

using namespace std;

map<int,int>  days_of_month = {{1,31},{2,28},{3,31},{4,30},{5,31},{6,30},{7,31},{8,31},{9,30},{10,31},{11,30},{12,31},{0,100}};

int f(int m,int d){
  int ans;
  for(int i=1;i<m;i++){
    ans+=days_of_month[i];

  }
  ans+=d;
  return ans;
}
int main(){
  cin.sync_with_stdio(false);

  ifstream in;
  in.open("input.txt",ios::in);
  ofstream out;
  out.open("output.txt", ios::out);

  int n,m,t,d,p;
  in>>n;
  map<int,int> sz;
  for(int i=0;i<n;i++){
    in>>m>>d>>p>>t;
    int day_of_year = f(m,d);
    while(t>0){
      sz[day_of_year - t]+=p;
      t--;
    }
  }
  int ans = 0;
  for(auto it=sz.begin();it!=sz.end();it++){
    ans=max(ans,it->second);
  }
  out<<ans;

  return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<queue>

#include<stack>
#include<string>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cstring>
#include<sstream>

using namespace std;

map<int,int>  days_of_month = {{1,31},{2,28},{3,31},{4,30},{5,31},{6,30},{7,31},{8,31},{9,30},{10,31},{11,30},{12,31},{0,100}};

int f(int m,int d){
  int ans;
  for(int i=1;i<m;i++){
    ans+=days_of_month[i];

  }
  ans+=d;
  return ans;
}
int main(){
  cin.sync_with_stdio(false);

  int n,m,t,d,p;
  cin>>n;
  map<int,int> sz;
  for(int i=0;i<n;i++){
    cin>>m>>d>>p>>t;
    int day_of_year = f(m,d);
    while(t>0){
      sz[day_of_year - t]+=p;
      t--;
    }
  }
  int ans = 0;
  for(auto it=sz.begin();it!=sz.end();it++){
    ans=max(ans,it->second);
  }
  cout<<ans;

  return 0;
}


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

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define P(a,n) for(int i=a;i<=n;i++) cout<<a[i]<<" ";
#define bp(n) __builtin_popcount(n);
#define D 1000000007
#define pb push_back
#define ci(x) cin>>x;
#define c2(x,y) cin>>x>>y;
#define c3(x,y,z) cin>>x>>y>>z;
#define p2(x,y) cout<<x<<" "<<y<<endl;
#define p3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define co(x) cout<<x<<endl;
#define r0 return 0;
#define r1 return 1;
#define fi first
#define se second
#define mp make_pair

typedef vector<int> VI;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> VII;
typedef vector<ll> VL;
typedef vector<pll> VLL;
ll tpp = 9e18; int tp = 1e9;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,a[13],m,d,p,t,day,mx;
int Q[500]={0};
int main()
{
	_
	ci(n);
	a[1]=31;a[2]=28;a[3]=31;a[4]=30;a[5]=31;a[6]=30;
	a[7]=31;a[8]=31;a[9]=30;a[10]=31;a[11]=30;a[12]=31;
	for(int i=2;i<=12;i++)
		a[i] += a[i-1];
	a[0]=0;
	while(n--)
	{
		cin>>m>>d>>p>>t;
		day = a[m-1] + d + 100;
		for(int i=1;i<=t;i++)
			Q[day-i] += p;
	}
	mx=0;
	for(int i=1;i<=465;i++)
		if(Q[i] > mx)
			mx = Q[i];
	co(mx);
	return 0;
}


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

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define P(a,n) for(int i=a;i<=n;i++) cout<<a[i]<<" ";
#define bp(n) __builtin_popcount(n);
#define D 1000000007
#define pb push_back
#define ci(x) cin>>x;
#define c2(x,y) cin>>x>>y;
#define c3(x,y,z) cin>>x>>y>>z;
#define p2(x,y) cout<<x<<" "<<y<<endl;
#define p3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define co(x) cout<<x<<endl;
#define r0 return 0;
#define r1 return 1;
#define fi first
#define se second
#define mp make_pair

typedef vector<int> VI;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> VII;
typedef vector<ll> VL;
typedef vector<pll> VLL;
ll tpp = 9e18; int tp = 1e9;
ifstream I("input.txt");
ofstream O("output.txt");
int n,a[13],m,d,p,t,day,mx;
int Q[500]={0};
int main()
{
	_
	I>>n;
	a[1]=31;a[2]=28;a[3]=31;a[4]=30;a[5]=31;a[6]=30;
	a[7]=31;a[8]=31;a[9]=30;a[10]=31;a[11]=30;a[12]=31;
	for(int i=2;i<=12;i++)
		a[i] += a[i-1];
	a[0]=0;
	while(n--)
	{
		I>>m>>d>>p>>t;
		day = a[m-1] + d + 100;
		for(int i=1;i<=t;i++)
			Q[day-i] += p;
	}
	mx=0;
	for(int i=1;i<=465;i++)
		if(Q[i] > mx)
			mx = Q[i];
	O<<mx<<endl;
	return 0;
}


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

#define sz(x) (int)x.size()

int n,ans;
map<int,int> days;
struct oly{
    int m,d,p,t;
};

oly arr[111];

bool cmp(oly a,oly b){
    if(a.m!=b.m)return a.m<b.m;
    if(a.d!=b.d)return a.d<b.d;
    return a.t<b.t;
}

bool ok(){
    for(int i=0;i<n;i++)
        if(arr[i].p)return 1;
    return 0;
}

pair<int,int> inc(int m, int d, int t){
    while(t--){
        d++;
        if(d>days[m])d=1,m++;
    }
    return {m,d};
}

//int days[14]={31,31,28,31,30,31,30,31,31,30,31,30,31,31};
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    days[-3]=30; //9
    days[-2]=31; //10
    days[-1]=30; //11
    days[0]=31; //12
    days[1]=31;
    days[2]=28;
    days[3]=31;
    days[4]=30;
    days[5]=31;
    days[6]=30;
    days[7]=31;
    days[8]=31;
    days[9]=30;
    days[10]=31;
    days[11]=30;
    days[12]=31;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>arr[i].m>>arr[i].d>>arr[i].p>>arr[i].t;
        int tmp=arr[i].t;
        while(tmp--){
            arr[i].d--;
            if(arr[i].d==0){
                arr[i].m--;
                arr[i].d=days[arr[i].m];
            }
        }
    }
    sort(arr,arr+n,cmp);
    while(ok()){
        ans++;
        int m=-100,d=-100;
        for(int i=0;i<n;i++){
            if(arr[i].p==0)continue;
            if(arr[i].m>m||(arr[i].m==m&&arr[i].d>d)){
                arr[i].p--;
                pair<int,int>nw=inc(arr[i].m,arr[i].d,arr[i].t-1);
                m=nw.first,d=nw.second;
            }
        }
    }
    cout<<ans;
}


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

#define sz(x) (int)x.size()

int n,m,d,p,t,ans;
map<pair<int,int>,int> mp;
map<int,int> days;
int main() {
//#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
//#endif
    days[-3]=30,days[-2]=31,days[-1]=30,days[0]=31,
    days[1]=31,days[2]=28,days[3]=31,days[4]=30,
    days[5]=31,days[6]=30,days[7]=31,days[8]=31,
    days[9]=30,days[10]=31,days[11]=30,days[12]=31;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>m>>d>>p>>t;
        while(t--){
            d--;
            if(d==0)--m,d=days[m];
            mp[{m,d}]+=p;
        }
    }
    for(map<pair<int,int> ,int>::iterator it=mp.begin();it!=mp.end();++it)
        ans=max(ans,it->second);
    cout<<ans;
}


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

#define sz(x) (int)x.size()

int n,ans;
map<int,int> days;
struct oly{
    int m,d,p,t;
};

oly arr[111];

bool cmp(oly a,oly b){
    if(a.m!=b.m)return a.m<b.m;
    if(a.d!=b.d)return a.d<b.d;
    return a.t<b.t;
}

bool ok(){
    for(int i=0;i<n;i++)
        if(arr[i].p)return 1;
    return 0;
}

pair<int,int> inc(int m, int d, int t){
    while(t--){
        d++;
        if(d>days[m])d=1,m++;
    }
    return {m,d};
}

//int days[14]={31,31,28,31,30,31,30,31,31,30,31,30,31,31};
int main() {
//#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
//#endif
    days[-3]=30; //9
    days[-2]=31; //10
    days[-1]=30; //11
    days[0]=31; //12
    days[1]=31;
    days[2]=28;
    days[3]=31;
    days[4]=30;
    days[5]=31;
    days[6]=30;
    days[7]=31;
    days[8]=31;
    days[9]=30;
    days[10]=31;
    days[11]=30;
    days[12]=31;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>arr[i].m>>arr[i].d>>arr[i].p>>arr[i].t;
        int tmp=arr[i].t;
        while(tmp--){
            arr[i].d--;
            if(arr[i].d==0){
                arr[i].m--;
                arr[i].d=days[arr[i].m];
            }
        }
    }
    sort(arr,arr+n,cmp);
    while(ok()){
        ans++;
        int m=-100,d=-100;
        for(int i=0;i<n;i++){
            if(arr[i].p==0)continue;
            if(arr[i].m>m||(arr[i].m==m&&arr[i].d>d)){
                arr[i].p--;
                pair<int,int>nw=inc(arr[i].m,arr[i].d,arr[i].t-1);
                m=nw.first,d=nw.second;
            }
        }
    }
    cout<<ans;
}


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

#define sz(x) (int)x.size()

int n,m,d,p,t,ans;
map<pair<int,int>,int> mp;
map<int,int> days;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
   // freopen("output.txt", "wt", stdout);
#endif
    days[-3]=30,days[-2]=31,days[-1]=30,days[0]=31,
    days[1]=31,days[2]=28,days[3]=31,days[4]=30,
    days[5]=31,days[6]=30,days[7]=31,days[8]=31,
    days[9]=30,days[10]=31,days[11]=30,days[12]=31;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>m>>d>>p>>t;
        while(t--){
            d--;
            if(d==0)--m,d=days[m];
            mp[{m,d}]+=p;
        }
    }
    for(map<pair<int,int> ,int>::iterator it=mp.begin();it!=mp.end();++it)
        ans=max(ans,it->second);
    cout<<ans;
}


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

int DY[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

int YR[1000];
int main()
{
	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
	int N; scanf("%d", &N);
	for (int i = 0; i < N; i++){
		int A, B, C, D;
		scanf("%d%d%d%d", &A, &B, &C, &D);

		int st_dat = 0;
		for (int j = 0; j < A; j++)
			st_dat += DY[j];
		st_dat += B;
		for (int j = st_dat - D; j < st_dat; j++)
			YR[j+150] += C;
	}
	int Ans = 0;
	for (int i = 0; i < 1000; i++) {
		Ans = max(Ans, YR[i]);
	}
	printf("%d\n", Ans);
}


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

int DY[] = {31,28,31,30,31,30,31,31,30,31,30,31};

int YR[1000];
int main()
{
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	int N; scanf("%d", &N);
	for (int i = 0; i < N; i++){
		int A, B, C, D;
		scanf("%d%d%d%d", &A, &B, &C, &D);

		int st_dat = 0;
		for (int j = 0; j < A-1; j++)
			st_dat += DY[j];
		st_dat += B;
		for (int j = st_dat - D; j < st_dat; j++)
			YR[j+100] += C;
	}
	int Ans = 0;
	for (int i = 0; i < 1000; i++) {
		Ans = max(Ans, YR[i]);
	}
	printf("%d\n", Ans);
}


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

int DY[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

int YR[1000];
int main()
{
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	int N; scanf("%d", &N);
	for (int i = 0; i < N; i++){
		int A, B, C, D;
		scanf("%d%d%d%d", &A, &B, &C, &D);

		int st_dat = 0;
		for (int j = 0; j < A; j++)
			st_dat += DY[j];
		st_dat += B;
		for (int j = st_dat - D; j < st_dat; j++)
			YR[j+150] += C;
	}
	int Ans = 0;
	for (int i = 0; i < 1000; i++) {
		Ans = max(Ans, YR[i]);
	}
	printf("%d\n", Ans);
}


#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;
const int N = 2000228;

const int months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int a[N], b[N], dp[N], l[N], r[N];

int main() {
    ios::sync_with_stdio(false);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    dp[0] = months[0];
    for(int i = 1; i < 12; i++) {
        dp[i] = dp[i - 1] + months[i];
    }

    vector<pair<int, int > > v;

    for(int i = 0; i < n; i++) {
        int m, d, p, t;

        cin >> m >> d >> p >> t;

        int x = (m - 1 ? dp[m - 2] : 0) + d;

        int r = x - 1;
        int l = r - t + 1;
        v.push_back(make_pair(l, +p));
        v.push_back(make_pair(r + 1, -p));
    }

    sort(v.begin(), v.end());

    int ans = 0;
    int cur = 0;
    int i = 0;
    while(i < v.size()) {
        int last = i;

        while(i < v.size() && v[i].first == v[last].first) {
            cur += v[i].second;
            i++;
        }
        ans = max(ans, cur);
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;
const int N = 2000228;

const int months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int a[N], b[N], dp[N], l[N], r[N];

int main() {
    ios::sync_with_stdio(false);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    dp[0] = months[0];
    for(int i = 1; i < 12; i++) {
        dp[i] = dp[i - 1] + months[i];
    }

    vector<pair<int, int > > v;

    for(int i = 0; i < n; i++) {
        int m, d, p, t;

        cin >> m >> d >> p >> t;

        int x = (m ? dp[m - 1] : 0) + d;

        int r = x - 1;
        int l = r - t + 1;
        v.push_back(make_pair(l, +p));
        v.push_back(make_pair(r + 1, -p));
    }

    sort(v.begin(), v.end());

    int ans = 0;
    int cur = 0;

    for(int i = 0; i < v.size(); i++) {
        cur += v[i].second;
        ans = max(ans, cur);
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;
const int N = 2000228;

const int months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int a[N], b[N], dp[N], l[N], r[N];

int main() {
    ios::sync_with_stdio(false);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    dp[0] = months[0];
    for(int i = 1; i < 12; i++) {
        dp[i] = dp[i - 1] + months[i];
    }

    vector<pair<int, int > > v;

    for(int i = 0; i < n; i++) {
        int m, d, p, t;

        cin >> m >> d >> p >> t;

        int x = (m - 1 ? dp[m - 2] : 0) + d;

        int r = x - 1;
        int l = r - t + 1;
        v.push_back(make_pair(l, +p));
        v.push_back(make_pair(r + 1, -p));
    }

    sort(v.begin(), v.end());

    int ans = 0;
    int cur = 0;
    int i = 0;
    while(i < v.size()) {
        int last = i;

        while(i < v.size() && v[i].first == v[last].first) {
            cur += v[i].second;
            i++;
        }
        ans = max(ans, cur);
    }
    cout << ans << "\n";

    return 0;
}


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

using namespace std;
using namespace __gnu_cxx;

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

const int N = 100;
const int em[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int in[20000], ot[20000];

struct date {
	int yr, mo, dy;
};

date moveDate(date cur, int day) {
	while (day--) {
		--cur.dy;
		if (cur.dy == 0) {
			--cur.mo;
			if (cur.mo == 0)
				--cur.yr, cur.mo = 12;
			cur.dy = em[cur.mo - 1];
		}
	}
	return cur;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastInOut();
	int n, m, d, p, t;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> m >> d >> p >> t;
		date cur = (date ) { 1, m, d };
		date st = moveDate(cur, t), ed = moveDate(cur, 1);
		in[st.yr * 10000 + st.mo * 100 + st.dy] += p;
		ot[ed.yr * 10000 + ed.mo * 100 + ed.dy] += p;
	}
	int ret = 0, tot = 0;
	for (int i = 0; i < 20000; ++i)
		tot += in[i], ret = max(ret, tot), tot -= ot[i];
	cout << ret << "\n";
	return 0;
}

void fastInOut() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}


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

using namespace std;
using namespace __gnu_cxx;

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

const int N = 100;
const int em[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int in[20000], ot[20000];

struct date {
	int yr, mo, dy;
};

date moveDate(date cur, int day) {
	while (day--) {
		--cur.dy;
		if (cur.dy == 0) {
			--cur.mo;
			if (cur.mo == 0)
				--cur.yr, cur.mo = 12;
			cur.dy = em[cur.mo - 1];
		}
	}
	return cur;
}

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	fastInOut();
	int n, m, d, p, t;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> m >> d >> p >> t;
		date cur = (date ) { 1, m, d };
		date st = moveDate(cur, t), ed = moveDate(cur, 1);
		in[st.yr * 10000 + st.mo * 100 + st.dy] += p;
		ot[ed.yr * 10000 + ed.mo * 100 + ed.dy] += p;
	}
	int ret = 0, tot = 0;
	for (int i = 0; i < 20000; ++i)
		tot += in[i], ret = max(ret, tot), tot -= ot[i];
	cout << ret << "\n";
	return 0;
}

void fastInOut() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}


//============================================================================
// Name        : hamopop.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
///============================================================================

#include <bits/stdc++.h>
using namespace std;
/*float x[3];
 float arr[3][10][3];
 float ahmed[3][10];
 pair<float, int> five[30];
 float m[3], r[3];
 void scaling() {
 for (int i = 0; i < 3; i++) {
 float sum = 0;
 for (int j = 0; j < 3; j++)
 for (int k = 0; k < 10; k++) {
 sum += arr[j][k][i];
 }
 m[i] = sum / 30;
 }
 for (int i = 0; i < 3; i++) {
 float sum = 0;
 for (int j = 0; j < 3; j++)
 for (int k = 0; k < 10; k++) {
 sum += (arr[j][k][i] - m[i]) * (arr[j][k][i] - m[i]);
 }
 sum /= 30;
 sum = sqrt(sum);
 r[i] = sum;
 }
 for (int i = 0; i < 3; i++)
 for (int j = 0; j < 3; j++)
 for (int k = 0; k < 10; k++)
 arr[j][k][i] = (arr[j][k][i] - m[i]) / r[i];
 for (int i = 0; i < 3; i++)
 x[i] = (x[i] - m[i]) / r[i];

 }
 void fill() {
 int k = 0;
 for (int numcl = 0; numcl < 3; numcl++) {
 for (int numr = 0; numr < 10; numr++) {
 float sum = 0;
 for (int numc = 0; numc < 3; numc++) {
 sum += (arr[numcl][numr][numc] - x[numc])
 * (arr[numcl][numr][numc] - x[numc]);
 }
 sum = sqrt(sum);
 ahmed[numcl][numr] = sum;
 five[k].first = sum;
 five[k].second = numcl;
 k++;
 }
 }

 }
 int single() {
 pair<float, int> min;
 min.first = 10000000;
 for (int i = 0; i < 3; i++)
 for (int j = 0; j < 10; j++) {
 if (ahmed[i][j] < min.first)
 min.first = ahmed[i][j], min.second = i + 1;
 }
 return min.second;
 }
 int fivex() {
 int arr[3] = { 0, 0, 0 };
 pair<int, int> ans;
 ans.first = 0;
 sort(five, five + 30);
 for (int i = 0; i < 5; i++)
 arr[five[i].second]++;
 for (int i = 0; i < 3; i++) {
 if (arr[i] > ans.first)
 ans.first = arr[i], ans.second = i + 1;
 }
 return ans.second;
 }
 int city() {
 pair<float, int> min;
 min.first = 10000000;
 for (int numcl = 0; numcl < 3; numcl++) {
 for (int numr = 0; numr < 10; numr++) {
 float sum = 0;
 for (int numc = 0; numc < 3; numc++) {
 sum += abs((arr[numcl][numr][numc] - x[numc]));
 }
 if (sum < min.first)
 min.first = sum, min.second = numcl + 1;
 }
 }
 return min.second;
 }
 int main() {
 freopen("input.txt", "rt", stdin);
 for (int i = 0; i < 3; i++)
 for (int k = 0; k < 10; k++)
 for (int r = 0; r < 3; r++)
 cin >> arr[i][k][r];
 cin >> x[0] >> x[1] >> x[2];
 string s, s1;
 cin >> s >> s1;
 if (s1 == "scaling")
 scaling();
 int ans;
 fill();
 if (s == "single")
 ans = single();
 if (s == "5th")
 ans = fivex();
 if (s == "city")
 ans = city();
 cout << "this features belong to " << ans;

 }*/
/*freopen("input.txt", "rt", stdin);
 freopen("output.txt", "wt", stdout);*/
void fun(int b,int d){
    int u=1;
    int v=0;
    if((b<0&&d>0)||(b>0&&d<0))  v=1;
    b=abs(b);
    d=abs(d);
    if(b<d){
        swap(b,d);
        u=0;
    }

    int b1=b,d1=d;
    int x=b%d;
    while(x){
        b=d;
        d=x;
        x=b%d;
    }

    if(u==0){
        if(v) d1*=-1;
        cout<<d1/d<<"/"<<b1/d;
    }
    else {
        if(v) b1*=-1;
        cout<<b1/d<<"/"<<d1/d;
    }
}

/*int main(){
    int n;
    cin>>n;
    pair<int ,int > arr[n];
    int a,b,c,d;
    int z;
    cin>>z;
    cin>>a>>b>>z>>c>>d;

    if((c>a&&c<b)||(d>a&&d<a))
        arr[n-2].second=1;

    else arr[n-2].second=0;

    if((a>c&&a<d)||(b>c&&b<d))
        arr[n-1].first=1;

    else arr[n-1].first=0;

    a=c; b=d;
    int j=n-3;

    n-=2;

    while(n--){

        cin>>z;
        if(z==1){
            cin>>c>>d;
            if((c>a&&c<b)||(d>a&&d<b))
                    arr[j].second=1;

            else arr[j].second=0;

            if((a>c&&a<d)||(b>c&&b<d))
                    arr[j+1].first=1;

            else arr[j+1].first=0;

            a=c,b=d;
            j--;
        }

        else{
            int x,y;
            cin>>x>>y;
            y+=j;
            x+=j;
            int u=0;
            if(x<y){

                while(x!=y){
                    if(!arr[x].second) {
                        u=1;
                        break;
                    }
                    x++;
                }
                if(u) cout<<"NO";
                else cout<<"YES";
            }
            else{
                while(x!=y){
                    if(!arr[x].first) {
                        u=1;
                        break;
                    }
                    x--;
                }
                if(u) cout<<"NO";
                else cout<<"YES";
            }
            cout<<endl;
        }
    }*/
int po(int m,int i){
    int r=1;
    while(i--){
        r*=m;
    }
    return r;
}

int v[600];
int main(){
    int arr[12];
    arr[0]=0;arr[1]=31;arr[2]=28+arr[1];arr[3]=31+arr[2];
    arr[4]=30+arr[3];arr[5]=31+arr[4];arr[6]=30+arr[5];arr[7]=31+arr[6];arr[8]=31+arr[7];
    arr[9]=30+arr[8];arr[10]=31+arr[9];arr[11]=30+arr[10];

    int n,m,d,p,t;
    cin>>n;
    while(n--){
        cin>>m>>d>>p>>t;
        int x=arr[m-1]+d+100;
        while(t--){
            v[x-t]+=p;
        }
    }
    int max=0;
    for(int i=0;i<600;i++)
        if(v[i]>max) max=v[i];
    cout<<max;

    return 0;
}


//============================================================================
// Name        : hamopop.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
///============================================================================

#include <bits/stdc++.h>
using namespace std;
/*float x[3];
 float arr[3][10][3];
 float ahmed[3][10];
 pair<float, int> five[30];
 float m[3], r[3];
 void scaling() {
 for (int i = 0; i < 3; i++) {
 float sum = 0;
 for (int j = 0; j < 3; j++)
 for (int k = 0; k < 10; k++) {
 sum += arr[j][k][i];
 }
 m[i] = sum / 30;
 }
 for (int i = 0; i < 3; i++) {
 float sum = 0;
 for (int j = 0; j < 3; j++)
 for (int k = 0; k < 10; k++) {
 sum += (arr[j][k][i] - m[i]) * (arr[j][k][i] - m[i]);
 }
 sum /= 30;
 sum = sqrt(sum);
 r[i] = sum;
 }
 for (int i = 0; i < 3; i++)
 for (int j = 0; j < 3; j++)
 for (int k = 0; k < 10; k++)
 arr[j][k][i] = (arr[j][k][i] - m[i]) / r[i];
 for (int i = 0; i < 3; i++)
 x[i] = (x[i] - m[i]) / r[i];

 }
 void fill() {
 int k = 0;
 for (int numcl = 0; numcl < 3; numcl++) {
 for (int numr = 0; numr < 10; numr++) {
 float sum = 0;
 for (int numc = 0; numc < 3; numc++) {
 sum += (arr[numcl][numr][numc] - x[numc])
 * (arr[numcl][numr][numc] - x[numc]);
 }
 sum = sqrt(sum);
 ahmed[numcl][numr] = sum;
 five[k].first = sum;
 five[k].second = numcl;
 k++;
 }
 }

 }
 int single() {
 pair<float, int> min;
 min.first = 10000000;
 for (int i = 0; i < 3; i++)
 for (int j = 0; j < 10; j++) {
 if (ahmed[i][j] < min.first)
 min.first = ahmed[i][j], min.second = i + 1;
 }
 return min.second;
 }
 int fivex() {
 int arr[3] = { 0, 0, 0 };
 pair<int, int> ans;
 ans.first = 0;
 sort(five, five + 30);
 for (int i = 0; i < 5; i++)
 arr[five[i].second]++;
 for (int i = 0; i < 3; i++) {
 if (arr[i] > ans.first)
 ans.first = arr[i], ans.second = i + 1;
 }
 return ans.second;
 }
 int city() {
 pair<float, int> min;
 min.first = 10000000;
 for (int numcl = 0; numcl < 3; numcl++) {
 for (int numr = 0; numr < 10; numr++) {
 float sum = 0;
 for (int numc = 0; numc < 3; numc++) {
 sum += abs((arr[numcl][numr][numc] - x[numc]));
 }
 if (sum < min.first)
 min.first = sum, min.second = numcl + 1;
 }
 }
 return min.second;
 }
 int main() {
 freopen("input.txt", "rt", stdin);
 for (int i = 0; i < 3; i++)
 for (int k = 0; k < 10; k++)
 for (int r = 0; r < 3; r++)
 cin >> arr[i][k][r];
 cin >> x[0] >> x[1] >> x[2];
 string s, s1;
 cin >> s >> s1;
 if (s1 == "scaling")
 scaling();
 int ans;
 fill();
 if (s == "single")
 ans = single();
 if (s == "5th")
 ans = fivex();
 if (s == "city")
 ans = city();
 cout << "this features belong to " << ans;

 }*/
/*freopen("input.txt", "rt", stdin);
 freopen("output.txt", "wt", stdout);*/
void fun(int b,int d){
    int u=1;
    int v=0;
    if((b<0&&d>0)||(b>0&&d<0))  v=1;
    b=abs(b);
    d=abs(d);
    if(b<d){
        swap(b,d);
        u=0;
    }

    int b1=b,d1=d;
    int x=b%d;
    while(x){
        b=d;
        d=x;
        x=b%d;
    }

    if(u==0){
        if(v) d1*=-1;
        cout<<d1/d<<"/"<<b1/d;
    }
    else {
        if(v) b1*=-1;
        cout<<b1/d<<"/"<<d1/d;
    }
}

/*int main(){
    int n;
    cin>>n;
    pair<int ,int > arr[n];
    int a,b,c,d;
    int z;
    cin>>z;
    cin>>a>>b>>z>>c>>d;

    if((c>a&&c<b)||(d>a&&d<a))
        arr[n-2].second=1;

    else arr[n-2].second=0;

    if((a>c&&a<d)||(b>c&&b<d))
        arr[n-1].first=1;

    else arr[n-1].first=0;

    a=c; b=d;
    int j=n-3;

    n-=2;

    while(n--){

        cin>>z;
        if(z==1){
            cin>>c>>d;
            if((c>a&&c<b)||(d>a&&d<b))
                    arr[j].second=1;

            else arr[j].second=0;

            if((a>c&&a<d)||(b>c&&b<d))
                    arr[j+1].first=1;

            else arr[j+1].first=0;

            a=c,b=d;
            j--;
        }

        else{
            int x,y;
            cin>>x>>y;
            y+=j;
            x+=j;
            int u=0;
            if(x<y){

                while(x!=y){
                    if(!arr[x].second) {
                        u=1;
                        break;
                    }
                    x++;
                }
                if(u) cout<<"NO";
                else cout<<"YES";
            }
            else{
                while(x!=y){
                    if(!arr[x].first) {
                        u=1;
                        break;
                    }
                    x--;
                }
                if(u) cout<<"NO";
                else cout<<"YES";
            }
            cout<<endl;
        }
    }*/
int po(int m,int i){
    int r=1;
    while(i--){
        r*=m;
    }
    return r;
}

int v[600];
int main(){
    freopen("input.txt", "rt", stdin);
     freopen("output.txt", "wt", stdout);
    int arr[12];
    arr[0]=0;arr[1]=31;arr[2]=28+arr[1];arr[3]=31+arr[2];
    arr[4]=30+arr[3];arr[5]=31+arr[4];arr[6]=30+arr[5];arr[7]=31+arr[6];arr[8]=31+arr[7];
    arr[9]=30+arr[8];arr[10]=31+arr[9];arr[11]=30+arr[10];

    int n,m,d,p,t;
    cin>>n;
    while(n--){
        cin>>m>>d>>p>>t;
        int x=arr[m-1]+d+100;
        while(t--){
            v[x-t]+=p;
        }
    }
    int max=0;
    for(int i=0;i<600;i++)
        if(v[i]>max) max=v[i];
    cout<<max;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define jan 122
#define feb 122+31
#define mar 122+31+28
#define apr 122+31+28+31
#define may 122+31+28+31+30
#define june 122+31+28+31+30+31
#define july 122+31+28+31+30+31+30
#define aug 122+31+28+31+30+31+30+31
#define sep 122+31+28+31+30+31+30+31+31
#define oct 122+31+28+31+30+31+30+31+31+30
#define nov 122+31+28+31+30+31+30+31+31+30+31
#define dec 122+31+28+31+30+31+30+31+31+30+31+30

int days[488];

int main()
{
    int n,month,d,jury,time,ans=0;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>month>>d>>jury>>time;
        if(ans<jury)
            ans=jury;
        if(month==1)
        {
            days[jan+d]-=jury;
            days[jan+d-time]+=jury;
        }
        else if(month==2)
        {
            days[feb+d]-=jury;
            days[feb+d-time]+=jury;
        }
        else if(month==3)
        {
            days[mar+d]-=jury;
            days[mar+d-time]+=jury;
        }
        else if(month==4)
        {
            days[apr+d]-=jury;
            days[apr+d-time]+=jury;
        }
        else if(month==5)
        {
            days[may+d]-=jury;
            days[may+d-time]+=jury;
        }
        else if(month==6)
        {
            days[june+d]-=jury;
            days[june+d-time]+=jury;
        }
        else if(month==7)
        {
            days[july+d]-=jury;
            days[july+d-time]+=jury;
        }
        else if(month==8)
        {
            days[aug+d]-=jury;
            days[aug+d-time]+=jury;
        }
        else if(month==9)
        {
            days[sep+d]-=jury;
            days[sep+d-time]+=jury;
        }
        else if(month==10)
        {
            days[oct+d]-=jury;
            days[oct+d-time]+=jury;
        }
        else if(month==11)
        {
            days[nov+d]-=jury;
            days[nov+d-time]+=jury;
        }
        else if(month==12)
        {
            days[dec+d]-=jury;
            days[dec+d-time]+=jury;
        }
    }

    for(int i=1;i<488;i++)
    {
        days[i]+=days[i-1];
        if(ans<days[i])
            ans=days[i];
    }

    cout<<ans<<endl;

    return 0;
}


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

int days[488];

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,month,d,jury,time,ans=0;
    scanf("%d",&n);

    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d%d",&month,&d,&jury,&time);
        if(ans<jury)
            ans=jury;
        if(month==1)
        {
            days[122+d]-=jury;
            days[122+d-time]+=jury;
        }
        else if(month==2)
        {
            days[153+d]-=jury;
            days[153+d-time]+=jury;
        }
        else if(month==3)
        {
            days[181+d]-=jury;
            days[181+d-time]+=jury;
        }
        else if(month==4)
        {
            days[212+d]-=jury;
            days[212+d-time]+=jury;
        }
        else if(month==5)
        {
            days[242+d]-=jury;
            days[242+d-time]+=jury;
        }
        else if(month==6)
        {
            days[273+d]-=jury;
            days[273+d-time]+=jury;
        }
        else if(month==7)
        {
            days[303+d]-=jury;
            days[303+d-time]+=jury;
        }
        else if(month==8)
        {
            days[334+d]-=jury;
            days[334+d-time]+=jury;
        }
        else if(month==9)
        {
            days[365+d]-=jury;
            days[365+d-time]+=jury;
        }
        else if(month==10)
        {
            days[395+d]-=jury;
            days[395+d-time]+=jury;
        }
        else if(month==11)
        {
            days[426+d]-=jury;
            days[426+d-time]+=jury;
        }
        else if(month==12)
        {
            days[456+d]-=jury;
            days[456+d-time]+=jury;
        }
    }

    for(int i=1;i<488;i++)
    {
        days[i]+=days[i-1];
        if(ans<days[i])
            ans=days[i];
    }

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

    return 0;
}


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

int days[488];

int main()
{
    int n,month,d,jury,time,ans=0;
    scanf("%d",&n);

    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d%d",&month,&d,&jury,&time);
        if(ans<jury)
            ans=jury;
        if(month==1)
        {
            days[122+d]-=jury;
            days[122+d-time]+=jury;
        }
        else if(month==2)
        {
            days[153+d]-=jury;
            days[153+d-time]+=jury;
        }
        else if(month==3)
        {
            days[181+d]-=jury;
            days[181+d-time]+=jury;
        }
        else if(month==4)
        {
            days[212+d]-=jury;
            days[212+d-time]+=jury;
        }
        else if(month==5)
        {
            days[242+d]-=jury;
            days[242+d-time]+=jury;
        }
        else if(month==6)
        {
            days[273+d]-=jury;
            days[273+d-time]+=jury;
        }
        else if(month==7)
        {
            days[303+d]-=jury;
            days[303+d-time]+=jury;
        }
        else if(month==8)
        {
            days[334+d]-=jury;
            days[334+d-time]+=jury;
        }
        else if(month==9)
        {
            days[365+d]-=jury;
            days[365+d-time]+=jury;
        }
        else if(month==10)
        {
            days[395+d]-=jury;
            days[395+d-time]+=jury;
        }
        else if(month==11)
        {
            days[426+d]-=jury;
            days[426+d-time]+=jury;
        }
        else if(month==12)
        {
            days[456+d]-=jury;
            days[456+d-time]+=jury;
        }
    }

    for(int i=1;i<488;i++)
    {
        days[i]+=days[i-1];
        if(ans<days[i])
            ans=days[i];
    }

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define el      	'\n'
#define ft 			first
#define sd 			second
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define clr(a,b)	memset(a,b,sizeof(a))
typedef long long ll;
void Yahia74() {
//#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
//#endif
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 1e5 + 74, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

int ans[500] ;
int month[14] = {0,102,133,161,192,222,253,283,314,344,375,405,436} ;
int main() {
	Yahia74();
	int n , mx = 0;
	cin >> n ;
	while(n--){
		int m , d , p , t ;
		cin >> m >> d >> p >> t ;
		int i = month[m] + d - 2 ;
		while(t--){
			ans[i] += p ;
			mx = max(ans[i] ,mx);
			i-- ;
 		}
	}
	cout << mx ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define el      	'\n'
#define ft 			first
#define sd 			second
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define clr(a,b)	memset(a,b,sizeof(a))
typedef long long ll;
void Yahia74() {
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
//#endif
//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 1e5 + 74, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

int ans[500] ;
int month[20] = {0,104,135,163,194,224,255,285,316,347,377,408,438} ;
int main() {
//	Yahia74();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n , mx = 0;
	cin >> n ;
	while(n--){
		int m , d , p , t ;
		cin >> m >> d >> p >> t ;
		int i = month[m] + d - 2 ;
		while(t--){
			ans[i] += p ;
			mx = max(ans[i] ,mx);
			i-- ;
 		}
	}
	cout << mx ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define el      	'\n'
#define ft 			first
#define sd 			second
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define clr(a,b)	memset(a,b,sizeof(a))
typedef long long ll;
void Yahia74() {
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
//#endif
//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 1e5 + 74, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

int ans[500] ;
int month[20] = {0,102,133,161,192,222,253,283,314,344,375,405,436} ;
int main() {
//	Yahia74();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n , mx = 0;
	cin >> n ;
	while(n--){
		int m , d , p , t ;
		cin >> m >> d >> p >> t ;
		int i = month[m] + d - 2 ;
		while(t--){
			ans[i] += p ;
			mx = max(ans[i] ,mx);
			i-- ;
 		}
	}
	cout << mx ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define el      	'\n'
#define ft 			first
#define sd 			second
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define clr(a,b)	memset(a,b,sizeof(a))
typedef long long ll;
void Yahia74() {
//#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
//#endif
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 1e5 + 74, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

int ans[500] ;
int month[13] = {0,102,133,161,192,222,253,283,314,344,375,405,436} ;
int main() {
	Yahia74();
	int n , mx = 0;
	cin >> n ;
	while(n--){
		int m , d , p , t ;
		cin >> m >> d >> p >> t ;
		int i = month[m] + d - 2 ;
		while(t--){
			ans[i] += p ;
			mx = max(ans[i] ,mx);
			i-- ;
 		}
	}
	cout << mx ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int Y2013[] = {0, 1, -2, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 };
int Y2012[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, -1 };
int main() {
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	map<pair<int, pair<int, int> >, int> myMap;
	int n;
	scanf("%d", &n);
	int m, d, p, t;
	int mx = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d %d %d %d", &m, &d, &p, &t);
		int y = 13;
		while (t--) {
			d--;
			if (!d) {
				if (!(m - 1)) {
					y = 12;
					m = 12;
					d = 30 + Y2012[m];
				} else {
					m--;
					d = 30 + Y2013[m];
				}
			}
			myMap[ { y, { m, d } }] += p;
			mx = max(mx, myMap[ { y, { m, d } }]);
		}
	}
//	for (auto i : myMap) {
//		printf("Year: %d, month: %d, day: %d == %d\n", i.first.first,
//				i.first.second.first, i.first.second.second, i.second);
//	}
	printf("%d\n", mx);
}
//2519


#include <bits/stdc++.h>
using namespace std;
int main() {
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	map<int , int> myMap;
	int n;
	scanf("%d",&n);
	int m , d , p , t;
	int mx = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d %d %d %d",&m, &d, &p , &t);
		int dd = m*30 + d;
		for (int j = dd  - t; j < dd; ++j) {
			myMap[j] += p;
			mx = max(mx, myMap[j]);
		}
	}
	printf("%d\n",mx);
}
//2519


#include <bits/stdc++.h>
using namespace std;
int Y2013[] = {0, 1, -2, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 };
int Y2012[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, -1 };
int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	map<pair<int, pair<int, int> >, int> myMap;
	int n;
	scanf("%d", &n);
	int m, d, p, t;
	int mx = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d %d %d %d", &m, &d, &p, &t);
		int y = 13;
		while (t--) {
			d--;
			if (!d) {
				if (!(m - 1)) {
					y = 12;
					m = 12;
					d = 30 + Y2012[m];
				} else {
					m--;
					d = 30 + Y2013[m];
				}
			}
			myMap[ { y, { m, d } }] += p;
			mx = max(mx, myMap[ { y, { m, d } }]);
		}
	}
//	for (auto i : myMap) {
//		printf("Year: %d, month: %d, day: %d == %d\n", i.first.first,
//				i.first.second.first, i.first.second.second, i.second);
//	}
	printf("%d\n", mx);
}
//2519


   /***********BISMILLAHIR RAHMANIR RAHIM****
         *******NAHID AL-ASIB***************
          ********************************/
#include<bits/stdc++.h>
#define mx 105

using namespace std;
struct info
{
     int st,en,pr,rem;
}arr[mx];
int n,m,d,p,t;
int mon[]={0,31,59,90,120,151,181,212,243,273,304,334};

bool cmp(info a,info b)
{
      if(a.en==b.en)
         return a.pr<b.pr;
     else
     {
           if(a.st==b.st)
             return a.en<b.en;
           else
             a.st<b.st;
     }
}

int main()
{
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      cin>>n;
      for(int i=0;i<n;i++)
      {
           scanf("%d%d%d%d",&m,&d,&p,&t);
           arr[i].pr=p;
           arr[i].rem=p;
           arr[i].st=mon[m-1]+d-t;
           arr[i].en=mon[m-1]+d-1;
      }
      sort(arr,arr+n,cmp);
      if(n==1) { cout<<arr[0].pr<<endl; return 0;}

      int ans=0;
      for(int i=0;i<n;i++)
      {
           ans+=arr[i].rem;
           int temp=arr[i].pr;
           for(int j=i+1;j<n && temp>0;j++)
           {
                 if(arr[j].st>arr[i].en)
                 {
                       if(temp>arr[j].rem)
                       {
                            temp-=arr[j].rem;
                            arr[j].rem=0;
                       }
                       else
                       {
                            arr[j].rem-=temp;
                            temp=0;
                       }
                 }
           }
      }
      cout<<ans<<endl;
      return 0;
}


   /***********BISMILLAHIR RAHMANIR RAHIM****
        *******NAHID AL-ASIB***************
        ********************************/
#include<bits/stdc++.h>
#define mx 105

using namespace std;
struct info
{
     int st,en,pr,rem;
}arr[mx];
int n,m,d,p,t;
int mon[]={0,31,59,90,120,151,181,212,243,273,304,334};

bool cmp(info a,info b)
{
       if(a.st==b.st)
       {
             if(a.en==b.en)
                a.pr<b.pr;
             else
                a.en<b.en;
       }
       else
         return a.st<b.st;
}

int main()
{
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      cin>>n;
      for(int i=0;i<n;i++)
      {
           scanf("%d%d%d%d",&m,&d,&p,&t);
           arr[i].pr=p;
           arr[i].rem=p;
           arr[i].st=mon[m-1]+d-t;
           arr[i].en=mon[m-1]+d-1;
      }
      sort(arr,arr+n,cmp);
      if(n==1) { cout<<arr[0].pr<<endl; return 0;}

      int ans=0;
      for(int i=0;i<n;i++)
      {
           ans+=arr[i].rem;
           int temp=arr[i].pr;
           for(int j=i+1;j<n && temp>0;j++)
           {
                 if(arr[j].st>arr[i].en)
                 {
                       if(temp>arr[j].rem)
                       {
                            temp-=arr[j].rem;
                            arr[j].rem=0;
                       }
                       else
                       {
                            arr[j].rem-=temp;
                            temp=0;
                       }
                 }
           }
      }
      cout<<ans<<endl;
      return 0;
}


   /***********BISMILLAHIR RAHMANIR RAHIM****
         *******NAHID AL-ASIB***************
          ********************************/
#include<bits/stdc++.h>
#define mx 105

using namespace std;
struct info
{
     int st,en,pr;
}arr[mx];
int n,m,d,p,t;
int mon[]={0,31,59,90,120,151,181,212,243,273,304,334};

bool cmp(info a,info b)
{
      if(a.st==b.st)
         return a.en<b.en;
      else
        return a.st<b.st;
}

int main()
{
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      cin>>n;
      for(int i=0;i<n;i++)
      {
           scanf("%d%d%d%d",&m,&d,&p,&t);
           arr[i].pr=p;
           arr[i].st=mon[m-1]+d-t;
           arr[i].en=mon[m-1]+d-1;
      }
      sort(arr,arr+n,cmp);
      if(n==1) { cout<<arr[0].pr<<endl; return 0;}
      int ans=arr[0].pr;
      for(int i=1;i<=n-1;i++)
      {
           if(arr[i].st<=arr[i-1].en)
               ans+=arr[i].pr;
      }
      cout<<ans<<endl;
      return 0;
}