#include <bits/stdc++.h>

#define rep(i,j,k) for(int i = (int) j; i < (int) k; ++i)
#define mp make_pair
#define ll long long
#define db double
#define P pair<int, int >
using namespace std;
const db eps = 1e-8;
inline int sig(db x) {return (x > eps) - (x < -eps);}
const int N = 100100;
P p[N];
P a, b, t;
int n;

inline void in(const P& z) {scanf("%d %d", &z.first, &z.second); }

inline db sqr(int x) {return 1.*x*x;}

inline db dist(P u, P v) {
    return sqrt(sqr(u.first-v.first) + sqr(u.second-v.second));
}

db dia[N], dib[N], dit[N];
db savea[N], saveb[N];
db d;

inline void init() {
    d = 0;
    rep(i, 0, n) {
        dia[i] = dist(a, p[i]);
        dib[i] = dist(b, p[i]);
        dit[i] = dist(t, p[i]);
        d += dit[i] + dit[i];
        savea[i] = dit[i] - dia[i];
        saveb[i] = dit[i] - dib[i];
    }
    return ;
}

void solve() {
    init();
    if(n == 1) {
        if(savea[0] > saveb[0])
            printf("%.10f\n", dist(b, t) + dit[0] + dit[0] - savea[0]);
        else
            printf("%.10f\n", dist(a, t) + dit[0] + dit[0] - saveb[0]);
        return ;
    }
    int ida1 = -1, ida2 = -1;
    db ma1 = -1e18, ma2 = -1e18;
    rep(i, 0, n) if(savea[i] > ma1) ida1 = i, ma1 = savea[i];
    rep(i, 0, n) {
        if(i == ida1) continue;
        if(savea[i] > ma2) ida2 = i, ma2 = savea[i];
    }

    int idb1 = -1, idb2 = -1;
    db mb1 = -1e18, mb2 = -1e18;
    rep(i, 0, n) if(saveb[i] > mb1) idb1 = i, mb1 = saveb[i];
    rep(i, 0, n) {
        if(i == idb1) continue;
        if(saveb[i] > mb2) idb2 = i, mb2 = saveb[i];
    }

    if(ida1 != idb1) {

            d -= ma1;
            d -= mb1;

    }
    else {
        //if(ma1 != mb1) {
            db m1 = ma1 + mb2;
            db m2 = ma2 + mb1;
            m1 = max(m1, m2);
            d -= m1;
       // }

    }
    printf("%.10f\n", d);
}

void out(P z) {printf("(%d %d)\n", z.first, z.second); }

int main()
{
#ifdef PIT
freopen("671a.in", "r", stdin);
//freopen(".out", "w", stdout);
#endif // PIT

    in(a); in(b); in(t);
    scanf("%d", &n);
    rep(i, 0, n) in(p[i]);
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, j, k) for(int i = (int) j; i <= (int) k; ++i)
#define ll long long
#define mp make_pair
#define fi first
#define se second

using namespace std;

const int N = 100100;

pair<double, double > t[N];
double d;
int ax, ay, bx, by, tx, ty;
int n;

double dist(int a, int b, int x, int y) {
    return sqrt(1.*(a-x)*(a-x) + 1.*(b-y)*(b-y));
}

