Source Code
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <chrono>

using namespace std;

int main()
{
    int bits[100000];
    int answer = 0;
    int n;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> bits[i];
    }

    for (int i = 0; i < n; i++)
    {
        if (bits[i] == 0)
        {
            while (i < n)
            {
                i++;

                if (i == n)
                {
                    break;
                }
                if (bits[i] == 1)
                {
                    answer++;
                    break;
                }
            }
        }
        else if (bits[i] == 1)
        {
            while (i < n)
            {
                i++;
                if (i == n)
                {
                    break;
                }
                if (bits[i] == 0)
                {
                    answer++;
                    break;
                }
            }
        }
    }
    cout << answer << endl;
    return 0;
}

Copy
Tha Bits DirtyQWERTY
GNU G++17
10 ms
1.2 MB
Accepted