Problem:
Set: Delete

For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique.

insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.

find($x$): Report the number of $x$ in $S$ (0 or 1).

delete($x$): Delete $x$ from $S$.

Input

The input is given in the following format.

$q$
$query_1$
$query_2$
:
$query_q$

Each query $query_i$ is given by

0 $x$

or

1 $x$

or

2 $x$

where the first digits 0, 1 and 2 represent insert, find and delete operations respectively.

Output

For each insert operation, print the number of elements in $S$.

For each find operation, print the number of specified elements in $S$.

Constraints

$1 \leq q \leq 200,000$

$0 \leq x \leq 1,000,000,000$

Sample Input 1

8
0 1
0 2
0 3
2 2
1 1
1 2
1 3
0 2

Sample Output 1

1
2
3
1
0
1
3

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var q = Input.num;
        var set = new Set<int>();
        var res = new List<int>();
        while (q-- > 0)
        {
            var qq = Input.ar;
            if (qq[0] == 0)
            {
                set.Insert(qq[1]);
                res.Add(set.Count);
            }
            else if (qq[0] == 1)
                res.Add(ToInt32(set.Contains(qq[1])));
            else set.Delete(qq[1]);
        }
        if(res.Count!=0)

            WriteLine(string.Join("\n", res));
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static string[] strs(int n)
        => Enumerable.Repeat(0, n).Select(_ => read).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}
public class Set<T> where T:IComparable<T>
{
    class Node
    {
        public T Key { get; set; }
        public Node parent;
        public Node left;
        public Node right;
        public bool isRed;
        public Node(T Key = default(T),Node parent=null, Node left = null, Node right = null, bool isRed = false)
        {
            this.Key = Key;
            this.parent = parent;
            this.left = left;
            this.right = right;
            this.isRed = isRed;
        }
        public static bool operator ==(Node l, Node r)
            => ReferenceEquals(l, r);
        public static bool operator !=(Node l, Node r)
            => !ReferenceEquals(l, r);
        public override bool Equals(object obj)
            => this == (Node)obj;
        public override int GetHashCode()
            => Key.GetHashCode();
    }
    public int Count { get; private set; }
    public bool IsMulti { get; }
    private Node root;
    private Node NIL;
    public Set(bool isMulti=false)
    {
        IsMulti = isMulti;
        NIL = new Node();
        NIL.parent = NIL;
        NIL.left = NIL;
        NIL.right = NIL;
        root = NIL;
    }

    private Node Search(T value)
    {
        var z = root;
        while (z != NIL && z.Key.CompareTo(value) != 0)
            if (z.Key.CompareTo(value) == 1)
                z = z.left;
            else z = z.right;
        return z;
    }

    public T Minimum(T value)
        => Minimum(Search(value)).Key;
    private Node Minimum(Node x)
    {
        while (x.left != NIL)
            x = x.left;
        return x;
    }

    public T Maximum(T value)
        => Maximum(Search(value)).Key;
    private Node Maximum(Node x)
    {
        while (x.right != NIL)
            x = x.right;
        return x;
    }
    
    private Node Successor(Node x)
    {
        if (x.right != NIL)
            return Minimum(x.right);
        var y = x.parent;
        while (y != NIL && x == y.right)
        {
            x = y;
            y = y.parent;
        }
        return y;
    }

    private Node Predecessor(Node x)
    {
        if (x.left != NIL)
            return Maximum(x.left);
        var y = x.parent;
        while (y != NIL && x == y.left)
        {
            x = y;
            y = y.parent;
        }
        return y;
    }
    private void LeftRotate(Node x)
    {
        var y = x.right;
        x.right = y.left;
        if (y.left!=NIL)
            y.left.parent = x;
        y.parent = x.parent;
        if (x.parent == NIL)
            root = y;
        else if (x.parent.left == x)
            x.parent.left = y;
        else x.parent.right = y;
        y.left = x;
        x.parent = y;
    }

    private void RightRotate(Node x)
    {
        var y = x.left;
        x.left = y.right;
        if (y.right!=NIL)
            y.right.parent = x;
        y.parent = x.parent;
        if (x.parent == NIL)
            root = y;
        else if (x.parent.left == x)
            x.parent.left = y;
        else x.parent.right = y;
        y.right = x;
        x.parent = y;
    }

