Algorithm


A. Magnets
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.

Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.

Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.

Output

On the single line of the output print the number of groups of magnets.

Examples
input
Copy
6
10
10
10
01
10
10
output
Copy
3
input
Copy
4
01
01
10
10
output
Copy
2
Note

The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.

The second testcase has two groups, each consisting of two magnets.



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<iostream>
using namespace std;

int main(){
  int n, count = 1;
  cin>>n;
  int arr[n];
  for(int i = 0; i < n; i++){
    cin>>arr[i];
  }
  for(int i = 0; i < n-1; i++){
    if(arr[i] != arr[i+1]){
      count++;
    }
  }
  cout<<count;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
6
10
10
10
01
10
10

Output

x
+
cmd
4
01
01
10
10
Advertisements

Demonstration


Codeforcess Solution 344-A A. Magnets ,C++, Java, Js and Python ,344-A,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+