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.

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.

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

NoteThe 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.

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let numOfMagnets, magnets = [], groups = 0;

rl.on('line', n => {
  if (!numOfMagnets) { numOfMagnets = n; } else {
    magnets.push(n);
    if (magnets.length === +numOfMagnets) {
      for (let i = 0; i < magnets.length; i++) {
        if (magnets[i] !== magnets[i - 1]) groups += 1;
      }
      console.log(groups);
      rl.close();
    }
  }
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let n = parseInt(readline());
    let current = '';
    let numOfGroups = 0;
    for (let i = 0 ; i < n ;i++){
        let line = readline();
        if (current != line) numOfGroups ++;
        current =line;
    }
console.log(numOfGroups);
}

function main() {
    // write code here:
    var n=Number(stdin[0]);
    var count=0;
    for(let i=1;i<=n;i++){
        if(stdin[i]!==stdin[i+1]){
            count++;
        }
    }
    console.log(count);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
    let result = 1
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 2) {
        items.forEach((el, index) => {
            if (index !== items.length - 1) {
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[next]) {
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else if (items.length === 2) {
        if (items[0] === items[1])
            result = 1
        else
            result = 2
    }
    console.log(result)
})

const readline = require("readline")

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let numberOfMagnets = 0;
let groupCounter = 0;
let counter = 0;
let temp;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));
    } else if (numberOfMagnets) {
        counter++

        if (!temp) {
            temp = input.split(" ").toString()
            groupCounter++
        }
        if (temp) {
            if (input.split(" ").toString() != temp) {
                temp = input.split(" ").toString();
                groupCounter++
            }
                if (counter === numberOfMagnets) {
                    rl.close();
                    console.log(groupCounter)
                }
        }

    }

});

// if (temp === plusMinus) {
//     groupCounter++
//     flag = true
// }
// if (temp === minusPlus) {
//     groupCounter++
//     flag = false;
// }

"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const x = readline();
 const arr = [];

 for(let n=0;n<x;n++){
     arr.push(readline());
 }

  fn(arr);
}

function fn(poles) {
  let groups = 1;

  for (let i = 1; i < poles.length; i++) {
    const prevMagnet = poles[i - 1];
    const currMagnet = poles[i];

    if (currMagnet&&prevMagnet&&prevMagnet[1] == currMagnet[0]) groups++;
  }
  console.log(groups);
  return groups;
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var mae = next();
  var output = 1;
  for(var i = 0; i < N - 1; i++){
    var ato = next();
    if(mae != ato){
      mae = ato;
      output++;
    }
  }
  myout(output);
}

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let magnetNo;
let counter = -1;
let groups = 1;
let lastChar;

rl.on('line', (input) => {
    counter++;
    if (counter === 0) {
        magnetNo = parseInt(input);
        return;
    }
    if (counter === 1) {
        lastChar = input[1];
    } else {
        let currentChar = input[0];
        groups = (currentChar === lastChar) ? groups + 1 : groups;
        lastChar = input[1];
    }

    if (counter === magnetNo) {
        rl.close();
        console.log(groups);
    }
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let magnetNo;
let counter = -1;
let inputs = [];

rl.on('line', (input) => {
    counter++;
    if (counter === 0) {
        magnetNo = parseInt(input);
        return;
    }

    inputs.push(input);
    if (counter === magnetNo) {
        rl.close();
        console.log(solve(inputs));
    }

});

const solve = (inputs) => {
    let groups = 1;

    for (let i = 0; i < inputs.length - 1; i++) {
        let mag1 = inputs[i];
        let mag2 = inputs[i + 1];
        if (mag1[1] === mag2[0]) groups++;
    }
    return groups;
};

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let isFirstLine = true;
let noOfGroups = 0;
let prevLineCode = null;

rl.on("line", function (line) {
  if (!isFirstLine) {
    const lineCode = line == "10" ? 1 : 0;
    if (lineCode !== prevLineCode) {
      noOfGroups++;
      prevLineCode = lineCode;
    }
  } else {
    isFirstLine = false;
  }
});

rl.on("close", function () {
  console.log(noOfGroups);
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const n = readline();
  let result = 1;
  let prev = readline();
  for (let i = 1; i < n; i++) {
    const cur = readline();
    if (cur !== prev) {
      result++;
      prev = cur;
    }
  }
  // output
  print(result);
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let prev = -1;
let ans = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (prev !== d) {
    prev = d;
    ans++;
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    const inputs = readline();
    let array=[];
    let groups =0;
    for (let i=0 ;i< inputs;i++){
        array[i] = readline();
    }

    for (let i=0 ;i< array.length;i++){
       if(array[i]!== array[i+1]){
           groups++
       }
    }

    console.log(groups);

    return;
}

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let answer = 0, last = null;
  input.forEach((line, i) => {
    if (i === 0) return;

    if (last === null) {
      answer += 1;
    }

    if (last === '0' && line[0] === '0') answer += 1;
    if (last === '1' && line[0] === '1') answer += 1;
    last = line[1];
  });

  console.log(answer);
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readline.on('line', line => input.push(line));

readline.on('close', () => {
    const n = parseInt(input.shift());
    const magnites = input;

    let islands = 1;
    for (let i = 1; i < magnites.length; i++) {
        if(magnites[i] === magnites[i - 1]) continue;
        else islands++;
    }

    console.log(islands);
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    // if(Array.isArray(inputString)) inputString = inputString.join('\n');
    inputString += inputStdin;
    // inputString = inputString.trim().split('\n').map(string => {
    //     return string.trim();
    // });

    // main();
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function readAsInt(){
  return parseInt(readline());
}

function readAsIntList(){
  return readline().trim().split(' ').filter(i => i).map(i => parseInt(i));
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  let n = readAsInt();
  let lastpole = null;
  let total = 0;
  for(let i = 1; i <= n; i++ ){
    let pole = readAsInt() === 10;
    total += i > 1 ? (pole === lastpole ? 0 : 1) : 1;
    lastpole = pole;
  }
  console.log(total);
}

/**
 * @author Sunwarul
 * Software Developer
*/

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStd => {
    inputString += inputStd;
});
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => {
        return str.trim();
    });
    main();
});

function readLine() {
    return inputString[currentLine++];
}

function main() {
	const n = +(readLine());
	let sum = 1;
	const magnets = [];
	for(let i = 0; i < n ; i++) {
		magnets[i] = readLine();
	}

	for(let i = 0; i < n - 1; i++) {
		if(magnets[i] !== magnets[i+1]) {
			++sum;
		}
	}

	console.log(sum);
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let currentLine = 0;
let inputString = "";

process.stdin.on("data", (raw_data) => {
  inputString += raw_data;
});

process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readLine() {
  return inputString[currentLine++];
}

/******** Main function*************/

function isLowerCase(str) {
  return str == str.toLowerCase() && str != str.toUpperCase();
}

function main() {
  var n = +readLine();
  var arr = [];
  for (var j = 0; j < n; j++) {
    var m = +readLine();
    arr.push(m);
  }

  var count = 1;

  for (var i = 0; i < n - 1; i++) {
    if (arr[i] != arr[i + 1]) {
      count++;
    }
  }
  console.log(count);
}

// Determine the number of groups that the magnets formed.

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0;
});
for (let i = 0; i < txt.length; i ++) {
    if(!isNaN(txt[i]*1)){
        let tab=[];
        for (let i1 = i+1; i1 < i+1+txt[i]*1; i1++) {
            tab.push(txt[i1]);

        }
        doit(tab);
        i+=txt[i]*1;
    }
}

function doit(tab) {
  let groups=1;
    tab.forEach((data,index)=>{
        if(tab[index+1]){
        if(data[1]==tab[index+1][0])++groups;
        }
    });
    console.log(groups);

}

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {
    let inputs = str.trim().split('\n');
    let magnetArr = inputs.slice(1);
    let count = 1;
    let groups = parseInt(magnetArr[0].trim(), 2);

    for (let i = 1; i < magnetArr.length; i++) {
        let group = parseInt(magnetArr[i].trim(), 2);
        if (group !== groups) {

            groups = parseInt(magnetArr[i].trim(), 2);
            count++;
        }
    }
    return count.toString();
}

var readline = require("readline")
var rl = readline.createInterface(process.stdin,process.stdout);
var n;
var l=0;
var magnets = [];
var groups = 1;
rl.question('',function(data){
      n = parseInt(data);
      //rl.prompt()
      rl.on("line",function(mag){
            magnets.push(mag.toString().trim())
            l++;
            if(l == n){
                  rl.close();
            }
      });
})
rl.on('close',function(){
      for (let i = 0; i < n-1; i++) {
            //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));
            if (magnets[i].charAt(1)==magnets[i+1].charAt(0)){
                  groups++;
            }
      }
      if(groups > 0){
            console.log(groups);
      } else {
            console.log(groups+1);
      }
})

const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
});
let counter = 0;
let isFirstLine = true;
let previousMagnet = null;
rl.on("line", function (magnet) {
  if (isFirstLine) {
    isFirstLine = false;
    return;
  }
  if (magnet !== previousMagnet) {
    counter++;
    previousMagnet = magnet;
  }
});

