Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least $$$2$$$ cosplayers, the number of males does not exceed the number of females (obviously).Currently, the line has $$$n$$$ cosplayers which can be described by a binary string $$$s$$$. The $$$i$$$-th cosplayer is male if $$$s_i = 0$$$ and female if $$$s_i = 1$$$. To ensure that the line is beautiful, you can invite some additional cosplayers (possibly zero) to join the line at any position. You can't remove any cosplayer from the line.Marin wants to know the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful. She can't do this on her own, so she's asking you for help. Can you help her?

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases.  The first line of each test case contains a positive integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of cosplayers in the initial line. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ — describing the cosplayers already in line. Each character of the string is either 0 describing a male, or 1 describing a female. Note that there is no limit on the sum of $$$n$$$.

For each test case, print the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful.

NoteIn the first test case, for each pair of adjacent cosplayers, you can invite two female cosplayers to stand in between them. Then, $$$000 \rightarrow 0110110$$$.In the third test case, you can invite one female cosplayer to stand next to the second cosplayer. Then, $$$010 \rightarrow 0110$$$.

let buf='';

process.stdin.on('readable', function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end', function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=line[0];
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[2*_-1]);
        let s=line[2*_];
        // console.log(n,s);
        let ans=0;
        let cnt=0;
        let sum=0;
        for(let i=0;i<n;i++)
        {
            if(s[i]==='0')
            {
                sum++;
                if(sum>1)
                {
                    if(cnt<2)
                    {
                        ans+=2-cnt;
                    }
                }
                cnt=0;
            }
            else
            {
                cnt++;
            }
        }
        console.log(ans);
    }
})

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const calc = (n, line)=>{
    let pos = -1;
    let res = 0;
    for (let i = 0; i < n; i++) {
        if (line[i] === '0') {
            if (pos === -1) {
                pos = i;
                continue;
            }
            let diff = i - pos;
            if (diff > 2) {
                pos = i;
                continue;
            }
            res += 2 - diff + 1;
            pos = i;
        }
    }
    return res;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let line = readline();
        console.log(`${calc(n, line)}`);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let b = readline().split('').map(Number);

        let ans = 0;
        let count = 2;
        for (let c of b) {
            if (c === 1) count++;
            else {
                ans += Math.max(2 - count, 0);
                count = 0;
            }
        }

        output(ans);
    }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
	var t = lines[0];
	var n = 0;
	for(i = 1; i <= t * 2; i++){
	    if(i % 2 == 1){
	        n = lines[i];
	    }else{
	        var s = lines[i].split('').map(Number);
	        var ans = 0;
	        for(j = 0; j < n; j++){
	            if(s[j] == 1){
	                continue;
	            }
	            if(j < n - 1 && s[j + 1] === 0){
	                ans += 2;
	            }else if(j < n - 2 && s[j + 1] == 1 && s[j + 2] === 0){
	                ans++;
	            }
	        }
	        console.log(ans);
	    }
	}
});

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const n = readLine();

        const a = readLine();

        const res = main(a);

        console.log(res)
    }
});

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

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function main(a){
    let ans = 0;
    let cnt = 2;
    for (let index = 0; index < a.length; index++) {
        if(a[index] == 1){
           cnt++;
        } else{
            ans += Math.max(2 - cnt,0);
            cnt = 0;
        }
    }
    return ans;
}

// problems/contest1658/A/src/ts/solution.ts
var lines = [];
require("readline").createInterface({
  input: process.stdin
}).on("line", (line) => lines.push(line));
process.stdin.on("end", () => {
  main(lines);
});
function main(lines2) {
  let i = 0;
  for (let t = Number(lines2[i++]); t > 0; t--) {
    const n = Number(lines2[i++]);
    const s = lines2[i++];
    console.log(solve(n, s));
  }
}
function solve(n, s) {
  let res = 0;
  let p = -1;
  for (let i = 0; i < n; i++) {
    if (s[i] === "0") {
      if (p >= 0) {
        if (p + 1 === i)
          res += 2;
        else if (p + 2 === i)
          res += 1;
      }
      p = i;
    }
  }
  return res;
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')
const N = Number(inputs[0])
for (let _ = 0, __ = 1; _ < N; _++) {
  const n = Number(inputs[__++]),
    data = inputs[__++]
  main(n, data)
}

function main(n, data) {
  let res = 0
  for (let i = 1; i < n; i++) {
    if (data[i - 1] === '0') {
      if (data[i] === '0') res += 2
      else if (data[i] === '1' && i + 1 !== n && data[i + 1] !== '1') res++
    }
  }
  console.log(res)
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        output[i] = solve(n, str)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str) {
    let ans = 0
    let prev
    for (let i = 0; i < str.length; i++) {
        if (str[i] === '0') {
            if (prev >= 0) {
                ans += Math.max(0, 3 - (i - prev))
            }
            prev = i
        }
    }
    return ans
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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();
	while(hasNext()){
		var N = nextInt();
		var S = next();
		var output = 0;
		for(var i = 0; i < N - 1; i++){
			if(S[i] == "0" && S[i + 1] == "0"){
				output += 2;
			}else if(i > 0 && S[i - 1] == "0" && S[i] == "1" && S[i + 1] == "0"){
				output++;
			}
		}
		myout(output);
	}
}

/*
INPUT
9
3
000
3
001
3
010
3
011
3
100
3
101
3
110
3
111
19
1010110000100000101
*/

var t = Number(readline());

for(var i = 0; i < t; i++) {
    readline();
    var s = readline();

    var lastZero = -Infinity;
    var total = 0;

    for(var j = 0; j < s.length; j++) {
        if(s[j] == '0') {
            if(lastZero == j - 1) {
                total += 2;
            }
            if(lastZero == j - 2) {
                total += 1;
            }
            lastZero = j;
        }
    }

    print(total);
}

let buf='';

process.stdin.on('readable', function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end', function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    console.log(1);
    setTimeout(()=>{
        console.log(3);
    },1000);
    console.log(2);
})

let buf='';

process.stdin.on('readable', function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end', function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    console.log(1);
    setTimeout(()=>{
        console.log(3);
    },100);
    console.log(2);
})

let buf='';

process.stdin.on('readable', function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end', function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    console.log(1);
})

let buf='';

process.stdin.on('readable', function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('read', function(){
    const {EOL}=requrie('os');
    let line=buf.split(EOL);
    console.log(1);
    setTimeout(()=>{
        console.log(3);
    },100);
    console.log(2);
})

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const calc = (n, line)=>{
    let pos = -1;
    let res = 0;
    for (let i = 0; i < n; i++) {
        if (line[i] === '0') {
            if (pos === -1) {
                pos = i;
                continue;
            }
            let diff = i - pos;
            if (diff > 2) {
                pos = i;
                continue;
            }
            res += 2 - diff + 1;
            pos = i;
        }
    }
    return res;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let line = readline();
        console.log(`Case #${t}: ${calc(n, line)}`);
    }
}