void in() {
    scanf("%d %d %d %d %d %d", &ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d", &n);
    int x, y;
    d = 0;
    rep(i, 1, n) {
        scanf("%d %d", &x, &y);
        double da, db, dt;
        da = dist(ax, ay, x, y);
        db = dist(bx, by, x, y);
        dt = dist(tx, ty, x, y);
        d += dt + dt;
        t[i] = {dt-da, dt-db};
    }
    t[0] = {dist(ax, ay, tx, ty), dist(bx, by, tx, ty)};
    sort(t, t+n+1);

    return ;
}

void solve() {
    double mx = 1e-16;
    for(int i = n; i >= 0; --i) {
        mx = max(mx, t[i].fi);
        mx = max(mx, t[i].se);
        if(i == n-1) mx = max(mx, t[i-1].fi+t[i].se);
        else mx = max(mx, t[n-1].fi+t[i].se);
    }
    printf("%.8f\n", d-mx);
    return ;
}

int main()
{
#ifdef PIT
//freopen("", "r", stdin);
#endif // PIT
    in();
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, j, k) for(int i = (int) j; i < (int) k; ++i)
#define ll long long
#define mp make_pair
#define fi first
#define se second

using namespace std;

const int N = 100100;

pair<double, double > t[N];
double d;
int ax, ay, bx, by, tx, ty;
int n;

double dist(int a, int b, int x, int y) {
    return sqrt((a-x)*(a-x) + (b-y)*(b-y));
}

void in() {
    scanf("%d %d %d %d %d %d", &ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d", &n);
    int x, y;
    d = 0;
    rep(i, 0, n) {
        scanf("%d %d", &x, &y);
        double da, db, dt;
        da = dist(ax, ay, x, y);
        db = dist(bx, by, x, y);
        dt = dist(tx, ty, x, y);
        d += dt + dt;
        t[i] = {dt-da, dt-db};
    }
    sort(t, t+n);
    return ;
}

void solve() {
    double mx = 1e-16;
    for(int i = n-1; i >= 0; --i) {
        mx = max(mx, t[i].fi);
        mx = max(mx, t[i].se);
        if(i == n-1) mx = max(mx, t[i-1].fi+t[i].se);
        else mx = max(mx, t[n-1].fi+t[i].se);
    }
    printf("%.8f\n", d-mx);
    return ;
}

int main()
{
#ifdef PIT
//freopen("", "r", stdin);
#endif // PIT
    in();
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i,j,k) for(int i = (int) j; i < (int) k; ++i)
#define mp make_pair
#define ll long long
#define db double
#define P pair<int, int >
using namespace std;
const db eps = 1e-8;
inline int sig(db x) {return (x > eps) - (x < -eps);}
const int N = 100100;
P p[N];
P a, b, t;
int n;

inline void in(const P& z) {scanf("%d %d", &z.first, &z.second); }

inline db sqr(int x) {return 1.*x*x;}

inline db dist(P u, P v) {
    return sqrt(sqr(u.first-v.first) + sqr(u.second-v.second));
}

db dia[N], dib[N], dit[N];
pair<db, db > sv[N];
db d;

inline void init() {
    d = 0;
    rep(i, 0, n) {
        dia[i] = dist(a, p[i]);
        dib[i] = dist(b, p[i]);
        dit[i] = dist(t, p[i]);
        d += dit[i] + dit[i];
        sv[i].first = dit[i] - dia[i];
        sv[i].second = dit[i] - dib[i];
    }
    return ;
}

void solve() {
    init();
    sort(sv, sv+n);
    db mx = 1e-18;
    rep(i, 0, n) {
        mx = max(mx, sv[i].first);
        mx = max(mx, sv[i].second);
        if(i) mx = max(mx, sv[n-1].first+sv[n-i-1].second);
        else mx = max(mx, sv[n-2].first+sv[n-1].second);
    }
    printf("%.8f\n", d-mx);

}

void out(P z) {printf("(%d %d)\n", z.first, z.second); }

int main()
{
#ifdef PIT
freopen("671a.in", "r", stdin);
//freopen(".out", "w", stdout);
#endif // PIT

    in(a); in(b); in(t);
    scanf("%d", &n);
    rep(i, 0, n) in(p[i]);
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i,j,k) for(int i = (int) j; i < (int) k; ++i)
#define mp make_pair
#define ll long long
#define db double
#define P pair<int, int >
using namespace std;
const db eps = 1e-8;
inline int sig(db x) {return (x > eps) - (x < -eps);}
const int N = 100100;
P p[N];
P a, b, t;
int n;

inline void in(const P& z) {scanf("%d %d", &z.first, &z.second); }

inline db sqr(int x) {return 1.*x*x;}

inline db dist(P u, P v) {
    return sqrt(sqr(u.first-v.first) + sqr(u.second-v.second));
}

db dia[N], dib[N], dit[N];
db savea[N], saveb[N];
db d;

inline void init() {
    d = 0;
    rep(i, 0, n) {
        dia[i] = dist(a, p[i]);
        dib[i] = dist(b, p[i]);
        dit[i] = dist(t, p[i]);
        d += dit[i] + dit[i];
        savea[i] = dit[i] - dia[i];
        saveb[i] = dit[i] - dib[i];
    }
    return ;
}

void solve() {
    init();
    if(n == 1) {
        if(savea[0] > saveb[0])
            printf("%.10f\n", dist(b, t) + dit[0] + dit[0] - savea[0]);
        else
            printf("%.10f\n", dist(a, t) + dit[0] + dit[0] - saveb[0]);
        return ;
    }
    int ida1 = -1, ida2 = -1;
    db ma1 = -1e18, ma2 = -1e18;
    rep(i, 0, n) if(savea[i] > ma1) ida1 = i, ma1 = savea[i];
    rep(i, 0, n) {
        if(i == ida1) continue;
        if(savea[i] > ma2) ida2 = i, ma2 = savea[i];
    }

    int idb1 = -1, idb2 = -1;
    db mb1 = -1e18, mb2 = -1e18;
    rep(i, 0, n) if(saveb[i] > mb1) idb1 = i, mb1 = saveb[i];
    rep(i, 0, n) {
        if(i == idb1) continue;
        if(saveb[i] > mb2) idb2 = i, mb2 = saveb[i];
    }

    if(ida1 != idb1) {

            d -= ma1;
            d -= mb1;

    }
    else {
        if(ma1 != mb1) {
            db m1 = ma1 + mb2;
            db m2 = ma2 + mb1;
            m1 = max(m1, m2);
            d -= m1;
        }

    }
    printf("%.10f\n", d);
}

void out(P z) {printf("(%d %d)\n", z.first, z.second); }

int main()
{
#ifdef PIT
freopen("671a.in", "r", stdin);
//freopen(".out", "w", stdout);
#endif // PIT

    in(a); in(b); in(t);
    scanf("%d", &n);
    rep(i, 0, n) in(p[i]);
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, j, k) for(int i = (int) j; i < (int) k; ++i)
#define ll long long
#define mp make_pair
#define fi first
#define se second

using namespace std;

const int N = 100100;

pair<double, double > t[N];
double d;
int ax, ay, bx, by, tx, ty;
int n;

double dist(int a, int b, int x, int y) {
    return sqrt(1.*(a-x)*(a-x) + 1.*(b-y)*(b-y));
}

void in() {
    scanf("%d %d %d %d %d %d", &ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d", &n);
    int x, y;
    d = 0;
    rep(i, 0, n) {
        scanf("%d %d", &x, &y);
        double da, db, dt;
        da = dist(ax, ay, x, y);
        db = dist(bx, by, x, y);
        dt = dist(tx, ty, x, y);
        d += dt + dt;
        t[i] = {dt-da, dt-db};
    }
    sort(t, t+n);
    return ;
}

void solve() {
    double mx = -1e16;
    for(int i = n-1; i >= 0; --i) {
        mx = max(mx, t[i].fi);
        mx = max(mx, t[i].se);
        if(i == n-1) mx = max(mx, t[i-1].fi+t[i].se);
        else mx = max(mx, t[n-1].fi+t[i].se);
    }
    printf("%.8f\n", d-mx);
    return ;
}

int main()
{
#ifdef PIT
//freopen("", "r", stdin);
#endif // PIT
    in();
    solve();
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
const int mod = 1e9+7;
const int maxn = 1e5+200;
const LL INF = 0x3f3f3f3f3f3f3f3f;
struct Coor{
    double x, y;
}coors[maxn];
double Distan(Coor a, Coor b){
    return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
double disa[maxn], disb[maxn];
int main(){
    int n;
    Coor a, b, t;
    while(scanf("%lf%lf %lf%lf %lf%lf",&a.x,&a.y,&b.x,&b.y,&t.x,&t.y)!=EOF){
        scanf("%d",&n);
        double dt;
        double sum = 0;
        double opt1 = double(INF), opt2 = double(INF);
        int opt1id = 1, opt2id = 1;
        for(int i = 1; i <= n; i++){
            scanf("%lf%lf",&coors[i].x,&coors[i].y);
            dt = Distan(coors[i], t);
            sum += 2.0*dt;
            disa[i] = Distan(coors[i], a) - dt;
            disb[i] = Distan(coors[i], b) - dt;
            if(disb[i] < opt1){
                swap(opt1, opt2);
                swap(opt1id,opt2id);
                opt1 = disb[i];
                opt1id = i;
            }else if(disb[i] < opt2){
                opt2 = disb[i];
                opt2id = i;
            }
        }
        double ans = double(INF);
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disa[i]);
        }
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disb[i]);
        }
        for(int i = 1; i <= n; i++){
            if(i == opt1id){
                ans = min(ans, sum + disa[i]+disb[opt2id]);
            }else{
                ans = min(ans, sum + disa[i] + disb[opt1id]);
            }
        }
        printf("%.7lf",ans);
    }
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
const int mod = 1e9+7;
const int maxn = 1e5+200;
const LL INF = 0x3f3f3f3f3f3f3f3f;
struct Coor{
    double x, y;
}coors[maxn];
double Distan(Coor a, Coor b){
    return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
double disa[maxn], disb[maxn];
int main(){
    int n;
    Coor a, b, t;
    while(scanf("%lf%lf %lf%lf %lf%lf",&a.x,&a.y,&b.x,&b.y,&t.x,&t.y)!=EOF){
        scanf("%d",&n);
        double dt;
        double sum = 0;
        double opt1 = double(INF), opt2 = double(INF);
        int opt1id = 1, opt2id = 1;
        for(int i = 1; i <= n; i++){
            scanf("%lf%lf",&coors[i].x,&coors[i].y);
            dt = Distan(coors[i], t);
            sum += 2.0*dt;
            disa[i] = Distan(coors[i], a) - dt;
            disb[i] = Distan(coors[i], b) - dt;
            if(disb[i] < opt1){
                swap(opt1, opt2);
                swap(opt1id,opt2id);
                opt1 = disb[i];
                opt1id = i;
            }else if(disb[i] < opt2){
                opt2 = disb[i];
                opt2id = i;
            }
        }
        double ans = double(INF);
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disa[i]);
        }
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disb[i]);
        }
        if(n == 1){
            printf("%.6lf",ans); continue;
        }
        for(int i = 1; i <= n; i++){
            if(i == opt1id){
                ans = min(ans, sum + disa[i]+disb[opt2id]);
            }else{
                ans = min(ans, sum + disa[i] + disb[opt1id]);
            }
        }
        printf("%.6lf",ans);
    }
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
const int mod = 1e9+7;
const int maxn = 1e5+200;
const LL INF = 0x3f3f3f3f3f3f3f3f;
struct Coor{
    double x, y;
}coors[maxn];
double Distan(Coor a, Coor b){
    return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
double disa[maxn], disb[maxn];
int main(){
    int n;
    Coor a, b, t;
    while(scanf("%lf%lf %lf%lf %lf%lf",&a.x,&a.y,&b.x,&b.y,&t.x,&t.y)!=EOF){
        scanf("%d",&n);
        double dt;
        double sum = 0;
        double opt1 = double(INF), opt2 = double(INF);
        int opt1id = 1, opt2id = 1;
        for(int i = 1; i <= n; i++){
            scanf("%lf%lf",&coors[i].x,&coors[i].y);
            dt = Distan(coors[i], t);
            sum += 2.0*dt;
            disa[i] = Distan(coors[i], a) - dt;
            disb[i] = Distan(coors[i], b) - dt;
            if(disb[i] < opt1){
                swap(opt1, opt2);
                swap(opt1id,opt2id);
                opt1 = disb[i];
                opt1id = i;
            }else if(disb[i] < opt2){
                opt2 = disb[i];
                opt2id = i;
            }
        }
        double ans = double(INF);
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disa[i]);
        }
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disb[i]);
        }
        for(int i = 1; i <= n; i++){
            if(i == opt1id){
                ans = min(ans, sum + disa[i]+disb[opt2id]);
            }else{
                ans = min(ans, sum + disa[i] + disb[opt1id]);
            }
        }
        printf("%.8lf",ans);
    }
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
const int mod = 1e9+7;
const int maxn = 1e5+200;
const LL INF = 0x3f3f3f3f3f3f3f3f;
struct Coor{
    double x, y;
}coors[maxn];
double Distan(Coor a, Coor b){
    return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
double disa[maxn], disb[maxn];
int main(){
    int n;
    Coor a, b, t;
    while(scanf("%lf%lf %lf%lf %lf%lf",&a.x,&a.y,&b.x,&b.y,&t.x,&t.y)!=EOF){
        scanf("%d",&n);
        double dt;
        double sum = 0;
        double opt1 = double(INF), opt2 = double(INF);
        int opt1id = 1, opt2id = 1;
        for(int i = 1; i <= n; i++){
            scanf("%lf%lf",&coors[i].x,&coors[i].y);
            dt = Distan(coors[i], t);
            sum += 2.0*dt;
            disa[i] = Distan(coors[i], a) - dt;
            disb[i] = Distan(coors[i], b) - dt;
            if(disb[i] < opt1){
                swap(opt1, opt2);
                swap(opt1id,opt2id);
                opt1 = disb[i];
                opt1id = i;
            }else if(disb[i] < opt2){
                opt2 = disb[i];
                opt2id = i;
            }
        }
        double ans = double(INF);
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disa[i]);
        }
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disb[i]);
        }
        if(n == 1){
            printf("%.8lf",ans); continue;
        }
        for(int i = 1; i <= n; i++){
            if(i == opt1id){
                ans = min(ans, sum + disa[i]+disb[opt2id]);
            }else{
                ans = min(ans, sum + disa[i] + disb[opt1id]);
            }
        }
        printf("%.8lf",ans);
    }
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
const int mod = 1e9+7;
const int maxn = 1e5+200;
const LL INF = 0x3f3f3f3f3f3f3f3f;
struct Coor{
    double x, y;
}coors[maxn];
double Distan(Coor a, Coor b){
    return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
double disa[maxn], disb[maxn];
int main(){
    int n;
    Coor a, b, t;
    while(scanf("%lf%lf %lf%lf %lf%lf",&a.x,&a.y,&b.x,&b.y,&t.x,&t.y)!=EOF){
        scanf("%d",&n);
        double dt;
        double sum = 0;
        double opt1 = double(INF), opt2 = double(INF);
        int opt1id = 1, opt2id = 1;
        for(int i = 1; i <= n; i++){
            scanf("%lf%lf",&coors[i].x,&coors[i].y);
            dt = Distan(coors[i], t);
            sum += 2.0*dt;
            disa[i] = Distan(coors[i], a) - dt;
            disb[i] = Distan(coors[i], b) - dt;
            if(disb[i] < opt1){
                swap(opt1, opt2);
                swap(opt1id,opt2id);
                opt1 = disb[i];
                opt1id = i;
            }else if(disb[i] < opt2){
                opt2 = disb[i];
                opt2id = i;
            }
        }
        double ans = double(INF);
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disa[i]);
        }
        for(int i = 1; i <= n; i++){
            ans = min(ans, sum + disb[i]);
        }
        if(n == 1){
            printf("%.8lf",ans); continue;
        }
        for(int i = 1; i <= n; i++){
            if(i == opt1id){
                ans = min(ans, sum + disa[i]+disb[opt2id]);
            }else{
                ans = min(ans, sum + disa[i] + disb[opt1id]);
            }
        }
        printf("%.7lf",ans);
    }
    return 0;
}