rl.on("close", function () {
  console.log(counter);
});

const readLine = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));
const magnets = () => {
    let ar = [];
    let count = 0;
    let q = +input.shift();
    for (const x of input) {
        for (const y of x) {
            ar.push(+y);
        }
    };

    for (let i = 1; i < ar.length; i++) {
        if (ar[i] === ar[i-1]) {
            count++;
        }
    }
    console.log(count+1);

};

readLine.on('close', magnets);

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function main() {
    let n = parseInt(readLine());
    let a = readLine();
    let ans = 1;
    for (var i = 0; i < n - 1; i++) {
        let b = readLine();
        if (a != b) {
            ans++;
            a = b;
        }
    }
    console.log(ans);
}

var n=+readline();
var ans=0;
var prev='';
while(n--){
	var now = readline();
	if(now!=prev){
		prev=now;
		ans++;
	}
}
print(ans);

var n = +readline(), m = [], counter = 0;
for(i = 0; i < n; i++){
	m.push(readline());
}

for(i = 0; i < n-1; i++){
	if(m[i][1] != m[i+1][0]){
		continue;
	}
	else{
		counter++;
	}
}
write(counter+1);

var x= parseInt(readline())-1;

var now = readline();
var grps=0;

var prev;

while(x--){
  var prev= now;
  var now=readline();
  if(now[0] === prev[1]){
    grps++;
  }
}

print(++grps);

var n = +readline();
var res = + (n > 0);
var last = 'x';

while (n) {
    var str = readline();
    if (str[0] === last) res++;
    last = str[1];
    n --;
}

print(res);

var m = 1;
var input=[];
var n = parseInt(readline());
input[0] = readline();
for(var i=1 ; i<n ;i++){
    input[1]=readline();
    if(input[0].charAt(1) == input[1].charAt(0)){
        m++;
    }
    input[0]=input[1];

}
print(m);

var m = 1;
var x, y;
var n = parseInt(readline());
x = readline();
for(var i=1 ; i<n ;i++){
    y=readline();
    if(x.charAt(1) == y.charAt(0)){
        m++;
    }
    x=y;

}
print(m);

var m = 0;
var x="";
var y;
var n = parseInt(readline());

for(var i=0 ; i<n ;i++){
    y=readline();
    if(x != y){
        x=y
        m++;
    }
}
print(m);

var m = 1;
var x, y;
var n = parseInt(readline());
x = readline();
for(var i=1 ; i<n ;i++){
    y=readline();
    if(x.localeCompare(y) !== 0){
        m++;
    }
    x=y;
}
print(m);

check = "00";
counter = 0;
num = Number(readline())
for (i = 0 ; i<num;i++){
    var x = readline();
    if (x!= check){counter++;check = x;}
}
print(counter)

function main(){
    var n = +readline();
    var prev;
    var res = 1;
    for(var i = 0; i < n; ++i){
        var num = readline();
        if(!prev){
            prev = num;
            continue;
        }
        if(prev !== num) ++res;
        prev = num;
    }

    print(res);
}

main();

var n = readline();
var Magnet_type = " ";
var counter = 0;
 for(var i = 0; i < n; i++){
   var read = readline();
   if(Magnet_type != read){
     Magnet_type = read;
     counter++
   }
 }
 print(counter);

var n = parseInt(readline());
var str = readline();
var sum = 0;
for(var i = 1; i < n; ++i)
{
    var temp = readline();
    if(temp != str){sum ++;}
    str = temp;
}
print(sum+1);

var n = readline();

var counter = 1;

var firstMagnit = readline();

for (var i = 0; i < (n - 1); i++) {

    var secondeMagnit = readline();

    if (firstMagnit != secondeMagnit) {
        counter += 1;
    }

    firstMagnit = secondeMagnit;

}

print(counter);

var n = readline();

var magnits = [];

for (var i = 0; i < n; i++) {
    magnits.push(readline());
}

var counter = 1;

for (var i = 0; i < (n - 1); i++) {

    if (magnits[i][1] === magnits[i + 1][0]) {
        counter += 1;
    }

}

print(counter);

var n = readline();

var magnits = [];

for (var i = 0; i < n; i++) {
    magnits.push(readline());
}

var counter = 1;

for (var i = 0; i < (n - 1); i++) {

    if (magnits[i] != magnits[i + 1]) {
        counter += 1;
    }

}

print(counter);

  var inputs = readline();
  var groupCounter = 0;
  var previousMagnet = -1;
  for (var i = 0; i < inputs; i++) {
    var line = readline();
    if (line[0] !== previousMagnet) {
      groupCounter += 1;
      previousMagnet = line[0];
    }
  }

  print(groupCounter);

var line1 = readline();

var groupCount = 0, magent, prevMagnet = readline();
for(var i = 1; i < line1; i++) {
    magnet = readline();

    if(magnet != prevMagnet) {
        groupCount++;
    }
    prevMagnet = magnet;
}
print(groupCount + 1);

var noOfMagnets=Number(readline());
var counter=0;
var firstValue;
var secondValue;

for(var i =0 ; i< noOfMagnets ; i++ )
{
    firstValue=Number(readline());
   if(firstValue != secondValue){
       counter=counter+1;
       secondValue = firstValue;
   }

}

print(counter);

var input = parseInt(readline());
var count = 0;
var prev;
while(input>0){
    var ins = readline();
    if(!prev || prev != ins){
        count++;
        prev = ins;
    }
    input--;
}
print(count);

;(function () {
	var n = +readline();
	var t = readline();
	var r;
	var x = 1;

	for (var i = 1; i < n; i++) {
		r = readline();
		if (t[1] == r[0]){
			x++;
			t = r;
		}
	}

	print(x);
}).call(this);

var size = readline(),
	counter = 0,
	hasChanged = false,
	lastMagnet = undefined;

for(var index = 0; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet !== currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet;
	}
}

print(counter);

var res = sol(readline());
print(res);

function sol(line) {

    var input = line.split(" ");

    var n = input[0];

    var prev = "";
    var group = 0;

    while(n > 0){
        var magnet = readline();

        if(prev != magnet){
            prev = magnet;
            group++;
        }

        n--;
    }

    return group;
}

var n = Number(readline());
var count = 0;
var prevStr = '';
for(var i = 0; i < n; i++) {
    var str = readline();
    if (str !== prevStr) {
        count++;
    }
    prevStr = str;
}
print(count);

var toInt = x => parseInt(x);
var toInput = () => readline();
var result = 1;
var toGroups = (a, b) => {
    result+= (a!==b);
    return b;
};
new Array(parseInt(readline())).fill('')
    .map(toInput).reduce(toGroups);

print(result);

'use strict';
let n = parseInt(readline()),
    array = new Array(n);

for (let i = 0; i < n; i++) {
    array[i] = readline();
}

write(array.join('').split('00').join(' ').split('11').join(' ').split(' ').length);

n = readline();
var ans = 0,
    u = "";
for (var i = 0; i < n; i++) {
    x = readline();
    if (x != u) {
        u = x;
        ans++;
    }
}
print(ans)

var n = readline(),
        p = readline(),
        count = 1;
for (var i = 1; i < n; i++) {
        var k = readline();
        if (k != p) count++;
        p = k;
}
print(count);

var n = readline();
var temp = 0;
var res = 0;
	for (var i=0; i<+n; i++){
		var str = readline();
		if (str!=temp) res++;
		temp = str;
	}
	print(res);

var limit = parseInt(readline())
var previous = readline()
limit--
var count = 1
while(limit > 0){
    var current = readline()
    if(current != previous){
        count++
    }

    previous = current
    limit--
}

print(count)

var line = readline();
var input = [];
var result = 0;
for(var i = 0; i < line; i++) {
   input[i] = readline();
}