There is a graph of $$$n$$$ rows and $$$10^6 + 2$$$ columns, where rows are numbered from $$$1$$$ to $$$n$$$ and columns from $$$0$$$ to $$$10^6 + 1$$$:  Let's denote the node in the row $$$i$$$ and column $$$j$$$ by $$$(i, j)$$$.Initially for each $$$i$$$ the $$$i$$$-th row has exactly one obstacle — at node $$$(i, a_i)$$$. You want to move some obstacles so that you can reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph (you can't pass through obstacles). Moving one obstacle to an adjacent by edge free node costs $$$u$$$ or $$$v$$$ coins, as below:  If there is an obstacle in the node $$$(i, j)$$$, you can use $$$u$$$ coins to move it to $$$(i-1, j)$$$ or $$$(i+1, j)$$$, if such node exists and if there is no obstacle in that node currently.  If there is an obstacle in the node $$$(i, j)$$$, you can use $$$v$$$ coins to move it to $$$(i, j-1)$$$ or $$$(i, j+1)$$$, if such node exists and if there is no obstacle in that node currently.  Note that you can't move obstacles outside the grid. For example, you can't move an obstacle from $$$(1,1)$$$ to $$$(0,1)$$$. Refer to the picture above for a better understanding. Now you need to calculate the minimal number of coins you need to spend to be able to reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph without passing through obstacles.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$u$$$ and $$$v$$$ ($$$2 \le n \le 100$$$, $$$1 \le u, v \le 10^9$$$) — the number of rows in the graph and the numbers of coins needed to move vertically and horizontally respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — where $$$a_i$$$ represents that the obstacle in the $$$i$$$-th row is in node $$$(i, a_i)$$$. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^4$$$.

For each test case, output a single integer — the minimal number of coins you need to spend to be able to reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph without passing through obstacles. It can be shown that under the constraints of the problem there is always a way to make such a trip possible.

NoteIn the first sample, two obstacles are at $$$(1, 2)$$$ and $$$(2,2)$$$. You can move the obstacle on $$$(2, 2)$$$ to $$$(2, 3)$$$, then to $$$(1, 3)$$$. The total cost is $$$u+v = 7$$$ coins.  In the second sample, two obstacles are at $$$(1, 3)$$$ and $$$(2,2)$$$. You can move the obstacle on $$$(1, 3)$$$ to $$$(2, 3)$$$. The cost is $$$u = 3$$$ coins.

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, u, v] = iInpArr();
    let arr = iInpArr();
    let flag = false;
    for (let i = 0; i < n - 1; i++) {
      if (arr[i] !== arr[i + 1]) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      console.log(v + Math.min(u, v));
      continue;
    }
    flag = false;
    for (let i = 0; i < n - 1; i++) {
      if (Math.abs(arr[i] - arr[i + 1]) >= 2) {
        console.log(0);
        flag = true;
        break;
      }
    }
    if (!flag) console.log(Math.min(u, v));
  }
};
solve();

'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();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        // var x = new Array(n)
        var [n, u, v] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var ans = false
        for (let i = 0; i < n - 1; i++) {
            if (Math.abs(a[i] - a[i + 1]) > 1) ans = true
        }
        // console.log('ansans')
        // console.log(ans)
        // console.log(a)
        if (ans) return console.log(0)

        var existOne = false
        for (let i = 0; i < n - 1; i++) {
            if (Math.abs(a[i] - a[i + 1]) === 1) existOne = true
        }

        if (existOne) return console.log(Math.min(u, v))

        var min1 = v + v
        var min2 = u + v
        console.log(Math.min(min1, min2))

    })
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const [n, u, v] = rna();
		const a = rna();

		let mxdf = 0;
		for (let i = 1; i < n; i++) {
			mxdf = Math.max(mxdf, Math.abs(a[i] - a[i-1]));
		}

		let ans;
		if (mxdf >= 2)
			ans = 0;
		else if (mxdf == 1) {
			ans = Math.min(u, v);
		} else {
			ans = v + Math.min(u, v);
		}

		console.log(ans);
	}
}

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    var index = 1;
    for (var a = 0; a < t; a++) {
        var [n, u, v] = input[index].split(" ").map((i) => {
            return Number(i);
        });
        index++;
        var arr = input[index].split(" ").map((i) => {
            return Number(i);
        });
        index++;
        var min = Infinity;
        for (var i = 1; i < arr.length; i++) {
            if (Math.abs(arr[i] - arr[i - 1]) > 1) {
                min = 0;
            } else if (Math.abs(arr[i] - arr[i - 1]) === 1) {
                min = Math.min(min, u, v);
            } else {
                min = Math.min(min, u + v, v + v);
            }
        }
        console.log(min);
    }

})

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();

  for (var i = 0; i < testCasesNum; i++) {
    var nuv = readNumArray();
    var u = nuv[1];
    var v = nuv[2];
    var arr = readNumArray();
    var diff = maxDiff(arr);
    if (diff === 2) {
      print(0);
    }
    if (diff === 1) {
      print(Math.min(u, v));
    }
    if (diff === 0) {
      print(v + Math.min(u, v));
    }
  }
}

function maxDiff(arr) {
  var max = 0;
  for (var j = 1; j < arr.length; j++) {
    var diff = Math.abs(arr[j] - arr[j - 1]);
    if (diff > max) {
      if (diff > 1) {
        return 2;
      }
      max = diff;
    }
  }
  return max;
}
main();

main = () => {
	allans=[];
	t=readInt();
	for (_=0;_<t;_++){
		nuv=readIntArr();
		n=nuv[0];u=nuv[1];v=nuv[2];
		a=readIntArr();
		haveLargeGap=false;
		haveOneGap=false;
		for(i=1;i<n;i++){
			gap=Math.abs(a[i]-a[i-1]);
			if (gap>1){
				haveLargeGap=true;
				break;
			}
			else if (gap===1) haveOneGap=true;
		}
		if (haveLargeGap) allans.push(0);
		else if (haveOneGap) allans.push(Math.min(u,v));
		else allans.push(v+Math.min(u,v));
	}
	multiLineArrayPrint(allans);
}

readInt = () => parseInt(readline());
readString = () => readline();
readIntArr = () => readline().split(" ").map(zzzz => parseInt(zzzz));
oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));
multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\n'));
multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\n'));

for (_ = 0; _ < 1; _++) {
	main();
}

// newline for testing
 //newline for testing
// codeforces js cannot use "let" keyword

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, u, v] = iInpArr();
    let arr = iInpArr();
    let flag = false;
    for (let i = 0; i < n - 1; i++) {
      if (arr[i] !== arr[i + 1]) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      console.log(u + v);
      continue;
    }
    flag = false;
    for (let i = 0; i < n - 1; i++) {
      if (Math.abs(arr[i] - arr[i + 1]) >= 2) {
        console.log(0);
        flag = true;
        break;
      }
    }
    if (!flag) console.log(Math.min(u, v));
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, u, v] = iInpArr();
    let arr = iInpArr();
    let flag = false;
    for (let i = 0; i < n - 1; i++) {
      if (arr[i] !== arr[i + 1]) {
        console.log(Math.min(u, v));
        flag = true;
        break;
      }
    }
    if (!flag) console.log(u + v);
  }
};
solve();

'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();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        // var x = new Array(n)
        var [n, u, v] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var ans = false
        for (let i = 0; i < n - 1; i++) {
            if (Math.abs(a[i] - a[i + 1]) > 1) ans = true
        }
        // console.log('ansans')
        // console.log(ans)
        // console.log(a)
        if (ans) return console.log(0)

        var existOne = false
        for (let i = 0; i < n - 1; i++) {
            if (a[i] - a[i + 1] === 1) existOne = true
        }

        if (existOne) return console.log(Math.min(u, v))

        var min1 = v + v
        var min2 = u + v
        console.log(Math.min(min1, min2))

    })
}

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();

  for (var i = 0; i < testCasesNum; i++) {
    var nuv = readNumArray();
    var u = nuv[1];
    var v = nuv[2];
    var arr = readNumArray();
    var diff = maxDiff(arr);
    if (diff === 2) {
      print(0);
    }
    if (diff === 1) {
      print(Math.min(u, v));
    }
    if (diff === 0) {
      print(u + v);
    }
  }
}