#include<iostream>
#define MAX 1000024
long long int a[MAX],n,i,b,sum=0;
using namespace std;
int main()
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>b;
a[b]++;
}
for(i=0;i<MAX;i++)
{
sum+=a[i]%2;
a[i+1]+=a[i]/2;
}
cout<<sum;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<algorithm>
#define N 2000100
using namespace std;
int n,cnt;
int a[N],vis[N];
int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]++;
    }
    for(int i=0;i<2000001;i++)
    {
        vis[i+1]+=vis[i]/2;
        vis[i]=vis[i]%2;
         //printf("vis[%d]=%d  vis[%d]=%d\n",i+1,vis[i+1],i,vis[i]);
    }
    cnt=0;
    for(int i=0;i<2000001;i++)
    {
        if(vis[i]!=0)
            cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<algorithm>
#define N 2000010
using namespace std;
int n,cnt,sum;
int vis[N],a[N];
int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]++;
    }
    /*for(int i=0;i<n;i++)
    {
        printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }*/
    int i=0;
    sort(a,a+n);
    sum=a[n-1];
    while(i<n)
    {
        if(vis[a[i]]>=2)
        {

            if(vis[a[i]+1]==0)
            {
                a[n]=a[i]+1;
                sum=max(sum,a[n]);
                n=n+1;
            }
            vis[a[i]+1]++;
            vis[a[i]]=vis[a[i]]-2;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
        }
        if(vis[a[i]]<=1)
        {
            i++;
        }
    }
    cnt=0;
    for(int i=0; i<n; i++)
    {
        if(vis[a[i]]!=0)
        {
            cnt++;
            vis[a[i]]=0;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]] );
        }
    }
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<algorithm>
#define N 2000010
using namespace std;
int n,cnt,sum;
int vis[N],a[N];
int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]++;
    }
    /*for(int i=0;i<n;i++)
    {
        printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }*/
    int i=0;
    sort(a,a+n);
    sum=a[n-1];
    while(i<n)
    {
        if(vis[a[i]]<=1)
        {
            i++;
        }
        if(vis[a[i]]>=2)
        {

            if(vis[a[i]+1]==0)
            {
                a[n]=a[i]+1;
                sum=max(sum,a[n]);
                n=n+1;
            }
            vis[a[i]+1]++;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
            vis[a[i]]=vis[a[i]]-2;

        }
        //printf("vis[%d] = %d\n",a[i],vis[a[i]]);

    }
    cnt=0;
    for(int i=0; i<n; i++)
    {
        if(vis[a[i]]!=0)
        {
            cnt++;
            vis[a[i]]=0;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]] );
        }
    }
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<algorithm>
#define N 2000010
using namespace std;
int n,cnt,sum;
int vis[N],a[N];
int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]++;
    }
    /*for(int i=0;i<n;i++)
    {
        printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }*/
    int i=0;
    sort(a,a+n);
    sum=a[n-1];
    while(i<n)
    {

        if(vis[a[i]]>=2)
        {

            if(vis[a[i]+1]==0)
            {
                a[n]=a[i]+1;
                sum=max(sum,a[n]);
                n=n+1;
            }
            vis[a[i]+1]++;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
            vis[a[i]]=vis[a[i]]-2;

        }
        if(vis[a[i]]<=1)
        {
            i++;
        }
        //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }
    cnt=0;
    for(int i=0; i<n; i++)
    {
        if(vis[a[i]]!=0)
        {
            cnt++;
            //printf("a[i] = %d\n",a[i]);
            vis[a[i]]=0;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]] );
        }
    }
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<algorithm>
#define N 2000010
using namespace std;
int n,cnt,sum;
int vis[N],a[N];
int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]++;
    }
    /*for(int i=0;i<n;i++)
    {
        printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }*/
    int i=0;
    sort(a,a+n);
    sum=a[n-1];
    while(i<n)
    {

        if(vis[a[i]]>=2)
        {

            if(vis[a[i]+1]==0)
            {
                a[n]=a[i]+1;
                sum=max(sum,a[n]);
                n=n+1;
            }
            vis[a[i]+1]++;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
            vis[a[i]]=vis[a[i]]-2;

        }
        if(vis[a[i]]<=1)
        {
            i++;
        }
        //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }
    cnt=0;
    for(int i=0; i<n; i++)
    {
        if(vis[a[i]]!=0)
        {
            cnt++;
            printf("a[i] = %d\n",a[i]);
            vis[a[i]]=0;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]] );
        }
    }
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<algorithm>
#define N 2000010
using namespace std;
int n,cnt;
int vis[N],a[N],b[N];
int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        b[i]=a[i];
        vis[a[i]]++;
    }
    /*for(int i=0;i<n;i++)
    {
        printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }*/
    int i=0;
    sort(b,b+n);
    int bb=b[n-1];
    while(i<n)
    {
        if(vis[a[i]]>=2)
        {

            if(vis[a[i]+1]==0)
            {
                a[n]=a[i]+1;
                bb=max(bb,a[n]);
                n=n+1;
            }
            vis[a[i]+1]++;
            vis[a[i]]=vis[a[i]]-2;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
        }
        if(vis[a[i]]<=1)
        {
            i++;
        }
    }
    cnt=0;
    for(int i=0; i<n; i++)
    {
        if(vis[a[i]]!=0)
        {
            cnt++;
            vis[a[i]]=0;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]] );
        }
    }
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<algorithm>
#define N 2000010
using namespace std;
int n,cnt;
int vis[N],a[N],b[N];
int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        b[i]=a[i];
        vis[a[i]]++;
    }
    /*for(int i=0;i<n;i++)
    {
        printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }*/
    int i=0;
    sort(b,b+n);
    int bb=b[n-1];
    while(i<n)
    {
        if(vis[a[i]]>=2)
        {
            vis[a[i]+1]++;
            if(a[i]+1>bb)
            {
                a[n]=a[i]+1;
                bb=a[n];
                n=n+1;
            }
            vis[a[i]]=vis[a[i]]-2;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
        }
        if(vis[a[i]]<=1)
        {
            i++;
        }
    }
    cnt=0;
    for(int i=0; i<n; i++)
    {
        if(vis[a[i]]!=0)
        {
            cnt++;
            vis[a[i]]=0;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]] );
        }
    }
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<algorithm>
#define N 2000010
using namespace std;
int n,cnt,sum,ans;
int vis[N],a[N];
int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]++;
    }
    /*for(int i=0;i<n;i++)
    {
        printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }*/
    int i=0;
    sort(a,a+n);
    sum=a[n-1];
    int ans=0;
    while(i<n)
    {

        if(vis[a[i]]>=2)
        {

            if(vis[a[i]+1]==0)
            {
                a[n]=a[i]+1;
                sum=max(sum,a[n]);
                n=n+1;
                vis[a[i]+1]++;
            }
            else
            {
                if(vis[a[i]+2]==0)
            {
                a[n]=a[i]+2;
                sum=max(sum,a[n]);
                n=n+1;
            }
               vis[a[i]+2]++;
               vis[a[i]+1]=0;
            }

            //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
            vis[a[i]]=vis[a[i]]-2;

        }
        if(vis[a[i]]<=1)
        {
            i++;
        }
        //printf("vis[%d] = %d\n",a[i],vis[a[i]]);
    }
    cnt=0;
    for(int i=0; i<n; i++)
    {
        if(vis[a[i]]!=0)
        {
            cnt++;
            //printf("a[i] = %d\n",a[i]);
            vis[a[i]]=0;
            //printf("vis[%d] = %d\n",a[i],vis[a[i]] );
        }
    }
    printf("%d\n",cnt);
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
ll a[2000009];
main()
{
    FC;
    FF;
   int n;
    cin>>n;
    rep(i,0,n-1)
      {
         int x; cin>>x;
         a[x]++;
      }
      ll ans=0;
      rep(i,0,2000009)
      {
         // cout <<a[i]<<endl;
          ans+=a[i]%2;
        a[i+1]+=a[i]/2;

      }
    cout <<ans;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
set <ll> divisors(ll n)
{
	set <ll> v;
	ll i;
	for(i=1;i*i<=n;++i)
		if(n%i == 0)
			v.insert(i), v.insert(n/i);
	if(i*i == n)
		v.insert(i);
	return v;
}
bool medo(ll x)
{
   set<ll> s=divisors(x);
     for(set<ll>::iterator it = s.begin();it!=s.end();it++)
      {

        ll w=sqrt(*it);
         if(w*w==*it && *it!=1) return false;
      }
      return true;
}
bool ok(ll x)
{
    ll y=2;
 while(1)
 {
     if(y>x) return false;
     if(y==x) return true;
     y*=2;
 }

}
main()
{
    int n;
    cin>>n;
    ll a[n+1];
    ll sum[n+1];
    ll s=0;

    rep(i,0,n-1)
    {
       cin>>a[i];
      s+=a[i];
      sum[i]=s;
    }
    ll ans=0;
    rep(j,0,n-1)
    {
        bool r=1;
        if(ok(sum[n-1-j])) {ans++; break;}
        rep(i,0,n-1)
       {
        if(ok(sum[n-1-j] - sum[i] ))
          {
             ans++;
             j=i;
             r=0;
             break;
          }
        }
     if(r) ans++;
    }

   cout <<ans;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
ll a[1000009];
main()
{
    FC;
    FF;
   int n;
    cin>>n;
    rep(i,0,n-1)
      {
         int x; cin>>x;
         a[x]++;
      }
      ll ans=0;
      rep(i,0,1000009)
      {
         // cout <<a[i]<<endl;
          ans+=a[i]%2;
        a[i+1]+=a[i]/2;

      }
    cout <<ans;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
int a[1000009];
main()
{
   int n;
    cin>>n;
    rep(i,0,n-1)
      {
         int x; cin>>x;
         a[x]++;
      }
      ll ans=0;
      rep(i,0,n-1)
      {
        a[i+1]=a[i+1]+a[i]/2;
        a[i]=a[i]%2;
        ans+=a[i];
      }
    cout <<ans;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
set <ll> divisors(ll n)
{
	set <ll> v;
	ll i;
	for(i=1;i*i<=n;++i)
		if(n%i == 0)
			v.insert(i), v.insert(n/i);
	if(i*i == n)
		v.insert(i);
	return v;
}
bool medo(ll x)
{
   set<ll> s=divisors(x);
     for(set<ll>::iterator it = s.begin();it!=s.end();it++)
      {

        ll w=sqrt(*it);
         if(w*w==*it && *it!=1) return false;
      }
      return true;
}
bool ok(ll x)
{
    ll y=2;
 while(1)
 {
     if(y>x) return false;
     if(y==x) return true;
     y*=2;
 }

}
main()
{
    int n;
    cin>>n;
    ll a[n+1];
    ll sum[n+1];
    ll s=0;

    rep(i,0,n-1)
    {
       cin>>a[i];
      s+=a[i];
      sum[i]=s;
    }
    ll ans=0;
    Drep(j,n-1,0)
    {
        //cout <<"D";
        bool r=1;
        if(ok(sum[j])) {ans++; break;}
        rep(i,0,n-1)
       {
        if(ok(sum[j] - sum[i] ))
          {
             ans++;
             //cout <<"i"<<i;
             j=i+1;
             r=0;
             break;
          }
        }
     if(r) ans++;
    }

   cout <<ans;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
int a[1000009];
main()
{
   int n;
    cin>>n;
    rep(i,0,n-1)
      {
         int x; cin>>x;
         a[x]++;
      }
      ll ans=0;
      rep(i,0,1000009)
      {
         // cout <<a[i]<<endl;
          ans+=a[i]%2;
        a[i+1]+=a[i]/2;

      }
    cout <<ans;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
set <ll> divisors(ll n)
{
	set <ll> v;
	ll i;
	for(i=1;i*i<=n;++i)
		if(n%i == 0)
			v.insert(i), v.insert(n/i);
	if(i*i == n)
		v.insert(i);
	return v;
}
bool medo(ll x)
{
   set<ll> s=divisors(x);
     for(set<ll>::iterator it = s.begin();it!=s.end();it++)
      {

        ll w=sqrt(*it);
         if(w*w==*it && *it!=1) return false;
      }
      return true;
}
bool LS[1000009];
main()
{
    int n;
    cin>>n;
    ll a[n+1];
    ll sum[n+1];
    ll s=0;
    int y=2;
    while(1)
    {
        if(y>1000000)
            break;
      LS[y]=1;
      y*=2;
    }
    rep(i,0,n-1)
    {
       cin>>a[i];
      s+=a[i];
      sum[i]=s;
    }
    ll ans=0;
    rep(j,0,n-1)
    {
        bool r=1;
        if(LS[sum[n-1-j]]) {ans++; break;}
        rep(i,0,n-1)
       {
        if(LS[sum[n-1-j] - sum[i] ])
          {
             ans++;
             j=i;
             r=0;
             break;
          }
        }
     if(r) ans++;
    }

   cout <<ans;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
int a[1000009];
main()
{
   int n;
    cin>>n;
    rep(i,0,n-1)
      {
         int x; cin>>x;
         a[x]++;
      }
      ll ans=0;
      rep(i,0,n-1)
      {
        a[i+1]=a[i+1]+a[i]/2;
        a[i]=a[i]%2;
        ans+=a[i];
      }
    cout <<max(ans,(ll)1);
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
int a[1000009];
main()
{
    FC;
    FF;
   int n;
    cin>>n;
    rep(i,0,n-1)
      {
         int x; cin>>x;
         a[x]++;
      }
      ll ans=0;
      rep(i,0,1000009)
      {
         // cout <<a[i]<<endl;
          ans+=a[i]%2;
        a[i+1]+=a[i]/2;

      }
    cout <<ans;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, string > is;
typedef pair<string, string > ss;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define rep(i, a, o) \
for (int i = int(a); i <= int(o); i++)
#define Drep(i, a, o) \
for (int i = int(a); i >= int(o); i--)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define MEMSET_INF 127
#define MEMSET_HALF_INF 63
#define MOD 1000000007
#define FC cin.tie(false);cout.tie(false);
#define FF ios_base::sync_with_stdio(false)
#define All(a) (a).begin(), (a).end()
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((powl((x1-x2),2)) + (powl((y1-y2),2)));
}
int a[1000009];
main()
{
   int n;
    cin>>n;
    rep(i,0,n-1)
      {
         int x; cin>>x;
         a[x]++;
      }
      ll ans=0;
      rep(i,0,n-1)
      {
          ans+=a[i]%2;
        a[i+1]=a[i+1]+a[i]/2;

      }
    cout <<max(ans,(ll)1);
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
ll i,j,k,l,n,m,arr[1000005],mymap[5000005];
int main()
{
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
    sort(arr,arr+n);
    k=arr[0];
    l=1;
    for(i=1;i<n;i++)
    {
        if(arr[i]==k)
            l++;
        else
        {
            mymap[k]=l;
            k=arr[i];
            l=1;
        }
    }
    mymap[k]=l;
    for(i=arr[0];i<=1000111;i++)
    {
        k=mymap[i];
        k=k/2;
        mymap[i]=mymap[i]-(2*k);
        mymap[i+1]=mymap[i+1]+k;
    }
    ll ans=0;
    for(i=arr[0];i<=1000111;i++)
        ans=ans+mymap[i];
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
ll i,j,k,l,n,m,arr[1000005],mymap[5000005];
int main()
{
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
    sort(arr,arr+n);
    k=arr[0];
    l=1;
    for(i=1;i<n;i++)
    {
        if(arr[i]==k)
            l++;
        else
        {
            mymap[k]=l;
            k=arr[i];
            l=1;
        }
    }
    mymap[k]=l;
    for(i=0;i<=1000111;i++)
    {
        k=mymap[i];
        k=k/2;
        mymap[i]=mymap[i]-(2*k);
        mymap[i+1]=mymap[i+1]+k;
    }
    ll ans=0;
    for(i=0;i<=1000111;i++)
        ans=ans+mymap[i];
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
ll i,j,k,l,n,m,arr[1000005],mymap[5000005];
int main()
{
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    k=arr[0];
    l=1;
    for(i=1;i<n;i++)
    {
        if(arr[i]==k)
            l++;
        else
        {
            mymap[k]=l;
            k=arr[i];
            l=1;
        }
    }
    mymap[k]=l;
    for(i=0;i<=3000000;i++)
    {
        k=mymap[i];
        k=k/2;
        mymap[i]=mymap[i]-(2*k);
        mymap[i+1]=mymap[i+1]+k;
    }
    ll ans=0;
    for(i=0;i<=3000000;i++)
        ans=ans+mymap[i];
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
ll i,j,k,l,n,m,arr[1000005],mymap[5000005];
int main()
{
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    k=arr[0];
    l=1;
    for(i=1;i<n;i++)
    {
        if(arr[i]==k)
            l++;
        else
        {
            mymap[k]=l;
            k=arr[i];
            l=1;
        }
    }
    mymap[k]=l;
    for(i=0;i<=1000111;i++)
    {
        k=mymap[i];
        k=k/2;
        mymap[i]=mymap[i]-(2*k);
        mymap[i+1]=mymap[i+1]+k;
    }
    ll ans=0;
    for(i=0;i<=1000111;i++)
        ans=ans+mymap[i];
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
ll i,j,k,l,n,m,arr[1000005],mymap[5000005];
int main()
{
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    k=arr[0];
    l=1;
    for(i=1;i<n;i++)
    {
        if(arr[i]==k)
            l++;
        else
        {
            mymap[k]=l;
            k=arr[i];
            l=1;
        }
    }
    mymap[k]=l;
    for(i=arr[0];i<=1000111;i++)
    {
        k=mymap[i];
        k=k/2;
        mymap[i]=mymap[i]-(2*k);
        mymap[i+1]=mymap[i+1]+k;
    }
    ll ans=0;
    for(i=arr[0];i<=1000111;i++)
        ans=ans+mymap[i];
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<pair<ll,ll> >v;
vector<ll>v1;
map<ll,ll>mymap;
ll i,j,k,l,n,m,arr[1000005];
int main()
{
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    k=arr[0];
    l=1;
    for(i=1;i<n;i++)
    {
        if(arr[i]==k)
            l++;
        else
        {
            mymap[k]=l;
            k=arr[i];
            l=1;
        }
    }
    mymap[k]=l;
    for(i=0;i<=999999;i++)
    {
        k=mymap[i];
        k=k/2;
        mymap[i]=mymap[i]-(2*k);
        mymap[i+1]=mymap[i+1]+k;
    }
    ll ans=0;
    if(mymap[1000000]>1)
    {
        k=2;
        while(k<mymap[1000000])
            k=k*2;
        k=k/2;
        mymap[1000000]=mymap[1000000]-k+1;
    }
    for(i=0;i<=1000000;i++)
        ans=ans+mymap[i];
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
ll i,j,k,l,n,m,arr[1000005],mymap[1000005];
int main()
{
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    k=arr[0];
    l=1;
    for(i=1;i<n;i++)
    {
        if(arr[i]==k)
            l++;
        else
        {
            mymap[k]=l;
            k=arr[i];
            l=1;
        }
    }
    mymap[k]=l;
    for(i=0;i<=999999;i++)
    {
        k=mymap[i];
        k=k/2;
        mymap[i]=mymap[i]-(2*k);
        mymap[i+1]=mymap[i+1]+k;
    }
    ll ans=0;
    if(mymap[1000000]>1)
    {
        k=2;
        while(k<mymap[1000000])
            k=k*2;
        k=k/2;
        mymap[1000000]=mymap[1000000]-k+1;
    }
    for(i=0;i<=1000000;i++)
        ans=ans+mymap[i];
    cout<<ans;
    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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a,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;
            p=p+a;
            if(mp[a]==0)
            {
                //cout<<"first\n";
                if(flag==0)
                cnt+=flag2+1;
                p=0;
                flag2=0;
                flag=1;
            }
            else if(mp[p]==0&&mp[a]==1)
            {
                //cout<<"second\n";
                flag=0;
                cnt+=flag2+1;
                flag2=0;
                p=0;
            }
            else if(mp[p]==1&&mp[a]==1)
            {
                //cout<<"Third\n";
                flag2=1;
                flag=0;
                continue;
            }
            else
            {
                //cout<<"fourth\n";
                flag=0;
                p=a;
                cnt++;
                flag2=0;
            }//cout<<cnt<<endl;
        }
        if(flag2==1)cnt++;
        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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a,flag=0,flag2=0,flag3=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;
            if(mp[a]==0)
            {
                if(flag==0)cnt+=flag2+1;
                flag=1;
                flag2=0;
                p=0;
            }
            else if(mp[a]==1)
            {
                flag=0;
                p=p+a;
                if(mp[p]==1)
                {
                    if(flag3==0)
                    flag2=1;
                    continue;
                }
                else
                {
                    cnt+=flag2+1;
                    flag2=0;
                    flag3=1;
                    p=a;
                }
            }
        }
        if(flag2)cnt++;

        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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a,flag=0,flag2=0,flag3=0,flag4=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;
            if(mp[a]==0)
            {
                if(flag==0)cnt+=flag2+1;
                flag=1;
                flag2=0;
                p=0;
                flag4=0;
            }
            else if(mp[a]==1)
            {
                flag=0;
                p=p+a;
                if(mp[p]==1)
                {
                    if(flag3==0)
                    flag2=1;
                    flag4=1;
                }
                else
                {
                    cnt+=flag2+1;
                    flag2=0;
                    flag3=1;
                    flag4=0;
                    p=a;
                }
            }
            cout<<cnt<<endl;
        }
        if(flag4)cnt++;

        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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a;
    mp[0]=1;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)
            {
                p=a;
                cnt++;
                continue;
            }
            p=p+a;
            if(mp[p]==1)continue;
            else
            {
                p=a;
                cnt++;
            }
        }
        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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a,flag=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;
            p=p+a;
            if(mp[p]==1&&mp[a]==1)continue;
            if(mp[a]==0)
            {
                if(flag==0)
                cnt++;
                flag=1;
                continue;
            }
            else
            {
                flag=0;
                p=a;
                cnt++;
            }
        }
        if(flag==1)cnt++;
        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;
}*/
long ar[1000006];
int main()
{
    long n;
    cin>>n;
    rep(i,n)cin>>ar[i];
    sort(ar,ar+n);
    queue<long>q;
    long u,v,cnt=0;
    rep(i,n)
    q.push(ar[i]);
    while(q.size()>1)
    {
        u=q.front();q.pop();
        v=q.front();q.pop();
        if(u==v)q.push(u+1);
        else
        {
            cnt++;
            q.push(v);
        }
    }
    if(q.size()>0)cnt++;
    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()
{
    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;
                if(prev==1&&a==2)continue;
                cnt++;
                flag=0;
                prev=a;
            }
            //cout<<cnt<<endl;

        }

        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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a,flag=0,flag2=0,flag3=0,flag4=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;
            if(mp[a]==0)
            {
                if(flag==0)cnt+=flag2+1;
                flag=1;
                flag2=0;
                p=0;
                flag4=0;
            }
            else if(mp[a]==1)
            {
                flag=0;
                p=p+a;
                if(mp[p]==1)
                {
                    if(flag3==0)
                    flag2=1;
                    flag4=1;
                }
                else
                {
                    cnt+=flag2+1;
                    flag2=0;
                    flag3=1;
                    flag4=0;
                    p=a;
                }
            }
            //cout<<cnt<<endl;
        }
        if(flag4&&flag3==0)cnt++;

        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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a,flag=0,flag2=0,flag3=0,flag4=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;
            if(mp[a]==0)
            {
                if(flag==0)cnt+=flag2+1;
                flag=1;
                flag2=0;
                p=0;
            }
            else if(mp[a]==1)
            {
                flag=0;
                p=p+a;
                if(mp[p]==1)
                {
                    if(flag3==0)
                    flag2=1;
                    flag4=1;
                }
                else
                {
                    cnt+=flag2+1;
                    flag2=0;
                    flag3=1;
                    p=a;
                }
            }
            cout<<cnt<<endl;
        }
        if(flag4)cnt++;

        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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a;
    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)
            {
                p=a;
                cnt++;
                continue;
            }
            p=p+a;
            if(mp[p]==1)continue;
            else
            {
                p=a;
                cnt++;
            }
        }
        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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a,flag=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;
            p=p+a;
            if(mp[p]==1&&mp[a]==1)
            {
                if(flag==1)cnt++;
                p=a;
            }
            else if(mp[a]==0)
            {
                if(flag==0)
                cnt++;
                p=a;
                flag=1;
            }
            else
            {
                flag=0;
                p=a;
                cnt++;
            }
        }
        if(mp[p]==1)cnt++;
        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()
{
    map<long long,long>mp;
    long long i,p=1,n,cnt=0,a,flag=0,flag2=0,flag3=0,flag4=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;
            if(mp[a]==0)
            {
                if(flag==0)cnt+=flag2+1;
                flag=1;
                flag2=0;
                p=0;
                flag4=0;
            }
            else if(mp[a]==1)
            {
                flag=0;
                p=p+a;
                if(mp[p]==1)
                {
                    if(flag3==0)
                    flag2=1;
                    flag4=1;
                }
                else
                {
                    cnt+=flag2+1;
                    flag2=0;
                    flag3=1;
                    flag4=0;
                    p=a;
                }
            }
            //cout<<cnt<<endl;
        }
        if(flag4)cnt++;

        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;
    cin>>n;
    priority_queue<long>q;
    long u,v,cnt=0;
    rep(i,n)
    {
        cin>>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++;
    cout<<cnt<<endl;
    return 0;
}