for(var i = 1; i < input.length; i++) {
    if(input[i] != input[i-1]){
        result ++;
    }
}
print(result + 1);

var n = readline()
var q = "", z = 0
for (var i = 0; i < n; i++) {
	var s = readline()
	if (s != q) {
		q = s
		z++
	}
}
print(z)

var n = Number(readline());

var magn = [];
var islands = 0, k = 0;
for (var i=0; i< n; i++) {
    var s = readline();
    magn.push(s);
}

for (var j = 0; j < magn.length; j++) {
    if (magn[j] === magn[j+1]) {
        k++;
        continue;
    }
    else {
        islands++;
        k = 0;
    }
}
print(islands)

var n_imanes = readline();
var comparador = "";
var grupos = 0;
for (var i = 0; i < n_imanes; i++) {
	var polo = readline();
	if (polo != comparador) {
		comparador = polo;
		grupos++;
	}
}
print(grupos);

var n_imanes = readline()
var comparador = "";
var grupos = 0;
for (var i = 0; i < n_imanes; i++) {
	var polo = readline();
	if (polo != comparador) {
		comparador = polo;
		grupos++;
	}
}
print(grupos);

var arr = [], count = 1, inputs, ch = ' ';
inputs = readline();

while (inputs !== 0) {

    arr = readline();
    if (arr[0] === ch) {
        count++;
    }
    ch = arr[1];
    inputs--;
}
print(count);

var inputs = readline();
  var groupCounter = 0;
  var previousMagnet = -1;
  for (var i = 0; i < inputs; i++) {
    var line = readline();
    if (line[0] !== previousMagnet) {
      groupCounter += 1;
      previousMagnet = line[0];
    }
  }

  print(groupCounter);

var numLines = readline();
var lastLine = '';
var blocks = 0;
for(var i = 0; i < numLines; i++)
{
    var currentLine = readline();
    if(currentLine !== lastLine) blocks++;
    lastLine = currentLine;
}

print(blocks);

var n = parseInt(readline());
var gr = 0;
var prev = null;
for (var i = 0; i < n; i++){
  var inp = readline();
  if (!prev || inp[0] == prev[1]){
    gr++;
  }
  prev = inp;
}
print (gr);

var main = function(arr)
{
    var c = 1;
    for (var i = 1; i < arr.length; i++)
    {
       if (arr[i] !== arr[i - 1]) c++;
    }
    return c;
}

{
    var num = readline();
    var arr = [];
    for (var i = 1; i <= +num; i++)
    {
        var aElem = readline();
        arr.push(aElem);
    }
    if (arr.length === 0) print(0);
    else
    print(main(arr));
}

var num=parseInt(readline());
// print(num)
var arr=[];

for(var i=0;i<num;i++){
  var mag=(readline());
  arr.push(mag)

}

var count=0;
var mag_check=arr[0];

for(var j=0;j<arr.length;j++){
  if(mag_check==arr[j+1]){
    count=count;
    mag_check=arr[j+1];
  }else{
    count=count+1;
    mag_check=arr[j+1];
  }
}
print(count);

var magnetNum=parseInt(readline());
var num=[readline()];
var groupNum=1;
for(i=1;i<magnetNum;i++){
  num[i]=readline();
  if(num[i-1]!=num[i])
   groupNum++;
}

print(groupNum)

  var n = readline();
  var magnets = [];
  var c = 1;
  for(var i = 0; i < n; i++)
  {
    var x = readline();
    magnets.push(x);
  }

  for(var i = 1; i < n; i++)
  {
    if(magnets[i] != magnets[i-1])
    {
      c++;
    }
  }
  print(c);

n = parseInt(readline()), r = 0
v = ""
while (n--) {
	u = readline()
	if (u != v)
		v = u, r++
}
print(r)

var n = parseInt(readline(), 10),
    magnet = [],
    group = 1;

for(var i=0; i<n; i++) {
    magnet.push(readline().split(''));
    if(i !== 0) {
        if(magnet[i-1][1] === magnet[i][0]) group++;
    }
}

print(group);

n = readline();
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = +readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

var n = readline();
var x ="";
var y = 0;
for(var i = 0; i<n; i++){
    var s = readline();
    if (s != x){
        x = s;
        y++;
    }
}
print(y);

var r = readline();
var s=1;
var x1 =readline();
for(var i = 0; i< r-1;i++){
    var x2 = readline();
    if (x1[1] == x2[0]){
        s++;
    }
    x1=x2;
}
print(s);

var n = readline();
var magnets = [], counter = 1;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === (arr[index+1] ? arr[index+1][0] : null)) counter++;
})
print(counter);

var count = readline();
var read = new Array(count-1);var calc=0;

for(var x = 0;x<count;x++){read[x] = readline();}

for(var i = 0;i<count;i++){
	if(i > 0){if(read[i][0] == read[i - 1][1]){calc+=1}}
}

print(calc + 1);

var nums = parseInt(readline());

var prev = null;
var block = 0; //block not gap
for (var i = 0; i < nums; i++) {
    var current = parseInt(readline());

    if (current !== prev) {
        block++;
    }

    prev = current;
}

print(block);

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var n=parseInt(readline());
var arr=[];
for(var i=0;i<n;i++){
    arr.push(readline());
}

var group=1;
for(var i=1;i<n;i++){
    var s=arr[i];
    var s1=arr[i-1];
   if(s1[s1.length-1]!=s[0]){

   }else{
       group++;
   }
};
print(group);

var numbersMagnetDomino = +readline();
var prevDomino = "";
var numbersDominoIsland = 0;
for (var stepDomino = 0; stepDomino<numbersMagnetDomino; stepDomino++) {
    var magnetDomino = readline();
    if (prevDomino!==magnetDomino) {
        numbersDominoIsland++;
        prevDomino = magnetDomino;
    }
}
print(numbersDominoIsland);

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let n = parseInt(readline());
    let current = '';
    let numOfGroups = 0;
    for (let i = 0 ; i < n ;i++){
        let line = readline();
        if (current === line) numOfGroups ++;
        current =line;
    }
console.log(numOfGroups);
}

function main() {
    // write code here:
    var n=Number(stdin[0]);
    var count=0;
    for(let i=1;i<=n;i++){
        if(stdin[i]===stdin[i+1]){
            count++;
        }
    }
    console.log(count);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
    let result = 0
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 2) {
        items.forEach((el, index) => {
            if (index > 0) {
                const prev = index - 1
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[prev]) {
                        views[prev] = 'true'
                        result++
                    } else if (el !== items[next]) {
                        views[next] = 'true'
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else if (items.length === 2) {
        result = 2
    } else {
        result = 1
    }
    console.log(result)
})

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
    let result = 0
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 2) {
        items.forEach((el, index) => {
            if (index > 0) {
                const prev = index - 1
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[prev]) {
                        views[prev] = 'true'
                        result++
                    }
                    if (el !== items[next]) {
                        views[next] = 'true'
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else if (items.length === 2) {
        if (items[0] === items[1])
            result = 1
        else
            result = 2
    } else {
        result = 1
    }
    console.log(result)
})

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
    let result = 0
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 2) {
        items.forEach((el, index) => {
            if (index > 0) {
                const prev = index - 1
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[prev]) {
                        views[prev] = 'true'
                        result++
                    } else if (el !== items[next]) {
                        views[next] = 'true'
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else if (items.length === 2) {
        if (items[0] === items[1])
            result = 1
        else
            result = 2
    } else {
        result = 1
    }
    console.log(result)
})

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
    let result = 0
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 1) {
        items.forEach((el, index) => {
            if (index > 0) {
                const prev = index - 1
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[prev]) {
                        views[prev] = 'true'
                        result++
                    } else if (el !== items[next]) {
                        views[next] = 'true'
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else {
        result = 1
    }
    console.log(result)
})

const readline = require("readline")

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let numberOfMagnets = 0;
let plusMinus = "01";
let minusPlus = "10";
let groupCounter = 0;
let flag = false;
let counter = 0;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));

        //console.log(typeof(numberOfMagnets),numberOfMagnets)
    }
    if (numberOfMagnets) {
        counter++;
        let temp = input.split(" ").toString();
        if (temp === plusMinus && flag === false) {
            groupCounter++
            flag = true
        }
        if (temp === minusPlus && flag === true) {
            groupCounter++
            flag = false;
        }

        if (counter > numberOfMagnets) {
            rl.close();
            console.log(groupCounter)
        }
    }

});