function maxDiff(arr) {
  var max = 0;
  for (var j = 1; j < arr.length; j++) {
    var diff = Math.abs(arr[j] - arr[j - 1]);
    if (diff > max) {
      if (diff > 1) {
        return 2;
      }
      max = diff;
    }
  }
  return max;
}
main();


You are given two integers $$$a$$$ and $$$b$$$. Print $$$a+b$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given as a line of two integers $$$a$$$ and $$$b$$$ ($$$-1000 \le a, b \le 1000$$$).

Print $$$t$$$ integers — the required numbers $$$a+b$$$.

var n = readline().split(' ');

for (var i = 0; i < n; i++) {
    var line = readline().split(' ');
    var x = parseInt(line[0]), y = parseInt(line[1]);
    print(x+y);
}

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 = readline();
var i=0;
while (i < n) {
  a = readline()
    .split(" ")
    .map((a) => parseInt(a));
  print(a[0]+a[1])
  i++;
}

t=readline();
while(t--){
	a=readline().split(" ");
	print(+a[0] + +a[1]);
}

var num = readline().split(" ").map(x => parseInt(x)); // num will be an array [1,2,3]
var tt = num[0]; // to store values in different variables.
var i;
for (i = 0; i < tt; i++) {
  var num2 = readline().split(" ").map(x => parseInt(x)); // num will be an array [1,2,3]
  var atefeh = num2[0];
  var behzad = num2[1];
  print(atefeh+behzad)
}

var n = Number(readline())
for(var i=0;i<n;i++){
  var a=readline().split(" ").map(Number)
  print(a[0]+a[1])
}

var t = Number(readline());
while(t--) {
    var v = readline().split(" ");
    var a = Number(v[0]);
    var b = Number(v[1]);
    print(a+b);
}

"use strict";

function sec(){
    var inp = readline().split(' ');
    print(parseInt(inp[1])+parseInt(inp[0]));
}

function main(){
    var t = readline();
    while(t--){
        sec();
    }
}

main();

var l = readline().split(' ');

while(l[0]--)
{
   var line = readline().split(' ');
   print(parseInt(line[0]) + parseInt(line[1]));
}

t = readline();

while (t--) {
  a = readline().split(' ');
  // JUST TESTING STRING INTERPOLATION
  ans = `${+a[0] + +a[1]}`;
  print(ans);

}

var t = readline();
while (t--) {
	var a = readline().split(" ").map(Number);
	print(a[0] + a[1]);
}

t = readline();
while (t--) {
	a = readline().split(" ").map(Number);
	print(a[0] + a[1]);
}

t = readline();

while (t--) {
  // JUST TESTING MAP ARROW FUNCTION SYNTAX
  a = readline().split(' ').map(x => +x);
  print(a[0] + a[1]);
}

t = readline();
while (t--) {
	a = readline().split(' ');
	print(+a[0] + +a[1]);
}

var Case  = Number(readline());
while(Case--){
	var s = readline().split(" ");
    var a = Number(s[0]);
    var b = Number(s[1]);
    print(a+b);
}

'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(str => str.trim());

    main();
});

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

function main() {
    const n = parseInt(readLine(), 10);
    for (let i = 0; i < n; i++) {
        const result = readLine().split(' ').map(x=> parseInt(x)).reduce((prev, curr)=> curr + prev, 0)
        console.log(result)
    }
    return;
}

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);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
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){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var tmp = nextIntArray();
		output[i] = tmp[0] + 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 [a, b] = d.split(' ').map(Number);
  console.log(a + b);

  c++;
});

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const [a, b] = lines[i+1].split(' ').map(x => +x)
    console.log(a+b)
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

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

function doline(t) {
    rl.question("", ab => {
        console.log(ab.split(" ").reduce((a,b) => a+Number(b),0))
        t == 1 ? rl.close():doline(t-1)
    })
}

rl.question("", t => doline(Number(t)))

raw_input = '';
process.stdin.on('data', input => raw_input += input.toString());
process.stdin.on('end', () => main());

function main() {
  const lines = raw_input.split('\n');
  T = +lines[0];
  for (i = 1; i <= T; i++) {
    [a, b] = lines[i].split(' ').map(i => +i);
    console.log(a + b);
  }
}

process.stdin.resume();
process.stdin.setEncoding('ascii');

var inputString="";
var currentLine=0;

process.stdin.on('data',function(data){
	inputString+=data;
});
process.stdin.on('end',function(){
	 inputString=inputString.split('\n');
	 main();
});

function readline(){
	return inputString[currentLine++];
}
function main(){
	var n=readline();
	for(let i=0;i<n;i++){
	    var s=readline().split(' ');
	    let [m,b]=s;
	      console.log(parseInt(m)+parseInt(b));
	}
}

'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++];
}
/**
    3
1 3
100000 100000
2 2

**/

function main() {
    var range = readline();

    for(var r=0;r<range;r++) {
        let [a, b] = readline().split(" ").map(Number);

        console.log(a + b);

    }
}

'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 yourFunction(arr) {
    return arr[0] + arr[1];
}

//----------------------------------------------

function main() {

    const n = parseInt(readLine(), 10);
    for (var i = 0; i < n; i++) {
        const arr = readLine().split(' ').map(arrTemp => parseInt(arrTemp, 10));

        let result = yourFunction(arr);

        console.log(result);
    }
}

var l = readline().split(' ');
var line = readline().split(' ');

while(l[0]--)
print(parseInt(line[0]) + parseInt(line[1]));

'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(str => str.trim());

    main();
});

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

function main() {
    const n = parseInt(readLine(), 10);
    for (let i = 0; i < n; i++) {
        const result = parseInt(readLine(), 10) + parseInt(readLine(), 10);
        console.log(result)
    }
    return;
}

raw_input = '';
process.stdin.on('data', input => raw_input += input.toString());
process.stdin.on('end', () => main());

function main() {
  const lines = raw_input.split('\n').slice(1);
  lines.forEach(line => {
    [a, b] = line.split(' ').map(i => +i);
    console.log(a + b);
  });
}

function yourFunction(a,b) {
    return a+b;
}

'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 yourFunction(arr) {
    return arr[0] + arr[1];
}

//----------------------------------------------

function main() {

    // const n = parseInt(readLine(), 10);

    const arr = readLine().split(' ').map(arrTemp => parseInt(arrTemp, 10));

    let result = yourFunction(arr);

    console.log(result);
}


This is an interactive problem.The jury has a permutation $$$p$$$ of length $$$n$$$ and wants you to guess it. For this, the jury created another permutation $$$q$$$ of length $$$n$$$. Initially, $$$q$$$ is an identity permutation ($$$q_i = i$$$ for all $$$i$$$).You can ask queries to get $$$q_i$$$ for any $$$i$$$ you want. After each query, the jury will change $$$q$$$ in the following way:   At first, the jury will create a new permutation $$$q'$$$ of length $$$n$$$ such that $$$q'_i = q_{p_i}$$$ for all $$$i$$$.  Then the jury will replace permutation $$$q$$$ with pemutation $$$q'$$$. You can make no more than $$$2n$$$ queries in order to quess $$$p$$$.

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.

