#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <ctime>
#include <bits/stdc++.h>
#include <cstring>
#include <queue>
using namespace std;
#define eps 1e-7
#define PI acos(-1)
#define de(x) cout<<#x<<'='<<x<<" , "
#define dee(x) cout<<#x<<'='<<x<<endl
#define sz(x) x.size()
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define mset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define ElemtType int
#define random ((rand()&1)?1:-1)*(rand()%13*rand()^233)

typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<ui,int> puii;
typedef vector<int> vi;
int clk;
set<int >rec;
const int maxn=100005;
typedef struct AVLTreeNode Node,*AVLTree;
struct AVLTreeNode{
    AVLTree son[2];
    int height;
    ElemtType key;

    Node* newnode(ElemtType val){
        Node *p=new Node;
        if(p==NULL){
            cout<<"!!!!!!!!!!!!!!!!!!"<<endl;
            return NULL;
        }
        p->key=val;
        p->height=0;
        p->son[0]=p->son[1]=NULL;
        return p;
    }
    int getheight(AVLTree t){
        return (t==NULL?-1:t->height);
    }
    AVLTree Rotate(Node* k,int type){
        /// type==0 : left-rotate
        /// type=0, T->son[1]=0
        Node* kk=k->son[type^1];
        k->son[type^1]=kk->son[type];
        kk->son[type]=k;
        //dee(k->key),de(k->son[0]),dee(k->son[1]);
        k->height=max(getheight(k->son[0]),getheight(k->son[1]))+1;
        kk->height=max(getheight(kk->son[0]),getheight(kk->son[1]))+1;
        //dee(k->height);
        return kk;
    }
    AVLTree DoubleRotate(Node *k,int type){
        /// type==0: left-right
        k->son[type]=Rotate(k->son[type],type);
        return Rotate(k,type^1);
    }
    void insert(AVLTree &T,ElemtType val){
        if(T==NULL){
            T=newnode(val);
        }
        else if(val==T->key) return ;
        else if(val<T->key){
            insert(T->son[0],val);
            if(getheight(T->son[0])-getheight(T->son[1])==2){
                clk++;
                if(val<T->son[0]->key)
                    T=Rotate(T,1);
                else
                    T=DoubleRotate(T,0);
            }
        }
        /// 不会有重复元素
        else{
            /// insert to right subtree
            insert(T->son[1],val);
            if(getheight(T->son[1])-getheight(T->son[0])==2){
                clk++;
                if(val>T->son[1]->key){
                    T=Rotate(T,0);
                }
                else
                    T=DoubleRotate(T,1);
            }
        }
        T->height=max(getheight(T->son[0]),getheight(T->son[1]))+1;
        //dee(T->height);
    }

    AVLTree find(AVLTree T,ElemtType val){
        while(T){
            if(T->key==val) break;
            else if(T->key<val) T=T->son[1];
            else T=T->son[0];
        }
        // de(T->key);
        return T;
    }

    void Delete(AVLTree &T,const Node *const p){
        if(T==NULL||p==NULL) return;
        //dee(p->key);
        //cout<<"in"<<endl;
        if(T->key<p->key){
            //cout<<"1"<<endl;
            Delete(T->son[1],p);
            //cout<<"tmpout"<<endl;
            if(getheight(T->son[0])-getheight(T->son[1])==2){
                if(1||T->son[1]==NULL||p->key<T->son[1]->key){
            //        cout<<"here"<<endl;
                    //de(T),de(T->son[0]),dee(T->son[1]);
                    T=Rotate(T,1);
                }
                else
                    T=DoubleRotate(T,1);
            }
        }
        /// zuozishu
        else if(T->key>p->key){
          //      cout<<"2"<<endl;
            Delete(T->son[0],p);
             if(getheight(T->son[1])-getheight(T->son[0])==2){
                //clk++;
                if(1||T->son[0]==NULL||p->key>T->son[0]->key)
                    T=Rotate(T,0);
                else
                    T=DoubleRotate(T,0);
            }
        }
        else {
            //cout<<"3"<<endl;
            if(T->son[0]==NULL||T->son[1]==NULL){
                //cout<<"11"<<endl;
                T=(T->son[0]?T->son[0]:T->son[1]);
                //cout<<111<<endl;
            }
            else{
                //cout<<"22"<<endl;
                AVLTree t=T->son[0];
                while(t->son[1]) t=t->son[1];
                T->key=t->key;
                Delete(T->son[0],t);
            }
        }
        if(T!=NULL)
            T->height=max(getheight(T->son[0]),getheight(T->son[1]))+1;
        //dee(T->height);
        //cout<<"out"<<endl;
    }

    void InOrder(AVLTree T,int last){
        if(T==NULL) return ;

        clk++;

        if(T->son[0]) InOrder(T->son[0],T->key);
        //if(T->height>=10)printf("%d,%d\n",T->key,T->height);
        if(T->son[1]) InOrder(T->son[1],T->key);
    }
};

int main(){
    int n=0;
    AVLTree root=NULL;
    //for(int i=1;i<=100000;++i) root->insert(root,i);
    //root->InOrder(root,-1);
    //for(int i=12375;i;--i) root->Delete(root,root->find(root,i));
    scanf("%d",&n);

    while(n--){
        int x; scanf("%d",&x);
        Node *p;
        if(p=root->find(root,x)){
            root->Delete(root,p);
        }
        else root->insert(root,x);

    }
    clk=0;
    root->InOrder(root,-1);
    cout<<clk<<endl;
}



Measured memory_bytes: 3328