const readline = require("readline")

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let numberOfMagnets = 0;
let plusMinus = "01";
let minusPlus = "10";
let groupCounter = 0;
let flag = true;
let counter = 0;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));
        //console.log(typeof(numberOfMagnets),numberOfMagnets)
    } else if (numberOfMagnets) {
        counter++;
        let temp = input.split(" ").toString();
        switch (temp) {
            case minusPlus:
                if(flag === true)
                groupCounter++ , flag= false;
                break;
            case plusMinus :
                if(flag === false)
                groupCounter++ , flag= true;

                break;
            default:
                break;
        }

        if (counter === numberOfMagnets) {
            console.log(counter, "\n")
            rl.close();
            console.log(groupCounter)
        }
    }

});

// if (temp === plusMinus) {
    //     groupCounter++
    //     flag = true
    // }
    // if (temp === minusPlus) {
    //     groupCounter++
    //     flag = false;
    // }

const readline = require("readline")

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let numberOfMagnets = 0;
let plusMinus = "01";
let minusPlus = "10";
let groupCounter = 0;
let flag = false;
let counter = 0;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));
        rl.pause();
        //console.log(typeof(numberOfMagnets),numberOfMagnets)
    }
    if (numberOfMagnets) {
        rl.resume();
        counter++;
        let temp = input.split(" ").toString();
        if (temp === plusMinus && flag === false) {
            groupCounter++
            flag = true
        }
        if (temp === minusPlus && flag === true) {
            groupCounter++
            flag = false;
        }

        if (counter > numberOfMagnets) {
            rl.close();
            console.log(groupCounter)
        }
    }

});

const readline = require("readline")

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let numberOfMagnets = 0;
let plusMinus = "01";
let minusPlus = "10";
let groupCounter = 0;
let flag = true;
let counter = 0;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));
        //console.log(typeof(numberOfMagnets),numberOfMagnets)
    } else if (numberOfMagnets) {
        counter++;
        let temp = input.split(" ").toString();
        switch (temp) {
            case minusPlus:
                if(flag === true)
                groupCounter++ , flag= false;
                break;
            case plusMinus :
                if(flag === false)
                groupCounter++ , flag= true;

                break;
            default:
                break;
        }

        if (counter === numberOfMagnets) {
            //console.log(counter, "\n")
            rl.close();
            console.log(groupCounter)
        }
    }

});

// if (temp === plusMinus) {
    //     groupCounter++
    //     flag = true
    // }
    // if (temp === minusPlus) {
    //     groupCounter++
    //     flag = false;
    // }

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let magnetNo;
let counter = 0;
let lastChar = '';
let groups = 1;

rl.on('line', (input) => {
    if (counter === 0) {
        magnetNo = parseInt(input);
        counter++;
        return;
    }
    if (counter === magnetNo) {
        rl.close();
        console.log(groups);
        return;
    }
    counter++;
    let currentChar = input[0];
    groups = (lastChar === '' || lastChar !== currentChar) ? groups : groups + 1;
    lastChar = input[1];

});

const solve = () => {

};

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let currentLine = 0;
let inputString = "";

process.stdin.on("data", (raw_data) => {
  inputString += raw_data;
});

process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readLine() {
  return inputString[currentLine++];
}

/******** Main function*************/

function isLowerCase(str) {
  return str == str.toLowerCase() && str != str.toUpperCase();
}

function main() {
  var n = +readLine();
  var arr = [];
  for (var i = 0; i < n; i++) {
    var m = +readLine();
    arr.push(m);
  }

  var newArr = [];
  var count = 0;

  for (var j = 0; j < n; j++) {
    if (arr[j] == arr[j + 1]) {
      count++;
    } else {
      newArr.push(count);
      count = 0;
    }
  }

  var max = Math.max(...newArr) + 1;
  console.log(max);
}

// either it only contains uppercase letters;
// or all letters except for the first one are uppercase.

var readline = require("readline")
var rl = readline.createInterface(process.stdin,process.stdout);
var n;
var l=0;
var magnets = [];
var groups = 0;
rl.question('',function(data){
      n = parseInt(data);
      //rl.prompt()
      rl.on("line",function(mag){
            magnets.push(mag.toString().trim())
            l++;
            if(l == n){
                  rl.close();
            }
      });
})
rl.on('close',function(){
      for (let i = 0; i < n-1; i++) {
            //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));
            if (magnets[i].charAt(1)!=magnets[i+1].charAt(0)){
                  groups++;
            }
      }
      if(groups > 0){
            console.log(groups);
      } else {
            console.log(groups+1);
      }
})

var readline = require("readline")
var rl = readline.createInterface(process.stdin,process.stdout);
var n;
var l=0;
var magnets = [];
var groups = 0;
rl.question('',function(data){
      n = parseInt(data);
      //rl.prompt()
      rl.on("line",function(mag){
            magnets.push(mag.toString().trim())
            l++;
            if(l == n){
                  rl.close();
            }
      });
})
rl.on('close',function(){
      for (let i = 0; i < n-1; i++) {
            //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));
            if (magnets[i].charAt(1)!=magnets[i+1].charAt(0)){
                  groups++;
            }
      }
      console.log(groups);
})

var readline = require("readline")
var rl = readline.createInterface(process.stdin,process.stdout);
var n;
var l=0;
var magnets = [];
var groups = 0;
rl.question('',function(data){
      n = parseInt(data);
      rl.prompt()
      rl.on("line",function(mag){
            magnets.push(mag.toString().trim())
            l++;
            if(l == n){
                  rl.close();
            }
      });
})
rl.on('close',function(){
      for (let i = 0; i < n-1; i++) {
            //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));
            if (magnets[i].charAt(1)!=magnets[i+1].charAt(0)){
                  groups++;
            }
      }
      console.log(groups);
})

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function main() {
    let n = parseInt(readLine());
    let a = readLine();
    let ans = 1;
    for (var i = 0; i < n; i++) {
        let b = readLine();
        if (a != b) {
            b = a;
            ans++;
        }
    }
    console.log(ans);
}

var n = +readline();
var res = 0;
var last = 'x';

while (n) {
    var str = readline();
    if (str[0] === last) res++;
    last = str[1];
    n --;
}

var n = +readline();
var res = 0;
var last = 'x';

while (n) {
    var str = readline();
    if (str[0] === last) res++;
    last = str[1];
    n --;
}

print(res);

var m = 0;
var x="";
var y;
var n = parseInt(readline());

for(var i=0 ; i<n ;i++){
    y=readline();
    print('i='+i+" x="+x +" y="+y+" m="+m);
    if(x != y){
        x=y
        m++;
    }
    print('i='+i+" x="+x +" y="+y+" m="+m);
}
print(m);

var noOfMagnets=Number(readline());
var counter=0;
var firstValue;
var secondValue;

for(var i =0 ; i< noOfMagnets ; i++ )
{
   if(firstValue != secondValue){
       counter=counter+1;
       secondValue = firstValue;
   }

}

print(counter);

var input = parseInt(readline());
var count = 0;
var prev;
while(input>0){
    var ins = readline();
    if(!prev) prev = ins;
    else if(prev != ins)count++;
    input--;
}
print(count);

var input = parseInt(readline());
var count = 0;
var prev;
while(input>0){
    var ins = readline();
    if(!prev) prev = ins;
    else if(prev != ins){
        count++;
        prev = ins;
    }
    input--;
}
print(count);

var size = readline(),
	counter = 0,
	hasChanged = false,
	lastMagnet = readline();

for(var index = 1; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet === currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet.split("").reverse().join("");
	}
}

print(counter);

/*var size = readline(),
	counter = 1,
	hasChanged = false,
	lastMagnet = readline();

for(var index = 1; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet === currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet;
	}
}

print(counter);*/

print(readline()/2)

/*var size = readline(),
	counter = 1,
	hasChanged = false,
	lastMagnet = readline();

for(var index = 1; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet === currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet;
	}
}

print(counter);*/

print(Math.ceil(readline()/2))

var size = readline(),
	counter = 0,
	hasChanged = false,
	lastMagnet = undefined;

for(var index = 0; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet === currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet;
	}
}

print(counter);

var n = Number(readline());
var count = 1;
for(var i = 0; i < n; i++) {
    var str = readline();
    if (i!==0 && str[i] !== str[i-1]) {
        count++;
    }
}
print(count);