NoteIn the first test case the hidden permutation $$$p = [4, 2, 1, 3]$$$.Before the first query $$$q = [1, 2, 3, 4]$$$ so answer for the query will be $$$q_3 = 3$$$.Before the second query $$$q = [4, 2, 1, 3]$$$ so answer for the query will be $$$q_2 = 2$$$.Before the third query $$$q = [3, 2, 4, 1]$$$ so answer for the query will be $$$q_4 = 1$$$.In the second test case the hidden permutation $$$p = [1, 3, 4, 2]$$$.Empty strings are given only for better readability. There will be no empty lines in the testing system.

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

const readInt = async function(){
    return parseInt(await getLine());
}

const readIntArray = async function() {
    return (await getLine()).split(' ').map(num => parseInt(num));
}

let solve = async () => {
    const nsc = await readInt();
    for(let sc = 0; sc < nsc; sc++) {
        const n = await readInt();
        rl.output.write(`? 1\n`);
        await readInt();
        const res = new Array(n + 1);
        let total = 1;
        const cycle = new Array(n + 1);
        let ncycle = 0;
        for (let i = 1; i <= n; i++) {
            if (!res[i]) {
                if (i===n) {
                    res[n] = n;
                    break;
                }
                ncycle = 0;
                const beforeTotal = total;
                while (true) {
                    rl.output.write(`? ${i}\n`);
                    // console.log(`? ${i}`);
                    const val = await readInt();
                    total++;
                    if (res[val])
                        break;
                    res[val] = true;
                    cycle[ncycle] = val;
                    ncycle++;
                }
                let cur = i;
                for (let j = (beforeTotal - 1) % ncycle, cnt = 1; cnt <= ncycle + 1; cnt++, j = (j + 1) % ncycle) {
                    res[cur] = cycle[j];
                    cur = res[cur];
                }
            }
        }

        rl.output.write(`! ${res.slice(1).join(' ')}\n`)
    }
}

solve();

const readline = require('readline');

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

const g = main();
g.next()
rl.on('line', (input) => {
    // console.log('read', input)
    input.split('\n').forEach(s => s.trim() && g.next(s))
});

function* main() {
    let input

    input = yield 1
    const t = +input
    for (let i = 0; i < t; i++) {
        input = yield 1
        const n = +input
        yield* solve(n)
    }
    process.exit(0)
}

function* solve(n) {
    const ans = Array(n).fill(-1)
    for (let i = 0; i < n; i++) {
        if (ans[i] >= 0) continue

        const map = {}
        const arr = []
        while (1) {
            const x = yield* ask(i + 1)
            if (map[x]) break

            map[x] = 1
            arr.push(x)
        }
        // the next of `x` is `px`
        for (let j = 0; j < arr.length; j++) {
            ans[arr[j] - 1] = arr[(j + 1) % arr.length]
        }
    }
    console.log(`! ${ans.join(' ')}`)
}
function* ask(i) {
    console.log(`? ${i}`)
    const x = yield 1
    return +x
}

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

const readInt = async function(){
    return parseInt(await getLine());
}

const readIntArray = async function() {
    return (await getLine()).split(' ').map(num => parseInt(num));
}

let solve = async () => {
    const nsc = await readInt();
    for(let sc = 0; sc < nsc; sc++) {
        const n = await readInt();
        console.log(`? 1`);
        await readInt();
        const res = new Array(n + 1);
        let total = 1;
        const cycle = new Array(n + 1);
        let ncycle = 0;
        for (let i = 1; i <= n; i++) {
            if (!res[i]) {
                if (i===n) {
                    res[n] = n;
                    break;
                }
                ncycle = 0;
                const beforeTotal = total;
                while (true) {
                    console.log(`? ${i}`);
                    const val = await readInt();
                    total++;
                    if (res[val])
                        break;
                    res[val] = true;
                    cycle[ncycle] = val;
                    ncycle++;
                }
                let cur = i;
                for (let j = (total - 2) % ncycle, cnt = 1; cnt <= ncycle; cnt++, j = (j + 1) % ncycle) {
                    res[cur] = cycle[j];
                    cur = res[cur];
                }
            }
        }

        console.log(`! ${res.slice(1).join(' ')}`)
    }
}

solve();

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

const readInt = async function(){
    return parseInt(await getLine());
}

const readIntArray = async function() {
    return (await getLine()).split(' ').map(num => parseInt(num));
}

let solve = async () => {
    const nsc = await readInt();
    for(let sc = 0; sc < nsc; sc++) {
        const n = await readInt();
        const res = new Array(n + 1);
        let total = 0;
        const cycle = new Array(n + 1);
        let ncycle = 0;
        for (let i = 1; i <= n; i++) {
            if (!res[i]) {
                ncycle = 0;
                const beforeTotal = total;
                while (true) {
                    console.log(`? ${i}`);
                    const val = await readInt();
                    total++;
                    if (res[val])
                        break;
                    res[val] = true;
                    cycle[ncycle] = val;
                    ncycle++;
                }
                let cur = i;
                for (let j = (total - 1) % ncycle, cnt = 1; cnt <= ncycle; cnt++, j = (j + 1) % ncycle) {
                    res[cur] = cycle[j];
                    cur = res[cur];
                }
            }
        }

        console.log(`! ${res.slice(1).join(' ')}`)
    }
}

solve();

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

const readInt = async function(){
    return parseInt(await getLine());
}

const readIntArray = async function() {
    return (await getLine()).split(' ').map(num => parseInt(num));
}

let solve = async () => {
    const n = await readInt();
    const res = new Array(n+1);
    let total = 0;
    const cycle = new Array(n + 1);
    const was = new Array(n+1);
    let ncycle = 0;
    for(let i = 1; i <= n; i++) {
        if (!res[i]) {
            ncycle = 0;
            const beforeTotal = total;
            while (true) {
                console.log(`? ${i}`);
                const val = await readInt();
                total++;
                if (res[val])
                    break;
                res[val] = true;
                cycle[ncycle] = val;
                ncycle++;
            }
            let cur = i;
            for(let j = (total - 1)%ncycle, cnt=1; cnt<=ncycle; cnt++, j=(j+1)%ncycle) {
               res[cur] = cycle[j];
               cur = res[cur];
            }
        }
    }

    console.log(`! ${res.slice(1).join(' ')}`)
}

solve();


Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).

The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly. Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.

Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.

Note  First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.

var input = readline().trim().split(' ').map((x)=>parseInt(x));
var n=input[0],t1=input[1],t2=input[2],k=input[3];

var participant = function(a,b,i) {
	this.a = a;
	this.b =b;
	this.i = i+1;
	this.maxi = Math.max(this.a*t1*(100-k)/100+this.b*t2,this.b*t1*(100-k)/100+this.a*t2).toFixed(2);
}
participant.prototype.print=function(){
    print(this.i+' '+this.maxi)
}
var p=[];
var ab;
for (var i = 0; i < n; i++) {
	ab=readline().trim().split(' ').map((x)=>parseFloat(x));
	p.push(new participant(ab[0],ab[1],i));
}
var sort = function(p1,p2) {
	return p1.maxi==p2.maxi?(p1.i-p2.i):(p2.maxi-p1.maxi);
}
p.sort(sort);

for (var i in p) {
	p[i].print();
}

var input = readline().trim().split(' ').map((x)=>parseInt(x));
var n=input[0],t1=input[1],t2=input[2],k=input[3];