    private void TransPlant(Node u,Node v)
    {
        if (u.parent == NIL)
            root = v;
        else if (u == u.parent.left)
            u.parent.left = v;
        else u.parent.right = v;
        v.parent = u.parent;
    }

    public void Insert(T value)
        => Insert(new Node(value, NIL, NIL, NIL,true));
    private void Insert(Node val)
    {
        var y = NIL;
        var x = root;
        while (x!=NIL)
        {
            y = x;
            if (!IsMulti && val.Key.CompareTo(x.Key) == 0) return;
            else if (val.Key.CompareTo(x.Key) == -1)
                x = x.left;
            else x = x.right;
        }
        Count++;
        val.parent = y;
        if (y==NIL)
            root = val;
        else if (val.Key.CompareTo(y.Key) == -1)
            y.left = val;
        else y.right = val;

        while (val.parent.isRed)
            if (val.parent.parent.left == val.parent)
            {
                var py = val.parent.parent.right;
                if (py.isRed)
                {
                    val.parent.isRed = false;
                    py.isRed = false;
                    val.parent.parent.isRed = true;
                    val = val.parent.parent; continue;
                }
                else if (val == val.parent.right)
                {
                    val = val.parent;
                    LeftRotate(val);
                }
                val.parent.isRed = false;
                val.parent.parent.isRed = true;
                RightRotate(val.parent.parent);
            }
            else
            {
                var py = val.parent.parent.left;
                if (py.isRed)
                {
                    val.parent.isRed = false;
                    py.isRed = false;
                    val.parent.parent.isRed = true;
                    val = val.parent.parent; continue;
                }
                else if (val==val.parent.left)
                {
                    val = val.parent;
                    RightRotate(val);
                }
                val.parent.isRed = false;
                val.parent.parent.isRed = true;
                LeftRotate(val.parent.parent);
            }
        root.isRed = false;
    }

    public void Delete(T value)
    {
        var z = Search(value);
        if (z == NIL) return;
        Count--;
        var tm = z;
        var oriCol = z.isRed;
        var x = NIL;
        if (z.left == NIL)
        {
            x = z.right;
            TransPlant(z, z.right);
        }
        else if (z.right == NIL)
        {
            x = z.left;
            TransPlant(z, z.left);
        }
        else
        {
            tm = Minimum(z.right);
            oriCol=tm.isRed;
            x = tm.right;
            if (tm.parent == z)
                x.parent = tm;
            else
            {
                TransPlant(tm, tm.right);
                tm.right = z.right;
                tm.right.parent = tm;
            }
            TransPlant(z, tm);
            tm.left = z.left;
            tm.left.parent = tm;
            tm.isRed = z.isRed;
        }
        if (oriCol) return;

        while (x != root && !x.isRed)
            if (x == x.parent.left)
            {
                var w = x.parent.right;
                if (w.isRed)
                {
                    w.isRed = false;
                    x.parent.isRed = true;
                    LeftRotate(x.parent);
                    w = x.parent.right;
                }
                if (!w.left.isRed && !w.right.isRed)
                {
                    w.isRed = true;
                    x = x.parent;
                    continue;
                }
                else if (!w.right.isRed)
                {
                    w.left.isRed = false;
                    w.isRed = true;
                    RightRotate(w);
                    w = x.parent.right;
                }
                w.isRed = x.parent.isRed;
                x.parent.isRed = false;
                w.right.isRed = false;
                LeftRotate(x.parent);
                x = root;
            }
            else
            {
                var w = x.parent.left;
                if (w.isRed)
                {
                    w.isRed = false;
                    x.parent.isRed = true;
                    RightRotate(x.parent);
                    w = x.parent.left;
                }
                if (!w.left.isRed && !w.right.isRed)
                {
                    w.isRed = true;
                    x = x.parent;
                　  continue;
                }
                else if (!w.left.isRed)
                {
                    w.right.isRed = false;
                    w.isRed = true;
                    LeftRotate(w);
                    w = x.parent.left;
                }
                w.isRed = x.parent.isRed;
                x.parent.isRed = false;
                w.left.isRed = false;
                RightRotate(x.parent);
                x = root;
            }
        x.isRed = false;
    }

    public bool Contains(T value)
    {
        var x = root;
        while (x != NIL)
            if (value.CompareTo(x.Key) == 0) return true;
            else if (value.CompareTo(x.Key) == 1) x = x.right;
            else x = x.left;
        return false;
    }
}