var n = readline();
var temp = 0;
var res = 1;
	for (var i=0; i<+n; i++){
		var str = readline();
		if (str!=temp) res++;
		temp = str;
	}
	print(res);

var arr = [], count = 0, inputs, ch = ' ';
inputs = readline();

while (inputs !== 0) {

    arr = readline();
    if (arr[0] === ch) {
        count++;
    }
    ch = arr[1];
    inputs--;
}
print(count);

var numLines = readline();
var lastLine = '';
var blocks = 0;
for(var i = 0; i < numLines; i++)
{
    var currentLine = readline();
    if(currentLine !== lastLine) blocks++
}

print(blocks);

var main = function(arr)
{
    var c = 0;
    for (var i = 1; i < arr.length; i++)
    {
       if (arr[i] !== arr[i - 1]) c++;
    }
    return c;
}

{
    var input1 = readline(), arr = [];
    for (var i = 1; i <= +input1; i++)
    {
        var aElem = readline();
        arr.push(aElem);
    }
    print(main(arr))
}

var main = function(arr)
{
    var c = 0;
    for (var i = 1; i < arr.length; i++)
    {
       if (arr[i] !== arr[i - 1]) c++;
    }
    return c;
}

{
    var inopt = readline();
    var input1 = readline(), arr = [];
    for (var i = 1; i <= +input1; i++)
    {
        var aElem = readline();
        arr.push(aElem);
    }
    print(main(arr))
}

var main = function(arr)
{
    var c = 1;
    for (var i = 1; i < arr.length; i++)
    {
       if (arr[i] !== arr[i - 1]) c++;
    }
    return c;
}

{
    var inopt = readline();
    var input1 = readline(), arr = [];
    for (var i = 1; i <= +input1; i++)
    {
        var aElem = readline();
        arr.push(aElem);
    }
    print(main(arr))
}

var num=parseInt(readline());
// print(num)
var arr=[];

for(var i=0;i<num;i++){
  var mag=(readline());
  arr.push(mag)

}

print(arr);
var count=0;
var mag_check=arr[0];

for(var j=0;j<arr.length;j++){
  if(mag_check==arr[j+1]){
    count=count;
    mag_check=arr[j+1];
  }else{
    count=count+1;
    mag_check=arr[j+1];
  }
}
print(count);

n = readline().split('').map(function(item) {
    return parseInt(item);
});
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

n = readline().split('').map(Number);
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

n = +readline().split('').map(Number);
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = +readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

n = readline().split('').map(function(item) {
    return parseInt(item, 10);
});
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

const main = () => {
  const n = readline();
  const arr = [];
  var total = 1;

  for (i of Array(Number(n))
    .fill()
    .map((a, b) => parseInt(b))) {
    arr.push(readline());
  }

  for (i of Array(Number(n - 1))
    .fill()
    .map((a, b) => parseInt(b))) {
    if (arr[i] != arr[i + 1]) {
      total++
    }
  }

  print(total);
};

var r = readline();
var s=0;
var x1 =readline();
for(var i = 0; i< r-1;i++){
    var x2 = readline();
    if (x1[1] == x2[0]){
        s++;
    }
    x1=x2;
}
print(s);

var r = readline();
var s=0;
var x1 =readline();
for(var i = 0; i< r-1;i++){
    var x2 = readline();
    if (x1[1] == x2[0]){
        s++;
    }
}
print(s);

var r = readline();
var s=0;
var x1 =readline();
for(var i = 0; i< r-1;i++){
    var x2 = readline();
    if (x1[1] == x2[0]) {
        s++;
    }
}
print(s);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
    print(typeof magnets[0])
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1]) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 1;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1] ? arr[index+1][0] : null) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1]) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1] ? arr[index+1][0] : null) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
    print(magnets)
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1]) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === (arr[index+1] ? arr[index+1][0] : null)) counter++;
})
print(counter);

var count = readline();
var read = new Array(count-1);var calc=0;

for(var x = 0;x<count;x++){read[x] = readline();}

for(var i = 0;i<count;i++){
	if(i > 0){if(read[i][0] == read[i - 1][1]){calc+=1}}
}

if(calc != 0){calc += 1};print(calc);

var count = readline();
var read = new Array(count-1);var calc=0;

for(var x = 0;x<count;x++){read[x] = readline();}

for(var i = 0;i<count;i++){
	if(i > 0){if(read[i][1] == read[i - 1][1]){calc+=1}}
}

print(calc);

var nums = parseInt(readline());

var prev = null;
var block = 0; //block not gap
for (var i = 0; i < nums.length; i++) {
    var current = parseInt(readline());

    if (current !== prev) {
        block++;
    }

    prev = current;
}

print(block);


Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of customers."Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of t. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence t1, t2, ..., tn. For example, if t = (1,  - 1, 1,  - 1), then any two elements ti and tj form a couple if i and j have different parity. Consequently, in this case the sought number equals 4.Of course, a client can't form a couple with him/herself.

The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-th customer that has been assigned to the customer by the result of the analysis of his interests.

Print the number of couples of customs with opposite t. The opposite number for x is number  - x (0 is opposite to itself). Couples that only differ in the clients' order are considered the same. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

NoteIn the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).In the second sample any couple of clients is opposite.

var getVals = function () { return readline().split(' '); };

var getNums = function () {
    return readline().split(' ').map(function (a) { return parseInt(a) });
};

//131b
var n = parseInt(readline());
var data = getNums();
var hash = {};
var res = 0;

for(var i = 1; i <= 10; i++) {
    hash[i] = 0;
    hash["-" + i] = 0;
}
hash[0] = 0;

for(var i = 0; i < n; i++) {
    hash[data[i]]++;
}

for(var i = 1; i <= 10; i++) {
    res += hash[i] * hash[-i];
}

if (hash[0] > 1) {
    for(var i = 1; i < hash[0]; i++) {
        res += i;
    }
}

print(res);

;(function () {

	print((function (n) {
		var ret = 0, m = {};
		readline().split(' ').map(function (e, i) {
			e = Number(e);
			m[e] = m[e] ? m[e] + 1 : 1;
		});

		for (var key in m) {
			if (key < 0) {
				if (!m[-key]) break;
				ret += m[key] * m[-key];
			} else if (key == 0 && m[key] > 1) {
				ret += m[key] * (m[key] - 1) / 2;
			}
		}

		return ret;
	}).apply(0, [+readline()]));

}).call(this);


You are given an array $$$a$$$ of $$$n$$$ elements. You can apply the following operation to it any number of times:  Select some subarray from $$$a$$$ of even size $$$2k$$$ that begins at position $$$l$$$ ($$$1\le l \le l+2\cdot{k}-1\le n$$$, $$$k \ge 1$$$) and for each $$$i$$$ between $$$0$$$ and $$$k-1$$$ (inclusive), assign the value $$$a_{l+k+i}$$$ to $$$a_{l+i}$$$. For example, if $$$a = [2, 1, 3, 4, 5, 3]$$$, then choose $$$l = 1$$$ and $$$k = 2$$$, applying this operation the array will become $$$a = [3, 4, 3, 4, 5, 3]$$$.Find the minimum number of operations (possibly zero) needed to make all the elements of the array equal.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 2 \cdot 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the array. The second line of each test case consists of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq n$$$) — the elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ lines, each line containing the answer to the corresponding test case — the minimum number of operations needed to make equal all the elements of the array with the given operation.

NoteIn the first test, all elements are equal, therefore no operations are needed.In the second test, you can apply one operation with $$$k=1$$$ and $$$l=1$$$, set $$$a_1 := a_2$$$, and the array becomes $$$[1, 1]$$$ with $$$1$$$ operation.In the third test, you can apply one operation with $$$k=1$$$ and $$$l=4$$$, set $$$a_4 := a_5$$$, and the array becomes $$$[4, 4, 4, 4, 4]$$$.In the fourth test, you can apply one operation with $$$k=1$$$ and $$$l=3$$$, set $$$a_3 := a_4$$$, and the array becomes $$$[4, 2, 3, 3]$$$, then you can apply another operation with $$$k=2$$$ and $$$l=1$$$, set $$$a_1 := a_3$$$, $$$a_2 := a_4$$$, and the array becomes $$$[3, 3, 3, 3]$$$.In the fifth test, there is only one element, therefore no operations are needed.

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = readline().split(' ').map(x=>parseInt(x));

        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(steps);

        }
        zombiesF(m)
    }
}