var participant = function(a,b,i) {
	this.a = a;
	this.b =b;
	this.i = i+1;
	this.maxi = (parseInt(Math.max(this.a*t1*(100-k)/100+this.b*t2,this.b*t1*(100-k)/100+this.a*t2)*100)*1.0)/100;
}
participant.prototype.print=function(){
    var out =this.i+' '+this.maxi;
    var m = (this.maxi+'').split('.')[1];
    if(m==undefined)
    out+='.00'
    else if(m.length==0)
        out+='00';
    else if(m.length==1)
     out+='0';
    print(out)
}
var p=[];
var ab;
for (var i = 0; i < n; i++) {
	ab=readline().trim().split(' ').map((x)=>parseFloat(x));
	p.push(new participant(ab[0],ab[1],i));
}
var sort = function(p1,p2) {
	return p1.maxi==p2.maxi?(p1.i-p2.i):(p2.maxi-p1.maxi);
}
p.sort(sort);

for (var i in p) {
	p[i].print();
}


This is a hard version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.You have to color all its characters the minimum number of colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $$$s$$$).After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.The goal is to make the string sorted, i.e. all characters should be in alphabetical order.Your task is to find the minimum number of colors which you have to color the given string in so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of exactly $$$n$$$ lowercase Latin letters.

In the first line print one integer $$$res$$$ ($$$1 \le res \le n$$$) — the minimum number of colors in which you have to color the given string so that after coloring it can become sorted by some sequence of swaps. In the second line print any possible coloring that can be used to sort the string using some sequence of swaps described in the problem statement. The coloring is the array $$$c$$$ of length $$$n$$$, where $$$1 \le c_i \le res$$$ and $$$c_i$$$ means the color of the $$$i$$$-th character.

'use strict'

readline();
const x = [ 'a' ], d = [];
readline().split('').forEach(c => {
    let i = 0;
    while (c < x[i]) if (++i === x.length) x.push(c);
    x[i] = c;
    d.push(i+1);
})
print(`${Math.max(...d)}\n${d.join(' ')}`)

'use strict'

readline();
const x = [ 'a' ], d = [];

readline().split('').forEach(c => {
    let i = 0, j = x.length - 1, m;
    if (c < x[j]) j++;
    else if (c >= x[i]) j = i;
    else while(i !== (m = (i + j) >> 1)) if (c < x[m]) i = m; else j = m;

    x[j] = c;
    d.push(j+1);
})
print(`${Math.max(...d)}\n${d.join(' ')}`)


Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.Mishka can put a box i into another box j if the following conditions are met:  i-th box is not put into another box;  j-th box doesn't contain any other boxes;  box i is smaller than box j (ai < aj). Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.Help Mishka to determine the minimum possible number of visible boxes!

The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.

Print the minimum possible number of visible boxes.

NoteIn the first example it is possible to put box 1 into box 2, and 2 into 3.In the second example Mishka can put box 2 into box 3, and box 4 into box 1.

readline();
boxes = readline().split(' ');
boxes.sort();

res = 0;
for(var i=0; i< boxes.length; i++){
    var num = 0;
    for (var j = 0; j < boxes.length; j++) {
        if(boxes[j]>num){
            num = boxes[j];
            boxes[j] = 0;
        }
    }
    num>0? res++:0
}

print(res);


Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the dictionary), but he is not allowed to swap any of them. The only operation he is allowed to do is to reverse any of them (first character becomes last, second becomes one before last and so on).To reverse the i-th string Vasiliy has to spent ci units of energy. He is interested in the minimum amount of energy he has to spent in order to have strings sorted in lexicographical order.String A is lexicographically smaller than string B if it is shorter than B (|A| < |B|) and is its prefix, or if none of them is a prefix of the other and at the first position where they differ character in A is smaller than the character in B.For the purpose of this problem, two equal strings nearby do not break the condition of sequence being sorted lexicographically.

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of strings. The second line contains n integers ci (0 ≤ ci ≤ 109), the i-th of them is equal to the amount of energy Vasiliy has to spent in order to reverse the i-th string.  Then follow n lines, each containing a string consisting of lowercase English letters. The total length of these strings doesn't exceed 100 000.

If it is impossible to reverse some of the strings such that they will be located in lexicographical order, print  - 1. Otherwise, print the minimum total amount of energy Vasiliy has to spent.

NoteIn the second sample one has to reverse string 2 or string 3. To amount of energy required to reverse the string 3 is smaller.In the third sample, both strings do not change after reverse and they go in the wrong order, so the answer is  - 1.In the fourth sample, both strings consists of characters 'a' only, but in the sorted order string "aa" should go before string "aaa", thus the answer is  - 1.

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const cost = getInts()
  const words = []
  const wordsRev = []
  const INF = Number.MAX_SAFE_INTEGER

  for (let i = 0; i < n; ++i) {
    const w = getLine()[0]
    words.push(w)
    wordsRev.push(reve(w))
  }

  words.push(words[n - 1])
  wordsRev.push(wordsRev[n - 1])

  const dp = [[cost[0], 0]]
  for (let i = 1; i <= n; ++i) {
    dp.push([INF, INF])

    if (wordsRev[i - 1] <= wordsRev[i]) {
      dp[i][0] = dp[i - 1][0] + cost[i]
    }

    if (wordsRev[i - 1] <= words[i]) {
      dp[i][1] = dp[i - 1][0]
    }

    if (words[i - 1] <= wordsRev[i]) {
      dp[i][0] = Math.min(dp[i - 1][1] + cost[i], dp[i][0])
    }

    if (words[i - 1] <= words[i]) {
      dp[i][1] = Math.min(dp[i][1], dp[i - 1][1])
    }
  }

  let ans = Math.min(dp[n - 1][0], dp[n - 1][1])
  print(ans !== INF ? ans : -1)
}

function reve(w) {
  return w.split('').reverse().join('')
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const cost = getInts()
  const words = []
  const INF = Number.MAX_SAFE_INTEGER

  for (let i = 0; i < n; ++i) {
    const w = getLine()[0]
    words.push(w)
  }

  words.push(words[n - 1])

  let ok = true
  const dp = [[cost[0], 0]]
  for (let i = 1; i <= n; ++i) {
    let found = false
    dp.push([INF, INF])

    if (reve(words[i - 1]) <= reve(words[i])) {
      dp[i][0] = dp[i - 1][0] + cost[i]
      found = true
    }

    if (reve(words[i - 1]) <= words[i]) {
      dp[i][1] = dp[i - 1][0]
      found = true
    }

    if (words[i - 1] <= reve(words[i])) {
      dp[i][0] = Math.min(dp[i - 1][1] + cost[i], dp[i][0])
      found = true
    }

    if (words[i - 1] <= words[i]) {
      dp[i][1] = Math.min(dp[i][1], dp[i - 1][1])
      found = true
    }

    if (!found) ok = false
  }

  let ans = Math.min(dp[n - 1][0], dp[n - 1][1])
  print(ok && ans !== INF ? ans : -1)
}

function reve(w) {
  return w.split('').reverse().join('')
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const cost = getInts()
  const words = []

  for (let i = 0; i < n; ++i) {
    const w = getLine()[0]
    words.push(w)
  }

  words.push(words[n - 1])

  let ok = true
  const dp = [[cost[0], 0]]
  for (let i = 1; i <= n; ++i) {
    let found = false
    dp.push([1e10, 1e10])

    if (reve(words[i - 1]) <= reve(words[i])) {
      dp[i][0] = dp[i - 1][0] + cost[i]
      found = true
    }

    if (reve(words[i - 1]) <= words[i]) {
      dp[i][1] = dp[i - 1][0]
      found = true
    }

    if (words[i - 1] <= reve(words[i])) {
      dp[i][0] = Math.min(dp[i - 1][1] + cost[i], dp[i][0])
      found = true
    }

    if (words[i - 1] <= words[i]) {
      dp[i][1] = Math.min(dp[i][1], dp[i - 1][1])
      found = true
    }

    if (!found) ok = false
  }

  let ans = Math.min(dp[n - 1][0], dp[n - 1][1])
  print(ok ? ans : -1)
}

