Problem:
Score : 300 points

Problem Statement

There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.

Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.

Ultimately, how many slimes will be there?

Constraints

1 \leq N \leq 10^5

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the final number of slimes.

Sample Input 1

10
aabbbbaaca

Sample Output 1

5

Ultimately, these slimes will fuse into abaca.

Sample Input 2

5
aaaaa

Sample Output 2

1

All the slimes will fuse into one.

Sample Input 3

20
xxzaffeeeeddfkkkkllq

Sample Output 3

10

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N=int.Parse(ReadLine());
        var s=ReadLine();
        var uf = new UnionFind(N);
        for (int i = 1; i < s.Length; i++)
        {
            if(s[i]==s[i-1])uf.Unite(i,i-1);
        }
        WriteLine(uf.Count);
    }
}

public class UnionFind
{
    int[] parent;
    int count;
    public int Count => count;

    public UnionFind(int length)
    {
        parent = new int[length];
        for (int i = 0; i < parent.Length; i++)
        {
            parent[i] = -1;
        }
        count = length;
    }

    public int Root(int v) => parent[v] < 0 ? v : parent[v] = Root(parent[v]);

    public bool Same(int l, int r) => Root(l) == Root(r);

    static void Swap<T>(ref T l, ref T r)
    {
        var t = l;
        l = r;
        r = t;
    }

    public bool Unite(int l, int r)
    {
        l = Root(l);
        r = Root(r);
        if (l == r) return false;
        count--;
        if (parent[l] > parent[r]) Swap(ref l, ref r);
        parent[l] += parent[r];
        parent[r] = l;
        return true;
    }

    public int Size(int v) => -parent[Root(v)];
}