const solve = arr=>{
    arr.reverse();
     let x = 1;
     let ans = 0;
     while(x<arr.length-1){
          if(arr[1]===arr[x+1]){
               x++;
          }
          else{
               ans++;
               x*=2;
          }
     }
     console.log(ans);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = [...readline().trim().split(" ").map(cur=>parseInt(cur)),0]
       solve(arr);
  }
}
main();

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});

process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0]);
  let i = 1;
  while (t--) {
    let n = parseInt(lines[i++]);
    let arr = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    arr.reverse();
    let x = 0;
    let count = 0;
    while (x < n) {
      if (arr[x] === arr[0]) {
        x++;
      } else {
        x *= 2;
        count++;
      }
    }
    console.log(count);
  }
});

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var g = readline();
            var a = readline().split(" ").map(w => parseInt(w))
            var n = a.length-1;
            var ref = a[n]
            var ans = 0;
            for(var i=n-1;i>=0;i--) {
            	if(a[i]==ref) continue;
            	var j = i;
            	var len = n-i;
            	var lim = Math.max(0, (i-len)+1);
            	var cnt = 0;
            	while(j >= lim) {
            		if(a[j] !== ref) {
            			cnt++;
            		}
            		j--
            	}
            	if(cnt > 0) {
            		ans++;
            	}
            	i=j+1;
            }
            console.log(ans)
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = readline().split(' ').map(x=>parseInt(x));

        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(m);

        }
        zombiesF(m)
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = readline().split(' ');
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(m);

        }
        zombiesF(m)
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = parseInt(readline());
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(n);

        }
        zombiesF(m)
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = parseInt(readline());
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(m);

        }
        zombiesF(m)
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = parseInt(readline());
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(steps, n, m ,'hello');

        }
        zombiesF(m)
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = parseInt(readline());
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(steps)

        }
        zombiesF(m)
    }
}

const solve = arr=>{
     let cnt = 0;
     const binaryserach = (start,end)=>{
          if(end-start===1) return arr[start];
          let mid = Math.floor((start+end)/2);
          let check = binaryserach(mid,end);
          for(let i=start;i<mid;i++){
               if(arr[i]!==check){
                    cnt++;
                    break;
               }
          }
          return check;
     }
     binaryserach(1,arr.length);
     console.log(cnt);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = [0,...readline().trim().split(" ").map(cur=>parseInt(cur))]
       solve(arr);
  }
}
main();

const solve = arr=>{
     let cnt = 0;
     const binaryserach = (start,end)=>{
          if(end-start===1) return arr[start];
          let mid = Math.floor((start+end)/2);
          let check = binaryserach(mid,end);
          for(let i=start;i<=mid;i++){
               if(arr[i]!==check){
                    cnt++;
                    break;
               }
          }
          return check;
     }
     binaryserach(0,arr.length);
     console.log(cnt);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();

const solve = arr=>{
    let cnt = 0;
     const binaryserach = (start,end)=>{
          if(end===start) return arr[end];
          let mid = Math.floor((start+end)/2);
          let check = binaryserach(mid+1,end);
          for(let i=start;i<=mid;i++){
               if(arr[i]!==check){
                    cnt++;
                    break;
               }
          }
          return check;
     }
     binaryserach(0,arr.length-1);
     console.log(cnt);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();

const solve = arr=>{
     let cnt = 0;
     const binaryserach = (start,end)=>{
          if(end-start===1) return arr[start];
          let mid = Math.floor((start+end)/2);
          let check = binaryserach(mid,end);
          for(let i=start;i<mid;i++){
               if(arr[i]!==check){
                    cnt++;
                    break;
               }
          }
          return check;
     }
     binaryserach(0,arr.length);
     console.log(cnt);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});

process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0]);
  let i = 1;
  while (t--) {
    let n = parseInt(lines[i++]);
    let arr = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let max = 0;
    let l, k;
    for (let j = 0; j < n; j++) {
      let stretch = 0;
      for (let p = j; p < n; p++) {
        if (arr[j] !== arr[p]) {
          break;
        }
        stretch++;
      }
      if (stretch > max) {
        max = stretch;
        l = j;
        k = stretch;
      }
    }
    let count = 0;
    let pos = l + k;
    while (pos < n) {
      pos = pos + k;
      k = k * 2;
      count++;
    }
    k = n - l;
    for (let pos = l; pos > 0; pos -= k) {
      k = k * 2;
      count++;
    }
    console.log(count);
  }
});

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});

process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0]);
  let i = 1;
  while (t--) {
    let n = parseInt(lines[i++]);
    let arr = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let max = 0;
    let l, k;
    for (let i = 0; i < n; i++) {
      let stretch = 0;
      for (let j = i; j < n; j++) {
        if (arr[i] !== arr[j]) {
          break;
        }
        stretch++;
      }
      if (stretch > max) {
        max = stretch;
        l = i;
        k = stretch;
      }
    }
    let m = l + k - 1;
    let count = 0;
    while (l > 0) {
      l = Math.max(l - k, 0);
      k = m - l + 1;
      count++;
    }
    while (m < n - 1) {
      m = m + k;
      k = m - l + 1;
      count++;
    }
    console.log(count);
  }
});


You are given an undirected unrooted tree, i.e. a connected undirected graph without cycles.You must assign a nonzero integer weight to each vertex so that the following is satisfied: if any vertex of the tree is removed, then each of the remaining connected components has the same sum of weights in its vertices.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 10^5$$$) — the number of vertices of the tree. The next $$$n-1$$$ lines of each case contain each two integers $$$u, v$$$ ($$$1 \leq u,v \leq n$$$) denoting that there is an edge between vertices $$$u$$$ and $$$v$$$. It is guaranteed that the given edges form a tree. The sum of $$$n$$$ for all test cases is at most $$$10^5$$$.

For each test case, you must output one line with $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$, where $$$a_i$$$ is the weight assigned to vertex $$$i$$$. The weights must satisfy $$$-10^5 \leq a_i \leq 10^5$$$ and $$$a_i \neq 0$$$. It can be shown that there always exists a solution satisfying these constraints. If there are multiple possible solutions, output any of them.

NoteIn the first case, when removing vertex $$$1$$$ all remaining connected components have sum $$$5$$$ and when removing vertex $$$3$$$ all remaining connected components have sum $$$2$$$. When removing other vertices, there is only one remaining connected component so all remaining connected components have the same sum.

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, edges) {
  const g = new Array(n).fill(0).map(() => []);
  for (let [u, v] of edges) {
    g[u].push(v);
    g[v].push(u);
  }
  let res = new Array(n).fill(0);
  const queue = [[0, 1]],
        st = [];
  for (let [node, d] of queue) {
    res[node] = d * g[node].length;
    for (let child of g[node]) {
      if (st[child]) continue;
      st[child] = 1;
      queue.push([child, d * -1]);
    }
  }
  console.log(res.join(' '));
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read()),
          edges = [];
    let tmp = n - 1;
    while (tmp--) {
      edges.push((await read()).split(' ').map(num => Number(num) - 1));
    }
    solve(n, edges);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')