function reve(w) {
  return w.split('').reverse().join('')
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const cost = getInts()
  const words = []
  const INF = Number.MAX_SAFE_INTEGER

  for (let i = 0; i < n; ++i) {
    const w = getLine()[0]
    words.push(w)
  }

  words.push(words[n - 1])

  let ok = true
  const dp = [[cost[0], 0]]
  for (let i = 1; i <= n; ++i) {
    let found = false
    dp.push([INF, INF])

    if (reve(words[i - 1]) <= reve(words[i])) {
      dp[i][0] = dp[i - 1][0] + cost[i]
      found = true
    }

    if (reve(words[i - 1]) <= words[i]) {
      dp[i][1] = dp[i - 1][0]
      found = true
    }

    if (words[i - 1] <= reve(words[i])) {
      dp[i][0] = Math.min(dp[i - 1][1] + cost[i], dp[i][0])
      found = true
    }

    if (words[i - 1] <= words[i]) {
      dp[i][1] = Math.min(dp[i][1], dp[i - 1][1])
      found = true
    }

    if (!found) ok = false
  }

  let ans = Math.min(dp[n - 1][0], dp[n - 1][1])
  print(ok ? ans : -1)
}

function reve(w) {
  return w.split('').reverse().join('')
}


Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate axes. Polyline is allowed to have self-intersections. Bender can take a rod and fold it exactly once in any place to form an angle of 90 degrees. Then he can attach the place of the fold to some unoccupied nail and attach two ends of this rod to adjacent nails. A nail is considered unoccupied if there is no rod attached to it (neither by it's end nor the by the fold place). No rod could be used twice. It is not required to use all the rods.Help Bender to solve this difficult task.

The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The last line contains m integers — the lenghts of the rods. All coordinates do not exceed 104 by absolute value. Lengths of the rods are between 1 and 200 000. No rod can be used twice. It is guaranteed that all segments of the given polyline are parallel to coordinate axes. No three consecutive nails lie on the same line.

If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod. If there are multiple solutions, print any of them.

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
const N = lll[0]
const M = lll[1]

const ns = [undefined]

for (let i = 0; i < N; i++) {
  ns.push(readline().split(' ').map(v => parseInt(v)))
}

const ls = readline().split(' ').map(v => parseInt(v))

ns[0] = ns[ns.length - 1]
ns.push(ns[1])

const ds = [undefined]
for (let i = 1; i < ns.length - 1; i++) {
  ds.push(getD(ns[i - 1], ns[i], ns[i + 1]))
}

let res = []
let ppp = 'NO'
let lss = JSON.parse(JSON.stringify(ls))
for (let i = 1; i < ds.length - 1; i = i + 2) {
  const li = lss.indexOf(ds[i])
  if (~li) {
    res.push(li + 1)
    lss[li] = -1
  } else {
    ppp = 'NO'
    break
  }
  ppp = 'YES'
}

if (ppp == 'YES') {
  res = res.join(' -1 ')
  res += ' -1'
}

if (ppp == 'NO') {
  res = []
  for (let i = 2; i < ds.length; i = i + 2) {
    const li = lss.indexOf(ds[i])
    if (~li) {
      res.push(li + 1)
      lss[li] = -1
    } else {
      ppp = 'NO'
      break
    }
    ppp = 'YES'
  }
}

if (ppp == 'YES' && typeof res != 'string') {
  res = res.join(' -1 ')
  res = '-1 ' + res
}

if (ppp == 'NO') {
  print('NO')
} else {
  print('YES')
  print(res)
}

function getD (p1, p2, p3) {
  return Math.abs(p1[0] - p2[0])
    + Math.abs(p1[1] - p2[1])
    + Math.abs(p2[0] - p3[0])
    + Math.abs(p2[1] - p3[1])
}


Ela needs to send a large package from machine $$$1$$$ to machine $$$n$$$ through a network of machines. Currently, with the network condition, she complains that the network is too slow and the package can't arrive in time. Luckily, a Wiring Wizard offered her a helping hand.The network can be represented as an undirected connected graph with $$$n$$$ nodes, each node representing a machine. $$$m$$$ wires are used to connect them. Wire $$$i$$$ is used to connect machines $$$u_i$$$ and $$$v_i$$$, and has a weight $$$w_i$$$. The aforementioned large package, if going through wire $$$i$$$, will move from machine $$$u_i$$$ to machine $$$v_i$$$ (or vice versa) in exactly $$$w_i$$$ microseconds. The Wiring Wizard can use his spell an arbitrary number of times. For each spell, he will choose the wire of index $$$i$$$, connecting machine $$$u_i$$$ and $$$v_i$$$, and rewire it following these steps:  Choose one machine that is connected by this wire. Without loss of generality, let's choose $$$v_i$$$.  Choose a machine that is currently connecting to $$$v_i$$$ (including $$$u_i$$$), call it $$$t_i$$$. Disconnect the wire indexed $$$i$$$ from $$$v_i$$$, then using it to connect $$$u_i$$$ and $$$t_i$$$. The rewiring of wire $$$i$$$ will takes $$$w_i$$$ microseconds, and the weight of the wire will not change after this operation. After a rewiring, a machine might have some wire connect it with itself. Also, the Wiring Wizard has warned Ela that rewiring might cause temporary disconnections between some machines, but Ela just ignores it anyway. Her mission is to send the large package from machine $$$1$$$ to machine $$$n$$$ as fast as possible. Note that the Wizard can use his spell on a wire zero, one, or many times. To make sure the network works seamlessly while transferring the large package, once the package starts transferring from machine $$$1$$$, the Wiring Wizard cannot use his spell to move wires around anymore.Ela wonders, with the help of the Wiring Wizard, what is the least amount of time needed to transfer the large package from machine $$$1$$$ to $$$n$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows. The first line contains $$$n$$$ and $$$m$$$ ($$$2 \le n \le 500$$$, $$$n - 1 \le m \le 250 000$$$), the number of nodes and number of wires, respectively. For the next $$$m$$$ lines, $$$i$$$-th line will contains $$$u_i$$$, $$$v_i$$$ and $$$w_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$1 \le w_i \le 10^9$$$) - the indices 2 machines that are connected by the $$$i$$$-th edge and the weight of it. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$500$$$ and the sum of $$$m$$$ over all test cases does not exceed $$$250 000$$$. The graph in each test case is guaranteed to be connected, no self-loops, but it can contain multiple edges.

For each test case, output one integer denotes the least amount of time needed to transfer the large package from machine $$$1$$$ to $$$n$$$.

