#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;
        k->height=max(getheight(k->son[0]),getheight(k->son[1]))+1;
        kk->height=max(getheight(kk->son[0]),getheight(kk->son[1]))+1;
        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;
    }

    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];
        }
        return T;
    }

    void Delete(AVLTree &T,const Node *const p){
        if(T==NULL||p==NULL) return;
        if(T->key<p->key){
            Delete(T->son[1],p);
            /// 由于删除操作是一路向上调整的，故不需要关心祖父节点，只要单旋转就可以
            if(getheight(T->son[0])-getheight(T->son[1])==2){
                T=Rotate(T,1);
            }
        }
        else if(T->key>p->key){
            Delete(T->son[0],p);
            if(getheight(T->son[1])-getheight(T->son[0])==2){
                T=Rotate(T,0);
            }
        }
        else {
            if(T->son[0]==NULL||T->son[1]==NULL){
                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;
    }

    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;
    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