const N = Number(inputs[0])
main(N, inputs)
function main(N, inputs) {
  for (let _ = 0, __ = 1; _ < N; _++, __++) {
    const n = Number(inputs[__]),
      edges = []
    for (let i = 0; i < n - 1; i++) {
      __++
      edges.push(inputs[__].split(' ').map(Number))
    }
    const g = new Array(n).fill(0).map(() => []),
      d = new Array(n).fill(0)

    const add = (i, j) => {
      g[i].push(j)
      d[j]++
    }
    for (let [u, v] of edges) add(u - 1, v - 1), add(v - 1, u - 1)
    let root = -1

    for (let i = 0; i < n; i++) {
      if (d[i] === 1) {
        root = i
        break
      }
    }

    const getNum = () => {
      let i = 0
      do {
        i = Math.floor(Math.random() * 10 ** 3)
      } while (i === 0)
      return i
    }

    const make = () => {
      const st = []

      let res = []
      res[root] = getNum()
      // res[root] = 1
      const child = g[root][0]
      res[child] = getNum()
      // res[child] = 2
      let flag = false
      st[root] = 1
      st[child] = 1

      // 断掉跟父元素连接的边之后,当前元素的联通分量表示为 s1,父元素的联通分量为 s2
      // 当前元素的值为 s1-s2*(children.length)
      const dfs = (i, s1, s2) => {
        if (flag) return
        st[i] = 1
        res[i] = s1 - s2 * (g[i].length - 1)
        if (res[i] === 0) {
          flag = true
          return
        }

        for (let j of g[i]) {
          if (st[j]) continue
          dfs(j, s2, s2 * (g[i].length - 1) + res[i])
        }
      }

      dfs(child, res[root] * (g[child].length - 1) + res[child], res[root])
      if (flag) return []
      return res
    }
    let res = []
    do {
      res = make()
    } while (res.length === 0)
    console.log(res.join(' '))
  }
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')
const N = Number(inputs[0])
main(N, inputs)
function main(N, inputs) {
  for (let _ = 0, __ = 1; _ < N; _++, __++) {
    const n = Number(inputs[__]),
      edges = []
    for (let i = 0; i < n - 1; i++) {
      __++
      edges.push(inputs[__].split(' ').map(Number))
    }
    const g = new Array(n).fill(0).map(() => []),
      d = new Array(n).fill(0)

    const add = (i, j) => {
      g[i].push(j)
      d[j]++
    }
    for (let [u, v] of edges) add(u - 1, v - 1), add(v - 1, u - 1)
    let root = -1

    for (let i = 0; i < n; i++) {
      if (d[i] === 1) {
        root = i
        break
      }
    }

    const make = () => {
      const st = []

      let res = []
      res[root] = Math.floor(Math.random() * 10 ** 3)
      // res[root] = 1
      const child = g[root][0]
      res[child] = Math.floor(Math.random() * 10 ** 3)
      // res[child] = 2
      let flag = false
      st[root] = 1
      st[child] = 1

      // 断掉跟父元素连接的边之后,当前元素的联通分量表示为 s1,父元素的联通分量为 s2
      // 当前元素的值为 s1-s2*(children.length)
      const dfs = (i, s1, s2) => {
        if (flag) return
        st[i] = 1
        res[i] = s1 - s2 * (g[i].length - 1)
        if (res[i] === 0) {
          flag = true
          return
        }

        for (let j of g[i]) {
          if (st[j]) continue
          dfs(j, s2, s2 * (g[i].length - 1) + res[i])
        }
      }

      dfs(child, res[root] * (g[child].length - 1) + res[child], res[root])
      if (flag) return []
      return res
    }
    let res = []
    do {
      res = make()
    } while (res.length === 0)
    console.log(res.join(' '))
  }
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')
const N = Number(inputs[0])
main(N, inputs)
function main(N, inputs) {
  for (let _ = 0, __ = 1; _ < N; _++, __++) {
    const n = Number(inputs[__]),
      edges = []
    for (let i = 0; i < n - 1; i++) {
      __++
      edges.push(inputs[__].split(' ').map(Number))
    }
    const g = new Array(n).fill(0).map(() => []),
      d = new Array(n).fill(0)

    const add = (i, j) => {
      g[i].push(j)
      d[j]++
    }
    for (let [u, v] of edges) add(u - 1, v - 1), add(v - 1, u - 1)
    let root = -1

    for (let i = 0; i < n; i++) {
      if (d[i] === 1) {
        root = i
        break
      }
    }
    const make = () => {
      const st = []
      st[root] = 1
      let res = []
      res[root] = Math.floor(Math.random() * 10 ** 3)
      const child = g[root][0]
      res[child] = Math.floor(Math.random() * 10 ** 3)
      let flag = false

      // 断掉跟父元素连接的边之后,当前元素的联通分量表示为 s1,父元素的联通分量为 s2
      // 当前元素的值为 s1-s2*(children.length)
      const dfs = (i, s1, s2) => {
        if (flag) return
        st[i] = 1
        res[i] = s1 - s2 * (g[i].length - 1)
        if (res[i] === 0) {
          flag = true
          return
        }

        for (let j of g[i]) {
          if (st[j]) continue
          dfs(j, s2, s2 + res[i])
        }
      }

      dfs(child, res[root] * (g[child].length - 1) + res[child], res[root])
      if (flag) return []
      return res
    }
    let res = []
    do {
      res = make()
    } while (res.length === 0)
    console.log(res.join(' '))
  }
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')
const N = Number(inputs[0])
main(N, inputs)
function main(N, inputs) {
  for (let _ = 0, __ = 1; _ < N; _++, __++) {
    const n = Number(inputs[__]),
      edges = []
    for (let i = 0; i < n - 1; i++) {
      __++
      edges.push(inputs[__].split(' ').map(Number))
    }
    const g = new Array(n).fill(0).map(() => []),
      d = new Array(n).fill(0)

    const add = (i, j) => {
      g[i].push(j)
      d[j]++
    }
    for (let [u, v] of edges) add(u - 1, v - 1), add(v - 1, u - 1)
    let root = -1

    for (let i = 0; i < n; i++) {
      if (d[i] === 1) {
        root = i
        break
      }
    }
    const make = () => {
      const st = []
      st[root] = 1
      let res = []
      res[root] = Math.floor(Math.random() * 10 ** 3)
      const child = g[root][0]
      res[child] = Math.floor(Math.random() * 10 ** 3)
      let flag = false
      // 断掉跟父元素连接的边之后,当前元素的联通分量表示为 s1,父元素的联通分量为 s2
      // 当前元素的值为 s1-s2*(children.length)
      const dfs = (i, s1, s2) => {
        if (flag) return
        st[i] = 1
        res[i] = s1 - s2 * g[i].length
        if (res[i] === 0) {
          flag = true
          return
        }
        for (let j of g[i]) {
          if (st[j]) continue
          dfs(j, s2, s2 + res[i])
        }
      }
      dfs(child, res[root] * g[child].length + res[child], res[root])
      if (flag) return []
      return res
    }
    let res = []
    do {
      res = make()
    } while (res.length === 0)
    console.log(res.join(' '))
  }
}


You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.Your task is to add spaces to the text by the following rules:  if there is no punctuation mark between two words, then they should be separated by exactly one space  there should be no spaces before each punctuation mark  there should be exactly one space after each punctuation mark It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.

The input data contains of a single non-empty line — the text whose length is no more than 10000 characters.

Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter.

galileo galilei was an   italian physicist  ,mathematician,astronomer

galileo galilei was an italian physicist, mathematician, astronomer

//JavaScript-C24.2.0 (SpiderMonkey)

var str = readline();
var arr = [];
var mySentence = [];
var mySentenceCopy = [];

for(var i=0; i<str.length;i++) {
    mySentence.push(str[i]);
}

function isPuncOrSpace(character) {
    return character==',' || character=='.' || character=='?' || character=='!' || character==' ';
}

var i=0;
while(i<mySentence.length) {

    if(isPuncOrSpace(mySentence[i])) {
        var count = 0;
        while(isPuncOrSpace(mySentence[count+i])) {
            count++;
        }
        var spacePuns = mySentence.slice(i,count+i);
        if(spacePuns.indexOf('.')!=-1) {
             mySentenceCopy.push('.');
             mySentenceCopy.push(' ');
        }
        else if(spacePuns.indexOf(',')!=-1) {
             mySentenceCopy.push(',');
             mySentenceCopy.push(' ');
        }
        else if(spacePuns.indexOf('!')!=-1) {
             mySentenceCopy.push('!');
             mySentenceCopy.push(' ');
        }
        else if(spacePuns.indexOf('?')!=-1) {
             mySentenceCopy.push('?');
             mySentenceCopy.push(' ');
        }
        else
             mySentenceCopy.push(' ');
        i = count+i;
    }
    else  {
      mySentenceCopy.push(mySentence[i]);
      i++;
    }
}
var mes = "";

for(var i=0; i<mySentenceCopy.length; i++) {
    mes+=mySentenceCopy[i];
}
print(mes)

str = readline();
str = str.replace(/  +/g, ' ');
str = str.replace(/ ([,!?.])/g, '$1 ');
str = str.replace(/([,!?.])/g, '$1 ');
str = str.replace(/  +/g, ' ');
write(str)

//JavaScript-C24.2.0 (SpiderMonkey)

var str = readline();
var arr = [];
var mySentence = [];

for(var i=0; i<str.length;i++) {
    mySentence.push(str[i]);
}

var mySentenceCopy = mySentence.slice();

function isPuncOrSpace(character) {
    return character==',' || character=='.' || character=='?' || character=='!' || character==' ';
}

for(var i=0; i<str.length; i++) {
    if(isPuncOrSpace(str[i]))
        arr.push('p');
    else
        arr.push('l');
}

var i=0;
while(i<mySentence.length) {

    if(arr[i]=='p') {
        var count = 0;
        while(arr[count+i]=='p') {
            count++;
        }
        var spacePuns = mySentence.slice(i,count+i);
        if(spacePuns.indexOf('.')!=-1)
             mySentenceCopy.splice(i,count,'. ');
        else if(spacePuns.indexOf(',')!=-1)
             mySentenceCopy.splice(i,count,', ');
        else if(spacePuns.indexOf('!')!=-1)
             mySentenceCopy.splice(i,count,', ');
        else if(spacePuns.indexOf('?')!=-1)
             mySentenceCopy.splice(i,count,'? ');
        else
             mySentenceCopy.splice(i,count,' ');

        i = count+i;
    }
    else
      i++;
}
var mes = "";

for(var i=0; i<mySentenceCopy.length; i++) {
    mes+=mySentenceCopy[i];
}
print(mes)

str = readline();
str = str.replace(/  +/g, ' ');
str = str.replace(/ ,/g, ', ');
str = str.replace(/,/g, ', ');
str = str.replace(/  +/g, ' ');
write(str)


New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) — the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros.

For each test case, print the answer on it — the number of minutes before the New Year.

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readALine() {
    return inputString[currentLine++];
}

function printALine(str) {
    console.log(str);
}

function stringArrayToNumbers(str) {
    var array = str.split(" ");
    var result = [];
    for( var i = 0; i < array.length; i++ ) {
        result.push( parseInt(array[i]) );
    }
    return result;
}

// ======================================================
// A. Minutes Before the New Year
// https://codeforces.com/problemset/problem/1283/A
// ======================================================

// hours = number of hours left
// min = number of minutes left.
function doIt( hours, min ) {

    var result = 0;

    var result1 = 60 - min;
    var result2 = 0;

    if( 1 + hours < 24 ) {
        result2 = (24 - (1 + hours)) * 60;
    }

    return result1 + result2;

}

function main() {

    var numOfTests = readALine();
    for( var i = 0; i < numOfTests; i++ ) {

        var string1 = readALine();
        var arr1 = stringArrayToNumbers(string1);

        var result = doIt( arr1[0], arr1[1] );

        printALine(result);

    }

}

'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main(inputString);
});