NoteHere is the graph in the first test case in the sample input:  Ela can ask the Wiring Wizard to use his spell on wire with the index of $$$7$$$, which is connecting machines $$$2$$$ and $$$3$$$. Then, since the machine $$$8$$$ is connected to machine $$$3$$$, the Wiring Wizard can disconnect wire $$$7$$$ from machine $$$3$$$ and connect it to machine $$$8$$$ in $$$3$$$ microseconds (weight of wire $$$3$$$).After that, the package can be sent from machine $$$1$$$ to machine $$$8$$$ in $$$6$$$ microseconds. Therefore, the answer is $$$3 + 6 = 9$$$ microseconds.Here is the graph in the third test case in the sample input:

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        m = rn(),
        edges = new Array(m);
  const dist = Array.from({
    length: n
  }, () => new Array(n).fill(Infinity)),
        min = new Array(n).fill(Infinity);
  for (let i = 0; i < n; i++) dist[i][i] = 0;
  for (let i = 0; i < m; i++) {
    let [u, v, c] = rns(3);
    u--;
    v--;
    edges[i] = [u, v, c];
    dist[u][v] = 1;
    dist[v][u] = 1;
  }
  for (let k = 0; k < n; k++) {
    for (let i = 0; i < n; i++) {
      for (let j = 0; j < n; j++) {
        dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  for (let i = 0; i < n; i++) {
    let ans = Infinity;
    for (let j = 0; j < n; j++) {
      ans = Math.min(ans, dist[i][j] + dist[j][0] + dist[j][n - 1]);
    }
    min[i] = ans;
  }
  let res = Infinity;
  for (let [u, v, c] of edges) {
    res = Math.min(res, (dist[u][0] + dist[v][n - 1] + 1) * c, (dist[v][0] + dist[u][n - 1] + 1) * c, (min[u] + 2) * c, (min[v] + 2) * c);
  }
  return res;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8')
.split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();


Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.  There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.

The first line of input contains integer n (1 ≤ n ≤ 105), the number of days. In the next n lines, i-th line contains two integers ai and pi (1 ≤ ai, pi ≤ 100), the amount of meat Duff needs and the cost of meat in that day.

Print the minimum money needed to keep Duff happy for n days, in one line.

NoteIn the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.

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

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

  let [a, p] = d.split(' ').map(Number);

  if (a && p) {
    minPrice = Math.min(minPrice, p);
    ans += a * minPrice;
  }

  c++;
});

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

const input = [];

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

RL.on('line', (line) => {
    input.push(line);
});

RL.on('close', () => {
  const n = input[0].split(' ').map(x => parseInt(x));

  let [meat, cost] = input[1].split(' ').map(x => parseInt(x));
  let answer = meat*cost;

  for (let i = 2; i <= n; i += 1) {
    const pair = input[i].split(' ').map(x => parseInt(x));
    if (pair[1] < cost) {
      cost = pair[1];
    }
    answer += pair[0] * cost;
  }

  console.log(answer);
});

//Input
//                      ai pi          1 <= ai, pi <= 100
// var n = "3"; var arr = ["1 3", "2 2", "3 1"];       // 10
// var n = "3"; var arr = ["1 3", "2 2", "3 2"];       // 8
// var n = "1"; var arr = ["39 52"];                   // 2028
// var n = "2"; var arr = ["125 56", "94 17"];         // 2998
// var n = "5"; var arr = ["39 213", "95 89", "70 90", "9 55", "85 32"];       // 6321
// var n = "12"; var arr = ["70 11",  "74 27",  "32 11",  "26 83",  "57 18",  "97 28",  "75 43",  "75 21",  "84 29",  "16 2",  "89 63",  "21 88"];       // 6742

var n = readline();

// retorno = eval(n, arr);
retorno = eval(n);

//Solution
// function eval(n, arr){
function eval(n){
    n = parseInt(n);
    var daysCosts = new Array(n+1).join("").split("");

    var arr = "";
    for(var i = 0 ; i < n ; i++){
        arr = readline();
        daysCosts[i] = arr.split(" ").map(function(x){ return parseInt(x)});
        // daysCosts[i] = arr[i].split(" ").map(function(x){ return parseInt(x)});
    };
    write(giveTheLowestCost(n, daysCosts));
    // console.log(giveTheLowestCost(n, daysCosts));
};

function giveTheLowestCost(n, daysCosts){
    var answer;
    var minimumCost = 0;
    var totalCost = 0;
    //console.log(daysCosts[0]);
    for(var i = 0 ; i < n ; i++){
        if(i == 0){
            minimumCost = daysCosts[i][1];
            totalCost = daysCosts[i][0]*daysCosts[i][1];
            //console.log("minimumCost: " + minimumCost + "    totalCost: " + totalCost);
            //console.log("dayCosts[" + i + "][1]: " + daysCosts[i][1] + "    minimumCost: " + minimumCost);
        } else{
            if(minimumCost > daysCosts[i][1]){
                minimumCost = daysCosts[i][1];
            };
            totalCost += daysCosts[i][0]*minimumCost;
            //console.log("dayCosts[" + i + "][1]: " + daysCosts[i][1] + "    minimumCost: " + minimumCost);
        };
    };

    //console.log("minimumCost: " + minimumCost + "    totalCost: " + totalCost);
    return totalCost;
};

function cmp(x){
	return parseInt(x);
}
var n = parseInt(readline());
	var a = [];
	for(var i = 0; i < n; i++)
	{
		a[i] = readline().split(" ").map(cmp);
	}
	//var a = [[1,3],[2,1],[3,2]];
	var minimum = 200;
	var sum = 0;
	for(var j = 0; j < n; j ++)
	{
		if(a[j][1] < minimum)
		minimum = a[j][1];
		sum += minimum*a[j][0];
	}
	print(sum);

var n =  readline();///.split(" ");
var str = [];  //readline().split(" "); "3 3".split(" "),"3 3".split(" "),"3 3".split(" ")
var min = 100;
var sum = 0;
		for (var i=0; i<+n; i++){
			str.push(readline().split(" "));
		}

		for (var i=0; i<+n; i++){
		    if (+str[i][1]<min){
			sum += +str[i][1]*str[i][0];
			 min = +str[i][1];}
			else {
				sum +=str[i][0]*min;
			}

		}
	 print(sum);

var d = parseInt(readline());
var lines = [];
var f = function(elem){
    return parseInt(elem);
};
for(var i = 0; i < d; i++)
    lines.push(readline().split(" ").map(f));

    var m = lines[0];
    var c = m[0] * m[1];
    for(var i = 1; i < lines.length;i++){
        if(lines[i][1] < m[1]) m = lines[i];
        c += lines[i][0] * m[1];
    }

    print(c);

var n = Number(readline());

var price = Infinity, result = 0;
for (var i = 0; i<n; i++) {
    var s = readline().split(' ').map(Number);
    price = Math.min(price, s[1]);
    result += s[0] * price;
}
print(result);

var n, a = [], p = [], args = [], result;
var total = 0, prev = 0;

function main() {
    n = +readline();

    for (var i = 0; i < n; i++) {
        args = readline().split(" ").map(function(v) {return parseInt(v, 10)});
        a.push(args[0]);
        total += a[i];
        p.push(args[1]);
    }

    result = total * p[0];
    total -= a[0];
    prev = 0;
    for (i = 1; i < n; i++) {
        if (result > result - total * p[prev] + total * p[i]) {
            result = result - total * p[prev] + total * p[i];
            prev = i;
        }
        total -= a[i];
    }

    print(result);
}

main();

"use strict";

var n = +readline();

var result = 0;
for (let i = 0, pmin = +Infinity; i < n; ++i) {
    let input = readline().split(' ').map(value => +value);
    let a = input[0];
    let p = input[1];

    pmin = Math.min(pmin, p);

    result += a * pmin;
}

write(result);

n=Number(readline())
a=new Array(n), p=new Array(n), mm=new Array(n)
for (var i=0; i<n; ++i) {
    X=readline().split(' ').map(Number)
    a[i]=X[0]
    p[i]=X[1]
}
mm[0]=p[0]
r=p[0]*a[0]
for (var i=1; i<n; ++i) {
    mm[i]=Math.min(mm[i-1],p[i])
    r+=mm[i]*a[i]
}

print(r)

a=[],p=[], mm=[]
n=Number(readline())
for (var i=0; i<n; ++i) {
    X=readline().split(' ').map(Number)
    a.push(X[0])
    p.push(X[1])
}
mm.push(p[0])
for (var i=1; i<n; ++i) {
    mm[i]=Math.min(mm[i-1],p[i])
}
r=0
for (var i=0; i<n; ++i) {
    r+=mm[i]*a[i]
}
print(r)

n=Number(readline())
a=new Array(n), p=new Array(n), mm=new Array(n)
for (var i=0; i<n; ++i) {
    X=readline().split(' ').map(Number)
    a[i]=X[0]
    p[i]=X[1]
}
mm[0]=p[0]
for (var i=1; i<n; ++i) {
    mm[i]=Math.min(mm[i-1],p[i])
}
r=0
for (var i=0; i<n; ++i) {
    r+=mm[i]*a[i]
}
print(r)

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '3';
            case 2: return '1 3';
            case 3: return '2 1';
            case 4: return '3 2';
        }
    }

    var write = console.log;
}

var n = +readline();

var a, p;

var s = 0;
var m;

for (var i = 0; i < n; i ++) {
    var x = readline().split(' ');

    a = +x[0];
    p = +x[1];

    if (m === undefined || m > p) {
        m = p;
    }

    s += a * m;
}

write(s);

// var inputString = "5\n2 4\n2 2\n2 3\n2 3\n2 1\n";

// var readline = (function () {
//   var regex = /(.+)\s/g,
//       i = 0;

//   return function () {
//     return inputString.match(regex)[i++].replace(/\n/g, "");
//   }
// })();

// function write (token) {
//   console.log(token);
// }
// function print (token) {
//   console.log(token);
// }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

var days = parseInt(readline(), 10);

var meatNeed = [],
    price = [];

var tempInput = "";
for (var i = 0; i < days; i++) {
    tempInput = readline().split(" ");
    price.push(parseInt(tempInput.pop(), 10));
    meatNeed.push(parseInt(tempInput.pop(), 10));
}

var minPrice = {};
minPrice.price = Math.min.apply(null, price);
minPrice.day = price.indexOf(minPrice.price);

var minSum = 0;

var i = 0;
while (i < days) {
    if (price[i] < price[i+1]) {
        var j = i;
        while (price[i] <= price[j]) {
            minSum += price[i] * meatNeed[j];
            j++;
        }
        i = j;
    } else {
        minSum += price[i] * meatNeed[i];
        i++;
    }
}

write(minSum);

var n = Number(readline());
var inp;
var min = 101;
var sum = 0;
for(var i = 0; i < n ; i++){
    inp = readline().split(" ").map(cur => Number(cur));
    (inp[1] < min) ? min = inp[1] : null;
    sum += min*inp[0];
}

print(sum);

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

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

  let [a, p] = d.split(' ').map(Number);

  ans += a * p;
  c++;
});

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

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

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

  let [a, p] = d.split(' ').map(Number);
  minPrice = Math.min(minPrice, p);

  ans += a * minPrice;
  c++;
});

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

var n = parseInt(readline());
	var a = [];
	for(var i = 0; i < n; i++)
	{
		a[i] = readline().split(" ").map(function(elment){return parseInt(elment);});
	}

	//var a=[[1,3],[2,1],[3,2]];
	var minimum = 200;
	var temp;
	for(var j = 0; j < n; j++)
	{
		minimum = Math.min(minimum,a[j][1]);
	}
	for(var k = 0; k < n; k++)
	{
		if(minimum === a[k][1])
		{
			temp = k;
			break;
		}
	}
	var ans=0;
	for(var l = 0; l <= temp; l++)
	{
		ans += a[l][0]*a[l][1];
	}
	for(var u = temp+1; u < n; u++)
	{
		ans += a[u][0]*minimum;
	}
	print(ans);

var n =  readline();///.split(" ");
var str = [];  //readline().split(" ");
var min = 100;
var sum = 0;
		for (var i=0; i<+n; i++){
			str.push([readline().split(" ")]);
		}

		for (var i=0; i<+n; i++){
		    if (+str[i][1]<min){
			sum += +str[i][1]*str[i][0];
			 min = +str[i][1];}
			else {
				sum +=str[i][0]*min;
			}

		}
	 print(sum);

var n, a = [], p = [], args = [], result;
var total = 0;

function main() {
    n = +readline();

    for (var i = 0; i < n; i++) {
        args = readline().split(" ").map(function(v) {return parseInt(v, 10)});
        a.push(args[0]);
        total += a[i];
        p.push(args[1]);
    }

    result = total * p[0];
    total -= a[0];
    for (i = 1; i < n; i++) {
        if (result > result - total * p[i - 1] + total * p[i]) {
            result = result - total * p[i - 1] + total * p[i];
        }
        total -= a[i];
    }

    print(result);
}

main();

// var inputString = "3\n1 3\n2 1\n3 2\n";

// var readline = (function () {
//   var regex = /(.+)\s/g,
//       i = 0;

//   return function () {
//     return inputString.match(regex)[i++].replace(/\n/g, "");
//   }
// })();

// function write (token) {
//   console.log(token);
// }
// function print (token) {
//   console.log(token);
// }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

var days = parseInt(readline(), 10);

var meatNeed = [],
    price = [];

var tempInput = "";
for (var i = 0; i < days; i++) {
    tempInput = readline().split(" ");
    price.push(parseInt(tempInput.pop(), 10));
    meatNeed.push(parseInt(tempInput.pop(), 10));
}

var minPrice = {};
minPrice.price = Math.min.apply(null, price);
minPrice.day = price.indexOf(minPrice.price);

var minSum = 0;

for (var i = 0; i < days; i++) {
    if (i < minPrice.day) {
        minSum += meatNeed.shift() * price.shift();
    } else {
        minSum += meatNeed.reduce(function (sum, cur) {
            return sum + cur * minPrice.price;
        }, 0) * minPrice.price;
        break;
    }
}

write(minSum);

// var inputString = "5\n5 5\n4 4\n3 3\n2 2\n2 2\n";

// var readline = (function () {
//   var regex = /(.+)\s/g,
//       i = 0;

//   return function () {
//     return inputString.match(regex)[i++].replace(/\n/g, "");
//   }
// })();

// function write (token) {
//   console.log(token);
// }
// function print (token) {
//   console.log(token);
// }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

var days = parseInt(readline(), 10);

var meatNeed = [],
    price = [];

var tempInput = "";
for (var i = 0; i < days; i++) {
    tempInput = readline().split(" ");
    price.push(parseInt(tempInput.pop(), 10));
    meatNeed.push(parseInt(tempInput.pop(), 10));
}

var minPrice = {};
minPrice.price = Math.min.apply(null, price);
minPrice.day = price.indexOf(minPrice.price);

var minSum = 0;

for (var i = 0; i < days; i++) {
    if (i < minPrice.day) {
        minSum += meatNeed.shift() * price.shift();
    } else {
        minSum += meatNeed.reduce(function (sum, cur) {
            return sum + cur * minPrice.price;
        }, 0);
        break;
    }
}

write(minSum);