function main(inputString) {
    let index = 0;
    let tests = inputString[index++];

    for (let i = 0; i < tests; ++i) {
        let curTime = inputString[index++].split(' ');
        console.log(minsRemained(curTime))
    }
}

function minsRemained(curTime) {
    return parseInt((24 - curTime[0] - 1)*60) + parseInt(60 - curTime[1]);
}

process.stdin.resume()
process.stdin.setEncoding('utf-8')

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const t = readInt(arr)

  for(let j = 0; j < t; j++) {
    const [h, m] = readInts(arr, j)
    const ans = (24 - h) * 60 - m
    wr(ans)
  }
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}
function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
  	var tmp = nextIntArray();
  	output[i] = 1440 - (tmp[0] * 60 + tmp[1]);
  }
  myout(myconv(output, 9));
}

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let c = 0;

rl.on("line", (d) => {
  if (c === 0) {
    c++;
    return;
  }

  const [h, m] = d.split(" ").map(Number);
  let ans = 0;
  let r = m === 0 ? 0 : 1;

  ans += m === 0 ? 0 : 60 - m;
  ans += (24 - r - h) * 60;

  console.log(ans);
  c++;
});

'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function main() {
    let t = parseInt(readLine(), 10);
    let i, h, m;

    for(i=1; i<=t; i++) {
        let inputs = readLine();
        inputs = inputs.split(' ');
        h = parseInt(inputs[0], 10);
        m = parseInt(inputs[1], 10);

        let totalMin = (23-h)*60 + 60-m;
        console.log(totalMin);
    }
}

var n = parseInt(readline());
while(n--){
  var z = readline();
  var t = z.split(' ').map(e => parseInt(e));
  print((23-t[0])*60+60-t[1]);
}

'use strict'

const problem = (h, m) => 1440 - h*60 - m;
let q = +readline();
while(q--) print(problem(...readline().split(' ').map(Number)))

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var hhmm = readline().split(' ').map(Number);
    var hh = hhmm[0];
    var mm = hhmm[1];
    print((23 - hh) * 60 + 60 - mm)
  }
}
main()

  var t = Number(readline());

  while (t--) {
    var input = readline().split(' ').map(function(x) {
        return parseInt(x);
      });
    var h = input[0];
    var m = input[1];
    var result = 1440 - (h * 60 + Number(m));
    print(result);
  }

"use strict";

let inputNumber = +readline();
let dates = [];
let output = [];

for (let i = 0; i < inputNumber; i++) {
	dates[i] = readline();
	dates[i] = dates[i].split(" ").map(function(item){ return +item; });
	let hours = dates[i][0];
	let mins = dates[i][1];
	output[i] = (24 - hours) * -60 + mins;
}

for (let i = 0; i < inputNumber; i++) {
	print(-output[i]);
}

var n=Number(readline());
for(var i=0;i<n;i++){
	var h=readline().split(" ");
	print(((23-Number(h[0]))*60)+(60-Number(h[1])));
}
//balda solve hoyna kno
//bal chal problem amar

var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)
var write = this.write || require('lol-io').write; //write --> creates output.txt with output
var readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt

var t, time, ans;

t = Number(readline());

for (i = 0; i < t; i++) {

    time = readline().replace(/\r$/, '').split(' ').map(Number);
    ans = 24 * 60;
    ans -= time[0] * 60 + time[1];

    print(ans);
}

var day = 1440;
var t = 0;
t = parseInt(readline());
for (var i=0;i<t;i++) {
var currentHour = 0;
var currentMin = 0;
var num = readline().split(" ").map(x => parseInt(x));
currentHour = num[0];
currentMin = num[1];
var CurrentTime = parseInt(currentHour) * 60 + parseInt(currentMin);
print(parseInt(day)-parseInt(CurrentTime));
}

var t = readline();
while(t--) {
    var a = readline().split(" ").map(function(num) {
        return parseInt(num)
    });
    print((23 - a[0]) * 60 + (60 - a[1]));
}

var cant = readline();

for (var i=0; i < cant; i++) {
    var numbers = readline().split(" ").map(function(x) { return parseInt(x); });
    var hours = numbers[0];
    var minutes = numbers[1];
    var toRet = 0;
    if(hours >= 0 ){
        toRet = (23-hours)*60;
    }
    if(minutes >= 0)
        toRet += 60-minutes;
    print(toRet);
}

const data = readline().split(" ").map(x => parseInt(x));
const t = data[0];
var timeArray=[];
for (var i=0; i<t; i++) {
    var time = readline().split(" ").map(x => parseInt(x));
    var minutes = time[0] * 60 + time[1];
    print(1440 - minutes);
}

  var t = readline();
  while (t--) {
    var h = readline();
    var m = readline();
    var result = 1440 - (h * 60 + Number(m));
    print(result);
  }

  var t = Number(readline());
  while (t--) {
    var h = Number(readline());
    var m = Number(readline());
    var result = 1440 - (h * 60 + Number(m));
    print(result);
  }

var n=Number(readline());
for(var i=0;i<n;i++){
	var h,m=readline().split(" ");
	print(((23-h)*60)+(60-m));
}
//balda solve hoyna kno
//bal chal problem amar

var n=Number(readline());
for(var i=0;i<n;i++){
	var h,m=readline().split(" ");
	print((23-Number(h)*60)+(60-Number(m)));
}
//balda solve hoyna kno
//bal chal problem amar

var day = 1440;
var t = readline();
for (var i=0;i<t;i++) {
var currentHour = parseInt(readline());
var currentMin = parseInt(readline());
CurrentTime = (currentHour) * 60 + (currentMin);
print(day-CurrentTime);
}

const data = readline().split(" ").map(x => parseInt(x));
const t = data[0];
var timeArray=[];
for (var i=0; i<t; i++) {
    var time = readline().split(" ").map(x => parseInt(x));
    const minutes = time[0] * 60 + time[1];
    timeArray.push(1440 - minutes);
}
print(timeArray);

const data = readline().split(" ").map(x => parseInt(x));
const t = data[0];
var timeArray=[];
for (var i=0; i<t; i++) {
    var time = readline().split(" ").map(x => parseInt(x));
    var minutes = time[0] * 60 + time[1];
    timeArray.push(1440 - minutes);
}
print(timeArray);