The Dogeforces company has $$$k$$$ employees. Each employee, except for lower-level employees, has at least $$$2$$$ subordinates. Lower-level employees have no subordinates. Each employee, except for the head of the company, has exactly one direct supervisor. The head of the company is a direct or indirect supervisor of all employees. It is known that in Dogeforces, each supervisor receives a salary strictly more than all his subordinates.The full structure of the company is a secret, but you know the number of lower-level employees and for each pair of lower-level employees, the salary of their common supervisor is known (if there are several such supervisors, then the supervisor with the minimum salary). You have to restore the structure of the company.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 500$$$) — the number of lower-level employees. This is followed by $$$n$$$ lines, where $$$i$$$-th line contains $$$n$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i,n}$$$ ($$$1 \le a_{i,j} \le 5000$$$) — salary of the common supervisor of employees with numbers $$$i$$$ and $$$j$$$. It is guaranteed that $$$a_{i,j} = a_{j,i}$$$. Note that $$$a_{i,i}$$$ is equal to the salary of the $$$i$$$-th employee.

In the first line, print a single integer $$$k$$$ — the number of employees in the company. In the second line, print $$$k$$$ integers $$$c_1, c_2, \dots, c_k$$$, where $$$c_i$$$ is the salary of the employee with the number $$$i$$$. In the third line, print a single integer $$$r$$$ — the number of the employee who is the head of the company. In the following $$$k-1$$$ lines, print two integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le k$$$) — the number of the employee and his direct supervisor. Note that the lower-level employees have numbers from $$$1$$$ to $$$n$$$, and for the rest of the employees, you have to assign numbers from $$$n+1$$$ to $$$k$$$. If there are several correct company structures, you can print any of them.

NoteOne of the possible structures in the first example:

let n = 0;
let a = [];
let employees = [];
let salaries = [];
let supervisors = [];

const traceRoot = ids => {
  if (ids.length === 1) return ids[0];

  let rootSalary = 0;
  for (const idu of ids)
    for (const idv of ids) {
      rootSalary = Math.max(rootSalary, a[idu][idv]);
    }

  let groups = [];
  for (let id of ids) {
    let found = false;
    for (let group of groups) {
      if (a[group[0]][id] < rootSalary) {
        found = true;
        group.push(id);
        break;
      }
    }
    if (!found) groups.push([id]);
  }
  const rootEmployee = employees.length;
  employees.push(rootEmployee);
  salaries.push(rootSalary);

  for (let group of groups) supervisors.push([traceRoot(group), rootEmployee]);

  return rootEmployee;
};

const main = () => {
  n = readInt();
  for (let i = 0; i < n; i++) {
    const r = readListInt();
    a.push(r);
  }
  for (let i = 0; i < n; i++) {
    salaries.push(a[i][i]);
    employees.push(i);
  }

  const ceo = traceRoot(employees);

  console.log(employees.length);
  console.log(salaries.join(" "));
  console.log(ceo + 1);
  for (const supervisor of supervisors) {
    console.log(`${supervisor[0] + 1} ${supervisor[1] + 1}`);
  }
};

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 => string.trim());
  main();
});

const readLine = () => {
  return inputString[currentLine++];
};

const readInt = () => {
  return parseInt(inputString[currentLine++]);
};

const readListInt = () => {
  return inputString[currentLine++].split(" ").map(s => parseInt(s));
};


This is an easier version of the problem with smaller constraints.Korney Korneevich dag up an array $$$a$$$ of length $$$n$$$. Korney Korneevich has recently read about the operation bitwise XOR, so he wished to experiment with it. For this purpose, he decided to find all integers $$$x \ge 0$$$ such that there exists an increasing subsequence of the array $$$a$$$, in which the bitwise XOR of numbers is equal to $$$x$$$.It didn't take a long time for Korney Korneevich to find all such $$$x$$$, and he wants to check his result. That's why he asked you to solve this problem!A sequence $$$s$$$ is a subsequence of a sequence $$$b$$$ if $$$s$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements.A sequence $$$s_1, s_2, \ldots , s_m$$$ is called increasing if $$$s_1 < s_2 < \ldots < s_m$$$.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 500$$$) — the elements of the array $$$a$$$.

In the first line print a single integer $$$k$$$ — the number of found $$$x$$$ values. In the second line print $$$k$$$ integers in increasing order $$$x_1, x_2, \ldots x_k$$$ ($$$0 \le x_1 < \ldots < x_k$$$) — found $$$x$$$ values.

NoteIn the first test case:  To get value $$$x = 0$$$ it is possible to choose and empty subsequence  To get value $$$x = 2$$$ it is possible to choose a subsequence $$$[2]$$$  To get value $$$x = 4$$$ it is possible to choose a subsequence $$$[4]$$$  To get value $$$x = 6$$$ it is possible to choose a subsequence $$$[2, 4]$$$

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 = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const ans = { 0: -1 }
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        for (let k = 0; k <= 512; k++) {
            if ((k in ans) && ans[k] < x) {
                ans[k ^ x] = Math.min(ans[k ^ x] || Infinity, x)
            }
        }
    }
    // console.log(ans)
    const ks = Object.keys(ans)
    return ks.length + '\n' + ks.sort((a, b) => +a - +b).join(' ')
}

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 = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const ans = { 0: -1 }
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        for (let k = 0; k <= 500; k++) {
            if ((k in ans) && ans[k] < x) {
                ans[k ^ x] = Math.min(ans[k ^ x] || Infinity, x)
            }
        }
    }
    // console.log(ans)
    const ks = Object.keys(ans)
    return ks.length + '\n' + ks.sort((a, b) => +a - +b).join(' ')
}

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 = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const ans = { 0: 1 }
    let cur = { 0: 1 }
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        const next = {}
        for (let k = 0; k <= x; k++) {
            if (cur[k]) {
                next[k] = 1
                next[k ^ x] = 1
                ans[k] = 1
                ans[k ^ x] = 1
            }
        }
        cur = next
    // console.log(ans)
    }
    const ks = Object.keys(ans)
    return ks.length + '\n' + ks.sort((a, b) => +a - +b).join(' ')
}

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 = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const set = {}
    set[0] = 1
    const xor = []
    for (let i = 0; i < arr.length; i++) {
        xor[i] = [arr[i]]
        set[arr[i]] = 1
        for (let j = 0; j < i; j++) {
            if (arr[i] > arr[j]) {
                for (let k = 0; k < xor[j].length; k++) {
                    const cur = arr[i] ^ xor[j][k]
                    xor[i].push(cur)
                    set[cur] = 1
                }
            }
        }
    }
    // console.log(xor)
    return Object.keys(set).sort((a, b) => +a - +b).join(' ')
}


The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:  Operation ++ increases the value of variable x by 1.  Operation -- decreases the value of variable x by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).

The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.

Print a single integer — the final value of x.

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

    let stdinInput = '';

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

    process.stdin.on('end', () => {
      main(stdinInput);
    })

    function main(data) {
      data = data.split('\n');
      const n = data.shift();
      let x = 0;
      for (let i = 0; i < n; i += 1) {
        if (data[i].match(/-/)) x -= 1;
        else x += 1;
      }
      process.stdout.write(x + '');
    }

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline();
	var k = s.indexOf("+");
	if(k == -1){meghdar--}
	else{meghdar++}

}
print(meghdar)

const main = () => {
  const N = Number(readline());

  var result = 0;

  for (var i = 0; i < N; i++) {
    if (readline().indexOf("-") >= 0) {
      result--;
    } else {
      result++;
    }
  }

  return result;
};

print(main());

function main() {
    const res = stdin.slice(1).reduce((s,x)=>{
        return s = (x[1] === "+") ? s+1 : s-1;
    },0)
    console.log(res)
}

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);

input=readline();
input=input.split(' ').map(e=>parseInt(e));
n=input[0]
ans=0;
while(n--){
    tmp=readline();
    ans+=(tmp.indexOf('+')===-1)?-1:1;
}
print(ans)

var operations = readline();
var value = 0;
for(var i = 0; i < operations; i++) {
    if(readline().indexOf('+') !== -1) {
        value++;
    } else {
        value--;
    }
}
print(value);

const n = Number(readline());
var x = 0;
var s ;
for(var i = 0; i<n ; i++ ){
   s = readline().split("");
   if(s.includes('-')){
       x--;
   }else{
       x++;
   }
}

print(x);//

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
var expect = 'n';
var x = 0;
rl.on('line',function(line){
    if(expect =='n'){
        n = parseInt(line);
        expect = 'statement';
        case_counter = 1;
    }else if (expect == 'statement'){
        if((line == '++X')||(line =='X++')){
            x++;
        } else {
            x--;
        }
        ++case_counter === n +1 ? rl.close() : 0;
    }
}).on('close', function(){
    console.log(x);
    process.exit(0);
});

var t = readline();
var x = 0;
while(t--){
    var str = readline();
    if(str == '++X' || str == 'X++'){
        x++;
    }else{
        x--;
    }
}

print(x);

var line_number = 0;
const cs = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

var lines = {};
cs.on("line", (input) => {
  if (input == "") {
    cs.close();
  }
  lines[line_number] = input.split(" ")
  line_number += 1;
}).on("close", () => {
  main();
  process.exit();
});

function isOp(str) {
  return str.length === 1 && str.match(/[<=>]/);
}
function isChr(str) {
  return str.length === 1 && str.match(/[a-z]/i);
}
function isInt(str) {
  return str.length === 1 && !isNaN(str);
}

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

function predict(test) {
  let op = "";
  let ops = [];
  let opVariables = [];
  let limits = [];
  for (let t of test) {
    // console.log(t);
    for (let i = 0; i < t.length; i++) {
      if (isOp(t[i])) {
        op = t[i];
        if (isOp(t[i + 1])) {
          op += t[i + 1];
          i += 1;
        }
        ops.push(op);
        op = "";
      } else if (isChr(t[i])) {
        // console.log(t[i])
        op = t[i];
        for (var j = i + 1; j < t.length; j++) {
          if (isChr(t[j]) || isInt(t[j])) {
            op += t[j];
            i = j;
          } else break;
        }
        opVariables.push(op);
        op = "";
      } else {
        if (i == 0 || (i > 0 && isOp(t[i - 1]))) {
          op = t[i];
          let j = i + 1;
          for (; j < t.length; j++) {
            if (isInt(t[j])) {
              op += t[j];
              i = j;
            } else break;
          }
          limits.push(op);
          op = "";
        }
      }
    }
  }

  let min = limits[0];
  let max = limits[1];

  let pvs = ops.map((o, i) => [o, opVariables[i]]);

  for (let pv of pvs) {
    if (pv[1] == undefined) {
      pv[1] = max;
    }
    // print(`${min} ${pv[0]} ${pv[1]} ?`)
    if (eval(`${min}${pv[0]}${pv[1]}`)) {
      // print(` ${min} ${pv[0]} ${pv[1]} true`)
      min = pv[1];
    } else {
      print("input error");
      process.exit();
    }
  }
}

var n
function main() {
    n = parseInt(lines[0][0], 10)
    predict(["1<=n<=150"])

    var x = 0
    for (var i = 1; i <= n; i++) {
        c = lines[i][0]
        // print(c)
        if (c[0] == '+' || c[c.length-1] == '+')
            x += 1
        else if (c[0] == "-" || c[c.length - 1] == "-")
            x -= 1;

    }

    print(x)
}

var input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
  console.log(input.split('\r\n').slice(1,-1).reduce((a, v) => v.includes('+') ? a+1:a-1, 0))
})

var num_lineas = readline(); // Leemos el número de lineas que debemos tratar
var sol = 0;
var linea;
// Por cada linea propuesta:
for (var i = 0; i < num_lineas; i++) {
    linea = readline(); // Leemos la linea
    // Si la linea contiene '+' sumamos 1 a la solución, en caso contrario restamos 1
    if (linea.indexOf('+') > -1) {
        sol++;
    } else {
        sol--;
    }

}
print(sol); // Imprimimos la solución

var DEBUG = 0

function prt(s) {
    (DEBUG ? console.log : print)(s);
}

var a, x = 0;
function solve(line) {
    if (a === undefined) {
        a = parseInt(line);
        return true;
    }
    if (line.charAt(1) === '-') {
        x--;
    } else {
        x++;
    }
    a--;
    if (a === 0) {
        prt(x);
        return false;
    }
    return true;
}

if (DEBUG) {
    var readline = require('readline');
    var rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout,
      terminal: false
    });
    rl.on('line', function(s){solve(s)});
} else {
    while (solve(readline()));
}

var num=readline();
var x=0;
for(var i=0;i<num;i++){
    var cur=readline();
    cur=cur.split("X");
    if(cur[0]=="++"||cur[1]=="++"){
        x+=1;
    }else{
        x-=1;
    }
}
print(x);

var cases = readline();
var res = 0;
for(var i = 0; i < cases; ++i){
    var op = readline();
    if(op.includes('--')) --res;
    if(op.includes('++')) ++res;
}

print(res);

var n = readline();
var a;
var cnt = 0;
for(var i = 0; i < n; i++){
    a = readline();
    if(a == "++X" || a == "X++"){
        cnt++;
    }
    else{
        cnt--;
    }
}
write(cnt);

readline()
  var result = 0

  var flag = true
  while (flag) {
    var line = readline()
    if (line) {
      var re = /[++]/
      re.test(line) ? result++ : result--
    } else {
      flag = false
    }
  }

  print(result)

// Generated by CoffeeScript 2.5.1
var lines, mainAux, print, readline, rl, rli, write;

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

print = console.log;

write = function(...args) {
  return process.stdout.write(args.join(' '));
};

lines = [];

rl.on('line', function(line) {
  return lines.push(line);
});

rl.on('close', main);

rli = 0;

readline = function() {
  return lines[rli++];
};

mainAux = function() {
  var i, j, numlines, ref, tot;
  numlines = readline();
  tot = 0;
  for (i = j = 1, ref = numlines; (1 <= ref ? j <= ref : j >= ref); i = 1 <= ref ? ++j : --j) {
    if (readline().includes('++')) {
      tot++;
    } else {
      tot--;
    }
  }
  return print(tot);
};

  function main() {
    return mainAux();
  }
;

//# sourceMappingURL=operator-282-a.js.map

'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();
});

const readLine=()=> inputString[currentLine++];
/* ================================================
           Main Solution Starts Here
===================================================*/

const main=()=>{
	let t = +readLine()
	let x=0
	while(t--){
		let operator = readLine()
		switch(operator){
			case 'X++':
				x++
				break
			case '++X':
			    ++x
			    break
			case 'X--':
				x--
				break
			case '--X':
				--x
				break
		}
	}
	console.log(x)
}

// https://codeforces.com/problemset/problem/282/A
const readline = require('readline');

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

let data = [];
rl.on('line', (input) => {
  data.push(input);
});

rl.on('close', () => {
  solve(data);
});

function solve(data) {
  let x = 0;

  for (let i = 1; i < data.length; i++) {
    const element = data[i];
    if (element.includes('++')) {
      x++;
    } else if (element.includes('--')) {
      x--;
    }
  }

  console.log(x);
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});

	let t = inputReader.readNumber();
	var x = 0;

	while (t--) {
	  let tmp = inputReader.readLine();
	  if (tmp[1] == "+") x++;
	  else x--;
	}

	console.log(x);

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readLine(){
		return _inputLines[_lineNumber++];
	}

	return {
		readNumber,
		readLine,
	}
}

answer = 0;
for(triesQuantity = readline(); triesQuantity; triesQuantity--)
    {
        if (readline().indexOf('++') !== -1)
        {
           answer++;
        }
        else
        {
            answer--;
        }
    }
print(answer);

var numero = readline();
var contador = 0;
for (var i = 0; i<numero;i++){
    var datos =  readline();
    if(datos=="++X" || datos=="X++"){
       contador++;
    }
    else if(datos=="--X" || datos=="X--"){
        contador--;
    }
}

print(contador);

//JavaScript-C24.2.0 (SpiderMonkey)
print(interpretator(triesQuantity = readline()));
function interpretator(triesQuantity)
{
  answer = 0;
  for(; triesQuantity; triesQuantity--)
    {
        if (readline().indexOf('++') !== -1)
        {
           answer++;
        }
        else
        {
            answer--;
        }
    }
    return answer;
}

"use strict";
let input = [];
const readline=require('readline');
const RL=readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
RL.on('line', (line)=>{
  input.push(line.trim());
});
RL.on('close', ()=>{
  const n = parseInt(input[0]);
  let answer=0;
  for(let i=1; i<=n; ++i){
    if(input[i].includes("++")){
      answer++;
    } else{
      answer--;
    }
  }
  console.log(answer);
});

var n = readline();
var x = 0;

for(var i = 0; i < n; i++)
{
    var statement = readline();
    if(statement[0] == "+" || statement[1] == "+" || statement[2] == "+")
    {
        x++
    }
    else
    {
        x--;
    }
}

print(x);

var n = readline()
var ans = 0

for(var i = 0; i < n; i++) {
    var exp = readline()
    if(exp[1] == "-"){
        ans--
    }else{
        ans++

    }
}
print(ans)

n = +readline();

X = 0;

while(n--){
    eval(readline())
}
print(X)

for(var i=0,x=parseInt(readline()),c=0;i<x;i++){
c+=(readline()[1]=='+'?1:-1);
}
print(c);

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

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

readLine.on("line", (line) => input.push(line));
readLine.on("close", () => {
  const length = input[0];
  let x = 0;
  for(let i = 1; i <= length; i ++){
    const string = String(input[i])
    if(string.indexOf('+') != -1){
      x++;
    } else if(string.indexOf('-') != -1){
      x--;
    }
    else {
      continue;
    }
  }
  console.log(x);
});

var statement = Number(readline());
var x = 0;
while(statement--){
   var row = readline();

    if(row == "X++" || row == "++X"){
       x++;
    }else{
       x--;
    }

}

print(x);

var n = readline();
var x = 0;

for (var i = 0; i < n; i++){
    var r = readline();
    if(r.includes('+')){
       x++;
    } else if (r.includes('-')){
        x--;
    }
}
print(x);

const n = Number(readline());
var x = 0;
var s ;
for(var i = 0; i<n ; i++ ){
   s = readline().split("");
   if(s.includes('-')){
       x--;
   }else{
       x++;
   }
}

print(x);//

var input = +readline();
var arrRequest = [];
var Arr = [];
var check = 0;
var x = 0;
for(var i = 0; i < input; i++){
	arrRequest[i] = readline().split('');
	Arr[i] = arrRequest[i][1];
}
Arr.forEach(function(val, index){
	if(val == '+')x++;
	if(val == '-')x--;
})
print(x);

/* TEST CASE
input
1
++X
output
1
input
2
X++
--X
output
0

 */
function main() {
	var n = parseInt(readline());
	var answer = 0;
	for (var i = 0; i < n; i++) {
		var s = readline();
		if (s == "++X" || s == "X++") {
			answer++;
		} else {
			answer--;
		}
	}

	print(answer);
}

main();

var entrada = parseInt(readline());
var resul = 0;
var cadena;
for (var x=0 ; x<entrada; x++) {
    cadena = readline();
    if (cadena.indexOf("++")!=-1) resul++;
    else
    {
        if (cadena.indexOf("--")!=-1) resul--;
    }
}
print(resul);

var n = Number(readline());
var k=0;
for(var i=0;i<n;i++) {
var m = readline();
if ( m.indexOf('+') !== -1){
    k++;
}
else {
    k--;
}
}
print(k);

'use strict';

function main() {
    let n = nextInt(), ans = 0;
    while (n--) {
        let str = nextString();
        str[1] === '+' ? ++ans : --ans;
    }
    console.log(ans);
}

// ------ IO Helper ------
// nextInt(), nextFloat(), nextChar(), nextString()
// isWhitespace(charater :string), clearWhitespaces()

var input = "";
var cursor = 0;
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(data) { input += data; });
process.stdin.on('end', function() { main(); });

function isWhitespace(character) {
    return ' \t\n\r\v'.indexOf(character) > -1;
}

function clearWhitespaces() {
    while (cursor < input.length && isWhitespace(input[cursor])) ++cursor;
}

function nextInt() {
    return parseInt(nextString());
}

function nextFloat() {
    return parseFloat(nextString());
}

function nextChar() {
    clearWhitespaces();
    if (cursor < input.length)
        return input[cursor++];
    return '';
}

function nextString() {
    let str = "";
    clearWhitespaces();
    while (cursor < input.length && !isWhitespace(input[cursor])) {
        str += input[cursor++];
    }
    return str;
}

var lines = readline();
var x = 0;
for (var i = 0; i < lines; i++) {
	var line = readline().split(' ');
	if (line == '++X' || line == 'X++') {
		x++;
	} else {
		x--;
	}
}
print(x);

var n = readline();
var x = 0;

for (var i = 0; i < n; i++) {
    var addOrSubtract = readline()[1];
    if (addOrSubtract === '+') {
        x++;
    } else {
        x--;
    }
}
print(x);

var operations = readline();
var value = 0;
for(var i = 0; i < operations; i++) {
    if(readline().indexOf('+') !== -1) {
        value++;
    } else {
        value--;
    }
}
print(value);

'use strict';

const count = readline().split(/\s+/g);
const n = count[0];

let answer = 0;

for(let i=0; i<n; i++){
    const statement = readline();

    const isInc = statement.match(/\+{2}/);
    if(isInc){
        answer += 1;
        continue;
    }

    const isDec = statement.match(/\-{2}/);
    if(isDec){
        answer -= 1;
        continue;
    }
}

print(answer);

var cases = readline();
var res = 0;
for(var i = 0; i < cases; ++i){
    var op = readline();
    if(op.includes('--')) --res;
    if(op.includes('++')) ++res;
}

print(res);

var range = readline();
var count = 0;

for(var i=0;i<range;i++) {
    var input = readline();
    if(input.indexOf("++") > -1) {
        count++;
    } else if(input.indexOf("--") > -1) {
        count --;
    }
}

print(count);

input=readline();
input=input.split(' ').map(e=>parseInt(e));
n=input[0]
ans=0;
while(n--){
    tmp=readline();
    ans+=(tmp.indexOf('+')===-1)?-1:1;
}
print(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 readAsInt(){
  return parseInt(readline());
}

function readAsIntList(){
  return readline().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() {
    const n = readAsInt();
    let result = 0;
    for (let i = 0; i < n; i++) {
      result += readline().includes("++") ? 1 : -1;
    }
    console.log(result);
}

var x= parseInt(readline());
var result=0;
while(x--){
  var y =readline();

  for(var i=0; i<y.length; i++){
    if(y[i] === '+'){
      result++;
      break;
    }
    if(y[i] === '-'){
      result--;
      break;
    }
  };
}

print(result);

var nOpers = readline()
var x = 0
var oper;

for(i=0;i<nOpers;i++){
	oper=readline();
	if(oper=="X++"||oper=="++X"){
		x++;
	}
	else{
		x--;
	}
}
print(x);

var n = readline();
var a = [];

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

var count = 0;

a.forEach(function (j, o ,s) {
    if (j.indexOf('+') != -1) count++;
    else count--;
});

print(count);

var n = parseInt(readline()) || 0;

if (!(n >= 1 && n <= 150)) {
    print(0);
}
else {
    var x = 0;

    while (n-- > 0){
        var statement = readline();
        var variable = String(statement).match(/[a-zA-Z]+/)[0];
        var atBegin = statement[0] === variable;
        var symbol = atBegin ? statement[statement.length - 1] : statement[0];

        if (symbol === '+') {
            if (atBegin) x++;
            else ++x;
        } else {
            if (atBegin) x--;
            else --x;
        }
    }

    print(x);
}

n = +readline();

X = 0;

while(n--){
    eval(readline())
}
print(X)

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

var skaicius = 0;

for(var i = 0; i < parseInt(input); i++) {
    var line = readline();

    if(line.toLowerCase() == "++x" || line.toLowerCase() == "x++") {
        skaicius++;
    } else if (line.toLowerCase() == "--x" || line.toLowerCase() == "x--") {
        skaicius--;
    }
}

print(skaicius);

var n = readline();
var a;
var cnt = 0;
for(var i = 0; i < n; i++){
    a = readline();
    if(a == "++X" || a == "X++"){
        cnt++;
    }
    else{
        cnt--;
    }
}
write(cnt);

let fs = require('fs')

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter((data) => {
    return data.length > 0;
});

for (let index = 0; index < txt.length; index++) {
    if (!isNaN(txt[index]*1)) {
        let tab = []
        for (let i = 1; i <= txt[index]; i++) {
            tab.push(txt[index + i]);
        }
        square(tab)
    }

}

function square(tab) {
    let score = 0;
    tab.forEach(element => {
       if(element[0]=="+" || element[1]=="+") {
           ++score;
       }else{
           --score;
       }
    });
    console.log(score);

}

var n = readline();//.split(" ").map(function(x) { return parseInt(x); });
n=parseInt(n);
var arr=[];
for (var i=0;i<n;i++){
	var s = readline();
	arr.push(s);
}

var x = 0;
for(i = 0; i < arr.length; i++){
	if (arr[i] == "X++" || arr[i] =="++X"){
		x++;

	}
	if (arr[i] == "X--" || arr[i] =="--X"){
		x--;

	}

}
 print (x);

var cases = readline();
var res = 0;
for(var i = 0; i < cases; ++i){
    var op = readline();
    if(op.includes('--')) --res;
    if(op.includes('++')) ++res;
}

print(res);

function main() {
    var lines = readline();
    var x = 0;
    for (; lines > 0; lines--) {
        var operation = readline();
        if (operation[1] === '+') {
            x += 1;
        } else if (operation[1] === '-') {
            x -= 1;
        }
    }
    print(x);
}
main()

    var lines = readline();
    var processes = [];
    var lineProcess = "";
    var x = 0;

    for(var i=0;i<lines;i++){
        lineProcess = readline();
        if(lineProcess[1]=="+"){
            x++;
        }
        else {
            x--;
        }
    };
    print(x);

var n = parseInt(readline());

var input = [];
for (var i = 1; i <= n; i++) {
    input[i] = readline();
}

var x = 0;

input.forEach(function(line){
    if (line.charAt(1) === '+') {
        x++;
    } else {
        x--;
    }
});

print(x);

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

function main() {
    let n = parseInt(readLine());
    let count = 0;
    for (let i = 0; i < n; i++) {
        let op = readLine();
        if (op === 'X++' || op === '++X') {
            count++;
        } else {
            count--;
        }
    }
    console.log(count);
}

for(var i=0,x=parseInt(readline()),c=0;i<x;i++){
c+=(readline()[1]=='+'?1:-1);
}
print(c);

var n = parseInt(readline());
var x = 0;
for (var i = 0; i < n; i++) {
    if (readline()[1] === "+") {
        x += 1;
    } else {
        x -= 1;
    }
}
print(x);

readline()
  var result = 0

  var flag = true
  while (flag) {
    var line = readline()
    if (line) {
      var re = /[++]/
      re.test(line) ? result++ : result--
    } else {
      flag = false
    }
  }

  print(result)

n = readline();
number = 0 ;
for (i = 0; i < n; i++) {
    a = readline();
    if(a  == '++X' || a  == 'X++') {
       number = number + 1;
    }

    if(a  == '--X' || a  == 'X--') {
       number = number - 1;
    }

}

print(number)

var n = Number(readline());
var ans = 0;
var str = '';

for (var i = 0 ; i < n ; i++) {
    str = readline();

    for (var j = 0 ; j < 3 ; j++) {
        if (str[j] == '+') {
            ans++;
            break;
        }
        if(str[j] == '-') {
            ans--;
            break;
        }
    }
}

print(ans);

var value = +readline();
var count = 0
for (var i=0; i < value; i++) {
    var c = readline().split("");
    if (c[0] === '+' || c[1] === '+' || c[2] === '+' ) {
        count++;
    } else count--
}
print(count);

readline()
  var result = 0

  var flag = true
  while (flag) {
    var line = readline()
    if (line) {
      var re = /[++]/
      re.test(line) ? result++ : result--
      // problems.push(line)
    } else {
      flag = false
    }
  }

  print(result)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline().replace(new RegExp('X' , 'g'), '')
	if(s == "++"){meghdar++}
	else{meghdar--}

}
print(meghdar)

var n = parseInt(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = readline();
    if(w[0] == '+' || w[1] == '+') {
        x += 1
    }else {
        x -= 1
    }
}
print(x)

var n=parseInt(readline());
var x=0;
for(var i=0;i<n;i++){
    var s=readline();
    if(s==="++X"||s==="X++")
        x++;
    else
        x--
}
print(x);

var operations = readline();
var value = 0;
for(var i = 0; i < operations; i++) {
    if(readline().indexOf('+') !== -1) {
        value++;
    } else {
        value--;
    }
}
print(value);

var n=readline();
var ans=0;
for (var i=0; i<n; i++){
    str=readline();
    if (str[1]=="+") ans+=1;
    if (str[1]=="-") ans-=1;
}
print (ans);

answer = 0;
for(triesQuantity = readline(); triesQuantity; triesQuantity--)
    {
        if (readline().indexOf('++') !== -1)
        {
           answer++;
        }
        else
        {
            answer--;
        }
    }
print(answer);

var n = Number(readline());
var k=0;
for(var i=0;i<n;i++) {
var m = readline();
if ( m.indexOf('+') !== -1){
    k++;
}
else {
    k--;
}
}
print(k);

var lines = readline();
var value = 0;

for (var i = 0; i < lines; i++) {
    var targetString = readline();
    if (targetString.includes('+')) value++;
    else if (targetString.includes('-')) value--;
}

print(value);

/**
 * @author Albert Hambardzumyan
 * @description Bit++.
 *  Reference: http://codeforces.com/problemset/problem/282/A
 *  Tags: implementation, 900
 */
(function () {
  const iterations = parseInt(readline())

  var x = 0
  var temp
  for (var i = 0; i < iterations; i++) {
    temp = readline()

    temp.charAt(0) === '+' || temp.charAt(2) === '+' ? x++ : x--
  }

  print(x)
})()

const readline = require('readline')

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

rl.on("line", main)
let i = 0;
let n = 0;
let x = 0;
function main(input){
	if(n == 0){
		n = input
		return
	}

	if(input[0] === "X"){
		if(input[1] === "-"){
			x--
		}
		else{
			x++
		}
	}
	else{
		if(input[0] === "-"){
			x--
		}
		else{
			x++
		}
	}

	i++
	if(i === parseInt(n)){
		console.log(x)
	}

}

var line=readline().split(' ');
var n=parseInt(line[0]);
var ans=0;

for(var i=0;i<n;i++){
    var f=0;
    var ip=readline().split('');
    var c='-';
    if(((ip[0]==c)&&(ip[1]==c))||((ip[2]==c)&&(ip[1]==c))){
        ans--;
    }
    else{
        ans++;
    }
}

print(ans);

var n = Math.floor(readline());
var x = 0;
for(i in n){
    w = parseInt(readline());
    if(w[0] === '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = Math.floor(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = readline();
    if(w[0] === '+' || w[1] === '+') {
        x++
    }else {
        x--
    }
    print(x)
}

var n = Math.floor(readline());
for(var x = 1; x <= n; x++){
    if(x === n) {
        print(x++)
    }else {
        print(--x)
        break;

    }
}

var n = Math.floor(readline());
var x = 0;
for(i in n){
    w = parseInt(readline());
    if(w[1] === '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = parseInt(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = readline();
    if(w[0] == '+' || w[1] == '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = Math.floor(readline());
var x = 0
for(i in n){
    w = parseInt(readline());
    if(w[1] === '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = Math.floor(readline());
var x = 0
for(i in n){
    w = parseInt(readline());
    if(w[0] === '+') {
        x += 1
    }else {
        x -= 1
    }
    print(x)
}

var n = Math.floor(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = parseInt(readline());
    if(w[0] === '+' || w[1] === '+') {
        print(x++)
    }else {
        print(--x)
        break;

    }
    print(x)
}

var n = parseInt(readline());
var x = 0;
for(var i = 0; i < n; i++){
    var w = readline();
    if(w[0] == '+') {
        x++
    }else {
        x--
    }
}
print(x)

var n = Math.floor(readline());
for(var x = 0; x < n; x++){
    if(x === n) {
        print(x++)
    }else {
        print(--x)
        break;

    }
}

var countLines = readline()*1,
    x = 0;

for(var i = 0; i < countLines.length; i++){
    if(/\+/.test(readline())) x++;
    else x--;
}

print(x);

var n = readline();
var a = [];

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

var count = 0;

a.forEach(function (i) {
    if (i.substr(0,1) == 'X') count++;
    else count--;
});

print(count);

var n = parseInt(readline()),
	x = 0,
	s = ''

while (n > 0) {
	s = readline()
	if (s.charAt(1) == '-')
		x ++
	else
		x --
	n --
}

print(x)

var numberOfTestCases = parseInt(readline());

var input = "";

var ans = 0

for(var i = 0 ; i < numberOfTestCases ; i++) {

input = readline().split(" ");

if (input[i] == "X++" || input[i] == "++X") ans++
else ans--
}

print(ans)

var numberOfTestCases = parseInt(readline());

var input = "";

var ans = 0;

for(var i = 0 ; i < numberOfTestCases ; i++) {

input = readline();

if (input[i] == "X++" || input[i] == "++X") ans++;
else ans--;

}

print(ans);

var num_op = parseInt(readline());
var x = 0;
while(num_op >0){
    var value = readline();
    if(value == "++X" || value == "X++" ) x++;
    if(value == "--X" || value == "X--" ) x++;
    num_op--;
}
print(x);

var nOpers = parseInt(readline());
var x = 0;
var operacion;

for(var i=0;i<nOpers;i++) {
  operacion = readline();
  if(operacion == "x++" || operacion == "++x"){
    x++;
} else {
    x--;
}
}

print(x)

var nOpers = parseInt(readline());
var x = 0;
var operacion;

for(var i=0;i<nOpers;i++) {
  operacion = readline();
  if(operacion == "x++" || operacion == "++x"){
    x++;
} else if (operacion == "x--" || operacion == "--x"){
    x--;
}
}

print(x)

var nOpers = readline()
var x = 0
var oper;

for(i=0;i<nOpers;i++){
	oper=readline();
	if(oper=="x++"||oper=="++x"){
		x++;
	}
	else{
		x--;
	}
}
print(x);

var result = 0;
var nOpers = parseInt(readline());

for(i=0;i<nOpers;i++) {
  var operacion = readline();
  if(operacion == "x++" || operacion == "++x"){
    result++;
} else {
    result--;
}
}
print(result);

var a = readline() ;
while(a-- != 0){
    var str = readline() ;
    var x = 0 ;
    if(str.charAt(1) == '+')
        x++ ;
    else
        x-- ;

}
  print(x)    ;

var a = readline() ;
while(a-- != 0){
    var str = readline() ;
    var x = 0 ;
    if(str.charAt(1) == '+')
        x++ ;
    else
        x-- ;
    print(x)    ;
}

var lines = readline();
var value = 0;

for (var i = 0; i < lines; i++) {
    var targetString = readline();
    if (targetString == 'X++') value++;
    else if (targetString == '--X') value--;
}

print(value);

function main() {
    var n = readline();
    var total = 0;
    while (n--) {
        var X = readline();
        if (X[1] == '+') {
            ++total
        }
        else {
            --total
        }
    }
   console.log(total)

}

function main() {

    var n = readline();
    // var X = readline();
    var total = 0;
    while (n--) {
        // var X = readline().split('');
        var X = readline();
        if (X[1] == '+') {
            ++total
        }
        else {
            --total
        }
        // return X
    }
    return 0;
}

function main() {
    var n = readline();
    var total  = 0;
    for(var i=0;i<n;i++){
        var X = readline();
        if(X[i] == '+'){
            ++total
        }
        else{
            --total
        }

    }
    console.log(total)
}

function main() {
    var n = readline();
    var total  = 0;
    for(var i=0;i<n;i++){
        var X = readline();
        if(X[1] == '+'){
            ++total
        }
        else{
            --total
        }

    }
    console.log(total)
}

function main() {
    var n = readline();
    var total  = 0;
    for(var i=0;i<n;i++){
        var X = readline();
        if(X[i] == '+'){
            ++total
        }
        else{
            --total
        }

    }
    print(total)
}

var n = readline();
var X = 0;

for (var i = 0; i < n; i++) {
    x = readline();
}
print(X);

const main = () => {
  const x = Number(readline());
  const arr = [];
  var count = 0;

  for (var i in [...Array(x).fill()]) {
    arr.push(readline().trim());
  }

  for (var b of arr) {
    if (b === 'X++') {
      count++;
      continue;
    }
    count--;
  }

  print(count);
};

main()

'use strict';
const n = parseInt(readline());
var x = 0;

for(let i = 0; i < n; i++) {
    if(readline().indexOf('+')){
        x++;
    } else {
        x--;
    }
}

write(x);

var numero = readline();
var contador=0;
var x=0;

for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++x" || datos[i]=="x++"){
        x=+1;
    }
    if(datos[i]=="--x" || datos[i]=="x--"){
        x=-1;
    }
}
        print(x);

var numero = readline();
var contador = 0;
for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++X" || datos[i]=="X++"){
       contador++;
    }
    if(datos[i]=="--X" || datos[i]=="X--"){
        contador--;
    }
}

print(contador);

var numero = readline();
var contador=0;
var x=0;

for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++x" || datos[i]=="x++"){
        x=x+1;
    }
    if(datos[i]=="--x" || datos[i]=="x--"){
        x=x-1;
    }
}
        print(x);

var numero = readline();

var x=0;

for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++x" || datos[i]=="x++"){
       var y=1;
    }
    else if(datos[i]=="--x" || datos[i]=="x--"){
        var y= 0-1;

    }
    x=x+y;
}

print(x);

var numero = readline();
var contador = 0;
for (var i = 0; i<numero;i++){
    var datos =  readline().split(" ");
    if(datos[i]=="++x" || datos[i]=="x++"){
       contador++;
    }
    else if(datos[i]=="--x" || datos[i]=="x--"){
        contador--;
    }
}

print(contador);

var n = +readline();

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

	var str = readline();
	if(str.charAt(1) == '+')
		ans+=1;
	else
		ans-=1;

}

var entrada = readline();
var casos = parseInt(entrada[0]);
var resul = 0;
var cadena;
var buscar = "++";
for (var x=0 ; x<casos ; x++) {
    cadena = readline();
    if (cadena.indexOf(buscar)!=-1) resul++;
    else resul--;
}
print(resul);

var entrada = readline();
var casos = parseInt(entrada[0]);
var resul = 0;
var cadena;
for (var x=0 ; x<casos ; x++) {
    cadena = readline();
    if (cadena.indexOf("++")!=-1) resul++;
    else
    {
        if (cadena.indexOf("--")!=-1) resul--;
    }
}
print(resul);

/* TEST CASE
input
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
output
word
l10n
i18n
p43s

 */
function main() {
	var n = parseInt(readline());
	for (var i = 0; i < n; i++) {
		var s = readline();
		if (s.length <= 10) {
			print(s);
		} else {
			print(s[0] + (s.length - 2) + s[s.length - 1]);
		}
	}
}

main();

var n=parseInt(readline());
var x=0;
for(var i=0;i<n;i++){
    var s=readline().split(' ');
    if(s[0]==="++X"||s[0]==="++X")
        x++;
    else
        x--
}
print(x);

var n=parseInt(readline());
var x=0;
for(var i=0;i<n;i++){
    var s=readline();
    if(s==="++X"||s==="++X")
        x++;
    else
        x--
}
print(x);

var calc = readline();

function resolve(prb) {
    var x=0;
    for (var i=0; i<prb; i++) {
        var exer = readline();
        exer=exer.toLowerCase();
        var valor,contRest, contSum = 0;
        if (exer[1]==="-") {
                contRest++;
        } else if (exer[1]==="+") {
                contSum++;
        }
        x+=contSum-contRest;
    }

    return x;
}

print (resolve(parseInt(calc)));

var loop = parseInt(readline());
var x=0;
for(var i = 0; i < loop; i++){
    var statement = readline();
    if(statement.charAt(1) == '+'){
        ++x
    }else {
        --x
    }
}

var numberOfStatements = readline();
var xValue = 0;

for(var i = 0; i < numberOfStatements; i++){
    var statement = readline();

    if(statement.indexOf('++')) xValue++;
    else if(statement.indexOf('--')) xValue--;
}

print(xValue);

var lines = readline()
var ans = 0
for(var i=0;i<lines;i++) {
    var stmt = readline()
    if(stmt.indexOf('++') === 0) {
        ans++
        continue
    }
    if(stmt.indexOf('++') > 0 && i !== lines.length) {
        ans++
        continue
    }
    if(stmt.indexOf('--') === 0) {
        ans--
        continue
    }
    if(stmt.indexOf('--') > 0 && i !== lines.length) {
        ans--
        continue
    }
}

print(ans)

var lines = parseInt(readline())
var ans = 0
for(var i=0;i<lines;i++) {
    var stmt = readline()
    if(stmt.indexOf('++') === 0) {
        ans++
        continue
    }
    if(stmt.indexOf('++') > 0 && i < lines - 1) {
        ans++
        continue
    }
    if(stmt.indexOf('--') === 0) {
        ans--
        continue
    }
    if(stmt.indexOf('--') > 0 && i < lines - 1) {
        ans--
        continue
    }
}

print(ans)

// The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.

// The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:

//     Operation ++ increases the value of variable x by 1.
//     Operation -- decreases the value of variable x by 1.

// A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.

// A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.

// You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
// Input

// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
// Output

// Print a single integer — the final value of x.

var n = readline();

var x = 0;
var operations = [];

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

operations.forEach(function(operation) {
  if (operation === 'X++' || operation === '++X') {
    x += 1;
  } else if (operation === 'X--' || operation === '--X') {
    x -= 1;
  }
});

print(n);

// The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.

// The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:

//     Operation ++ increases the value of variable x by 1.
//     Operation -- decreases the value of variable x by 1.

// A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.

// A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.

// You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
// Input

// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
// Output

// Print a single integer — the final value of x.

const n = readline();

// let x = 0;
// let operations = [];

// for (let i = 0; i < n; i++) {
//   const temp = readline();
//   operations.push(temp);
// }

// operations.forEach(function(operation) {
//   if (operation === 'X++' || operation === '++X') {
//     x += 1;
//   } else if (operation === 'X--' || operation === '--X') {
//     x -= 1;
//   }
// });

print(n);

var n = parseInt(readline());
var X = 0;
var i;
for (i in n){
    eval(readline());
}
print(X);

var n = Number(readline());
var x = 0;

for (var i = 0; i < n; i++) {
    var codeLine = readline();

    if ( codeLine.indexOf('++') ) {
        x++;
    } else {
        x--;
    }
}

print( x );

var count = readline();
var num=0;
for(var i = 0; i<count; i++){
    var op = readline();
    if(count-1 == i){
       if(op === 'X++' ){
            break;
        }
        if(op === 'X--' ){
            break;
        }
    }
    if(op === '++X' || op === 'X++' ){
        ++num;
    }
    if(op === '--X' || op === 'X--' ){
        --num;
    }

}

print(num);

var linea = readline(); // Leemos el número de lineas que debemos tratar
var sol = 0;
var linea;
// Por cada linea propuesta:
for (var i = 0; i < linea; i++) {
    linea = readline(); // Leemos la linea
    // Si la linea contiene '+' sumamos 1 a la solución, en caso contrario restamos 1
    if (linea.indexOf('+') > -1) {
        sol++;
    } else {
        sol--;
    }

}
print(sol);

/**
 * @author Albert Hambardzumyan
 * @description Bit++.
 *  Reference: http://codeforces.com/problemset/problem/282/A
 *  Tags: implementation, 900
 */
(function () {
  const iterations = readline()

  var x = 0
  for (var i = 0; i < iterations; i++) {
    const temp = readline()

    temp.charAt(0) === '+' || temp.charAt(2) === '+' ? x++ : x--
  }

  print(x)
})()

var n = readline()
var ans = 0

for(var i = 0; i < n; i++) {
    var exp = readline()
    var a = (exp[0] == "-")?ans--:ans++;
}

print(ans)

var n = readline()
var ans = 0

for(var i = 0; i < n; i++) {
    var exp = readline()
    print(exp[1])
    if(exp[1] == "-"){
        ans--
    }else{
        ans++

    }

}

print(ans)

function main(){
  var n = +readline();
  var x;
  while (n>0) {
      x = readline();
        if (x.includes("++")) {
          x += +1 ;
        }
        if (x.includes("--")) {
          x += -1 ;
        }
        n--;
  }
  print(x);
}

main();

function main(){
  var n = +readline();
  var x;
  var result = 0;
  while (n>0) {
      x = readline();
        if (x.includes("++")) {
          result = +1 ;
        }
        if (x.includes("--")) {
          result = -1 ;
        }
        n--;
  }
  print(result);
}

main();

function main(){
  var n = +readline();
  var x;
  while (n>0) {
      x = readline();
        if (x.includes("++")) {
          x = x+1 ;
        }
        if (x.includes("--")) {
          x = x-1 ;
        }
        n--;
  }
  print(x);
}

main();

var n = readline();
var x = 0;

for (var i = 0; i < n; i++){
    var r = readline();
    print(r);
    if(r.includes('+')){
       x++;
    } else if (r.includes('-')){
        x--;
    }
}
print(x);

var n=readline();
var ans;
for (var i=0; i<n; i++){
    str=readline();
    if (str[1]=="+") ans++;
    if (str[1]=="-") ans--;
}
print (ans);

var n = Number(readline());
var ans = 0;
var str = '';

for (var i = 0 ; i < n ; i++) {
    str = readline();

    for (var j = 0 ; j < 3 ; j++) {
        if (str[i] == '+') {
            ans++;
            break;
        }
        else if(str[i] == '-') {
            ans--;
            break;
        }
    }
}

print(ans);

var n = Number(readline());
var ans = 0;
var str = '';

for (var i = 0 ; i < n ; i++) {
    str = readline();

    for (var j = 0 ; j < 3 ; j++) {
        if (str[i] == '+') {
            ans++;
            break;
        }
        if(str[i] == '-') {
            ans--;
            break;
        }
    }
}

print(ans);

var line=readline().split(' ');
var n=parseInt(line[0]);
var ans=0;

for(var i=0;i<n;i++){
    var f=0;
    var ip=readline().split('');
    var c='-';
    if(((ip[0]==c)&&(ip[1]==c))||((ip[2]==c)&&(ip[1]==c))){
        ans--;
    }
    else{
        ans++;
    }
    print(ans);
}

print(ans);

var lines = readline();
var x = 0;
for (var i = 0; i < lines; i++) {
	var line = readline().split(' ');
	if (line === '++X' || line === 'X++') {
		x++;
	} else {
		x--;
	}
}
print(x);

x=parseInt(readline());
var c=0;
for(var i=0;i<x;i++){
x=readline();
c+=x[1]==0;
}
print(c);

x=parseInt(readline());
var c=0;
for(var i=0;i<x;i++){
x=readline();
c+=(x[1]=='+'?1:-1);
}
print(c);

x=parseInt(readline());
var c=0;
for(var i=0;i<x;i++){
x=readline();
c+=x[1]=='+'?1:-1;
}
print(c);

x=parseInt(readline());
var c=0;
for(var i=0;i<x;i++){
x=readline();
c+=x[1]=='+';
}
print(c);

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline().replace(new RegExp('X' , 'g'), '')
	if(s = "++"){meghdar++}
	else{meghdar--}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline()
	var k = s.indexOf("+");
	if(k = -1){meghdar--}
	else{meghdar++}

}
print(s)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline()
	var k = s.indexOf("+");
	if(k = -1){meghdar--}
	else{meghdar++}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline().replace(new RegExp('X' , 'g'), '')
	var k = s.indexOf("+");
	if(k = -1){meghdar--}
	else{meghdar++}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{
 	s=readline().replace(new RegExp('X' , 'g'), '')

	if(s = "++"){meghdar++}
	else{meghdar--}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{
 	s=readline().replace(new RegExp('X' , 'g'), '')

	if(s = "++"){meghdar++}
	else if(s = "--"){meghdar--}

}
print(meghdar)

n = readline();
var meghdar = 0;
while(n--)
{

	s = readline();
	var k = s.indexOf("+");
	if(k = -1){meghdar--}
	else{meghdar++}

}
print(meghdar)

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 X=0;
for(var i=0;i<n;i++){
   if(readline()=='++X')
    X++;
    if(readline()=='--X')
    X--;
}
print(X)

var n = readline();
var X=0;
for (var i=0; i<n;i++) {
    var offer = readline();
    if (offer=='X++') X++;
    X--;
}
print(X);

var n = readline();
var X=0;
for (var i=0; i<n;i++) {
    var offer = readline();
    if (offer=='X++') {
        X++;
    } else {
        X--;
    }
}
print(X);

function main() {
    const res = stdin.reduce((s,x)=>{
        return s = x[1] === "+" ? s+1 : s-1;
    },0)
    console.log(res)
}

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);

function main() {
    console.log(stdin);
}

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);

// var stdin = "";
// process.stdin.resume();
// process.stdin.setEncoding("ascii");
// process.stdin.on("data", function(data) {
//   stdin += data;
// });
// process.stdin.on("end", function() {
//   main(stdin);
// });

const debug = 0;
const stdin = `1

++X
`;
main(stdin);

/////////////// ignore above this line ////////////////////

function main(stdin) {
  let currentLine = 0;
  let res = 0;
  const commandCount = readLine(stdin, currentLine);

  while (commandCount > currentLine) {
    ++currentLine;
    const command = readLine(stdin, currentLine).replace("X", "");

    if (command === "++") {
      res += 1;
    } else if (command === "--") {
      res -= 1;
    }
  }

  console.log(res);
}

function readLine(str, line) {
  return str.split(/\r?\n/).filter(s => Boolean(s.trim()))[line];
}

// var stdin = "";
// process.stdin.resume();
// process.stdin.setEncoding("ascii");
// process.stdin.on("data", function(data) {
//   stdin += data;
// });
// process.stdin.on("end", function() {
//   main(stdin);
// });

const debug = 0;
const stdin = `2

X++

--X
`;
main(stdin);

/////////////// ignore above this line ////////////////////

function main(stdin) {
  let currentLine = 0;
  let res = 0;
  const commandCount = readLine(stdin, currentLine);

  while (commandCount > currentLine) {
    ++currentLine;
    const command = readLine(stdin, currentLine).replace("X", "");

    if (command === "++") {
      res += 1;
    } else if (command === "--") {
      res -= 1;
    }
  }

  console.log(res);
}

function readLine(str, line) {
  return str.split("\n").filter(s => Boolean(s.trim()))[line];
}

var stdin = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function(data) {
  stdin += data;
});
process.stdin.on("end", function() {
  main(stdin);
});

// main(stdin);

/////////////// ignore above this line ////////////////////

function main(stdin) {
  let currentLine = 0;
  let res = 0;
  const commandCount = readLine(stdin, currentLine);

  while (commandCount > currentLine) {
    ++currentLine;
    const command = readLine(stdin, currentLine).replace("X", "");

    if (command === "++") {
      res += 1;
    } else if (command === "--") {
      res -= 1;
    }
  }

  console.log(res);
}

function readLine(str, line) {
  return str.split("\n")[line];
}

// var stdin = "";
// process.stdin.resume();
// process.stdin.setEncoding("ascii");
// process.stdin.on("data", function(data) {
//   stdin += data;
// });
// process.stdin.on("end", function() {
//   main(stdin);
// });

const debug = 0;
const stdin = `1

++X
`;
main(stdin);

/////////////// ignore above this line ////////////////////

function main(stdin) {
  let currentLine = 0;
  let res = 0;
  const commandCount = readLine(stdin, currentLine);

  while (commandCount > currentLine) {
    ++currentLine;
    const command = readLine(stdin, currentLine).replace("X", "");

    if (command === "++") {
      res += 1;
    } else if (command === "--") {
      res -= 1;
    }
  }

  console.log(res);
}

function readLine(str, line) {
  return str.split("\n").filter(Boolean)[line];
}

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

let first = true;
let total = 0;
rl.on('line', line => {
    if (first === true) {
        total = parseInt(line);
        first = false;
    }
    input = line;
    solution(input, total);
});

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

function solution(input) {
    const operator = input[1];

    if (operator === '+') {
        total += 1;
    } else if (operator === '-') {
        total -= 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(string => {
        return string.trim();
    });

    main();
});

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

function print(s){
    process.stdout.write(s);
}

function println(s){
    console.log(s);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    // var n = readline().split(' ');
    // for(var i=0; i<a.length; i++){
    //     println(a[i]);
    // }

    // var b = parseInt(a[0])/parseInt(a[1]);
    // println(String(b));

    var n = parseInt(readline().split(' ')[0]);
    println(n);

    var x  = 0;
    for(var i=0; i<n; i++){
        var op = readline().split(' ')[0];
        if(op == "X++" || op == "++X"){
            x++;
        }else{
            x--;
        }
    }

    println(x);
}

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

// read each line
let i = 0;
let arr = [];
rl.on("line", (lineInput) => {
  if (i !== 1) arr.push(lineInput);
  i++;
});

// when all file readed
rl.on("close", () => {
  let result = 0;
  for (let index = 0; index < arr.length; index++) {
    if (arr[index].indexOf("++") > -1) result++;
    if (arr[index].indexOf("--") > -1) result--;
  }
  console.log(result);
});

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

// read each line
let i = 0;
let arr = [];
rl.on("line", (lineInput) => {
  if (i !== 1) arr.push(lineInput);
  i++;
});

// when all file readed
rl.on("close", () => {
  let result = 0;
  arr.forEach(function (el) {
    if (el.indexOf("++") > -1) result++;
    if (el.indexOf("--") > -1) result--;
  });
  console.log(result);
});

'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 arr = [];
    let ans = 0;
    for (let i = 0; i < n; i++) {
        arr.push(readLine());
        if (arr[0].indexOf('-') != -1) {
            ans--;
        } else ans++;
    }
    console.log(ans);
}


You have a card deck of $$$n$$$ cards, numbered from top to bottom, i. e. the top card has index $$$1$$$ and bottom card — index $$$n$$$. Each card has its color: the $$$i$$$-th card has color $$$a_i$$$.You should process $$$q$$$ queries. The $$$j$$$-th query is described by integer $$$t_j$$$. For each query you should:   find the highest card in the deck with color $$$t_j$$$, i. e. the card with minimum index;  print the position of the card you found;  take the card and place it on top of the deck.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 3 \cdot 10^5$$$; $$$1 \le q \le 3 \cdot 10^5$$$) — the number of cards in the deck and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 50$$$) — the colors of cards. The third line contains $$$q$$$ integers $$$t_1, t_2, \dots, t_q$$$ ($$$1 \le t_j \le 50$$$) — the query colors. It's guaranteed that queries ask only colors that are present in the deck.

Print $$$q$$$ integers — the answers for each query.

NoteDescription of the sample:   the deck is $$$[2, 1, 1, 4, \underline{3}, 3, 1]$$$ and the first card with color $$$t_1 = 3$$$ has position $$$5$$$;  the deck is $$$[3, \underline{2}, 1, 1, 4, 3, 1]$$$ and the first card with color $$$t_2 = 2$$$ has position $$$2$$$;  the deck is $$$[2, 3, \underline{1}, 1, 4, 3, 1]$$$ and the first card with color $$$t_3 = 1$$$ has position $$$3$$$;  the deck is $$$[\underline{1}, 2, 3, 1, 4, 3, 1]$$$ and the first card with color $$$t_4 = 1$$$ has position $$$1$$$;  the deck is $$$[1, 2, 3, 1, \underline{4}, 3, 1]$$$ and the first card with color $$$t_5 = 4$$$ has position $$$5$$$.

'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*$/, ''));

    const [n, queries] = readLine().split(' ').map(Number);

    const arr = readLine().split(' ').map(Number);

    const colors = readLine().split(' ').map(Number); //query colors.

    c(n,queries,arr,colors)

});

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

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

function c(n,q,a,t)
{
    const N = 60;

    let pos = Array(N).fill(-1);
    for (let i = 0; i < n; i++) {
        if (pos[a[i]] < 0) pos[a[i]] = i;
    }
    let res = [];
    for (let k = 0; k < q; k++) {
        res.push(pos[t[k]] + 1);
        for (let i = 1; i < 60; i++) {
            if (pos[i] >= 0 && pos[i] < pos[t[k]]) {
                pos[i]++;
            }
        }
        pos[t[k]] = 0;
    }
    return console.log(res.join(' '))
}

module.exports = c;

"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++];
}
class Node {
  constructor(val) {
    this.val = val;
    this.next = null;
    this.prev = null;
  }
}
class Dl {
  constructor() {
    this.head = null;
    this.tail = null;
  }
  push(val) {
    if (!this.head) this.head = this.tail = new Node(val);
    else {
      let newn = new Node(val);
      this.tail.next = newn;
      newn.prev = this.tail;
      this.tail = newn;
    }
  }
  shift(val) {
    let newN = new Node(val);
    newN.next = this.head;
    this.head.prev = newN;
    this.head = newN;
  }
  remove(val) {
    let ind = 1,
      p = this.head;
    while (p) {
      if (p.val === val) {
        if (p.prev === null) return ind;
        else if (p.next === null) {
          this.shift(p.val);
          this.tail = p.prev;
          this.tail.next = null;
          return ind;
        } else {
          this.shift(p.val);
          p.prev.next = p.next;
          p.next.prev = p.prev;
          return ind;
        }
      }
      p = p.next;
      ind++;
    }
  }
}
const solve = () => {
  let t = 1;
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let q = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let list = new Dl();
    for (let i = 0; i < n; i++) list.push(arr[i]);
    let res = "";
    for (let i = 0; i < k; i++) res += list.remove(q[i]) + " ";
    console.log(res);
  }
};
solve();

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 set = new Array(51).fill(Infinity); // index is card number, value is highest position.
    var a = input[1].split(" ").map((i) => {
        return Number(i);
    });
    var query = input[2].split(" ").map((i) => {
        return Number(i);
    });
    for (let i = 0; i < a.length; i++) {
        set[a[i]] = Math.min(i + 1, set[a[i]]);
    }
    var result = [];
    for (let i = 0; i < query.length; i++) {
        var index = set[query[i]];
        result.push(index);
        for (var j = 1; j <= 50; j++) {
            if (set[j] < index) {
                set[j] += 1;
            }
        }
        set[query[i]] = 1;
    }
    console.log(result.join(" "));
})

'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++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

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

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  //   var n = parseInt(readline());
  var [n, qq] = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  })
  // var [x, y] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // });
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  })
  var q = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  })
  var colors = new Array(51)
  for (let j = 0; j < 51; j++) {
    colors[j] = -1
  }

  for (let j = 0; j < a.length; j++) {
    if (colors[a[j]] === -1) colors[a[j]] = j
  }
  var res = ''
  for (let i = 0; i < q.length; i++) {
    res = res + (colors[q[i]]+1) + ' '
    for (let j = 0; j < 51; j++) {
      if (colors[j] < colors[q[i]] && colors[j] !== -1) colors[j] += 1
    }
    colors[q[i]] = 0
  }
  console.log(res)

  // })
}

'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*$/, ''));

    const [n, queries] = readLine().split(' ').map(Number);

    const arr = readLine().split(' ').map(Number);

    const colors = readLine().split(' ').map(Number); //query colors.

    c(n,queries,arr,colors)

});

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

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

function c(n,q,a,t)
{
    const N = 50;

    let pos = Array(N).fill(-1);
    for (let i = 0; i < n; i++) {
        if (pos[a[i]] < 0) pos[a[i]] = i;
    }
    let res = [];
    for (let k = 0; k < q; k++) {
        res.push(pos[t[k]] + 1);
        for (let i = 1; i < 60; i++) {
            if (pos[i] >= 0 && pos[i] < pos[t[k]]) {
                pos[i]++;
            }
        }
        pos[t[k]] = 0;
    }
    return console.log(res.join(' '))
}

module.exports = c;

'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*$/, ''));

    const [n, queries] = readLine().split(' ').map(Number);

    const arr = readLine().split(' ').map(Number);

    const colors = readLine().split(' ').map(Number); //query colors.

    c(n,queries,arr,colors)

});

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

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

function c(n,q,a,t)
{
    const N = 50;

    let pos = Array(N).fill(-1);
    for (let i = 0; i < n; i++) {
        if (pos[a[i]] < 0) pos[a[i]] = i;
    }
    let res = [];
    for (let k = 0; k < q; k++) {
        res.push(pos[t[k]] + 1);
        for (let i = 1; i < 51; i++) {
            if (pos[i] >= 0 && pos[i] < pos[t[k]]) {
                pos[i]++;
            }
        }
        pos[t[k]] = 0;
    }
    return console.log(res.join(' '))
}

module.exports = c;

'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 [n,q] = get_ints();
        let a = get_ints();
        let c = get_ints();
        let ans = [];
        var idx = 0;
        for(let i = 0 ;  i < q; i++)
        {
            let a_new = [];
            const color = c[i];
            for(let j = 0 ; j < n; j++)
            {
                if(a[j] === color)
                {
                   a_new.unshift(color)
                   ans.push(j+1);
                   //console.log('a_new = ', a_new, 'a.slice(j+1) = ', a.slice(j+1))
                   //print(a_new.concat(a.slice(j+1)))
                   idx = j;
                   break;
                }
                else
                {
                    a_new.push(a[j])
                }
            }
            a = a_new.concat(a.slice(idx+1));
        }
        print(ans);
});

function print(c){
    return console.log(c);
}

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

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

"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++];
}
class Node {
  constructor(val) {
    this.val = val;
    this.next = null;
    this.prev = null;
  }
}
class Dl {
  constructor() {
    this.head = null;
    this.tail = null;
  }
  push(val) {
    if (!this.head) this.head = this.tail = new Node(val);
    else {
      let newn = new Node(val);
      newn.prev = this.tail;
      this.tail = this.tail.next = newn;
    }
  }
  shift(val) {
    let newN = new Node(val);
    newN.next = this.head;
    this.head = newN;
  }
  remove(val) {
    let ind = 1,
      p = this.head;
    while (p) {
      if (p.val === val) {
        if (p.prev === null) return ind;
        else if (p.next === null) {
          this.shift(p.val);
          p.prev = null;
          this.tail = p.prev;
          return ind;
        } else {
          this.shift(p.val);
          p.prev.next = p.next;
          p.next.prev = p.prev;
          return ind;
        }
        break;
      }
      p = p.next;
      ind++;
    }
  }
}
const solve = () => {
  let t = 1;
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let q = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let list = new Dl();
    for (let i = 0; i < n; i++) list.push(arr[i]);
    let res = "";
    for (let i = 0; i < k; i++) res += list.remove(q[i]) + " ";
    console.log(res);
  }
};
solve();


An array is beautiful if both of the following two conditions meet:  there are at least $$$l_1$$$ and at most $$$r_1$$$ elements in the array equal to its minimum;  there are at least $$$l_2$$$ and at most $$$r_2$$$ elements in the array equal to its maximum. For example, the array $$$[2, 3, 2, 4, 4, 3, 2]$$$ has $$$3$$$ elements equal to its minimum ($$$1$$$-st, $$$3$$$-rd and $$$7$$$-th) and $$$2$$$ elements equal to its maximum ($$$4$$$-th and $$$5$$$-th).Another example: the array $$$[42, 42, 42]$$$ has $$$3$$$ elements equal to its minimum and $$$3$$$ elements equal to its maximum.Your task is to calculate the minimum possible number of elements in a beautiful array.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Each test case consists of one line containing four integers $$$l_1$$$, $$$r_1$$$, $$$l_2$$$ and $$$r_2$$$ ($$$1 \le l_1 \le r_1 \le 50$$$; $$$1 \le l_2 \le r_2 \le 50$$$).

For each test case, print one integer — the minimum possible number of elements in a beautiful array.

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseArray = readline().split(" ");
    var l1 = parseInt(caseArray[0]);
    var r1 = parseInt(caseArray[1]);
    var l2 = parseInt(caseArray[2]);
    var r2 = parseInt(caseArray[3]);
    var result = l1;
    if (l1 < l2)
    {
        if (r1 >= l2)
        {
            result = l2;
        }
        else
        {
            result = l1 + l2;
        }
    }
    if (l1 > l2)
    {
        if (l1 <= r2)
        {
            result = l1;
        }
        else
        {
            result = l1 + l2;
        }
    }
    print(result);
}

var t = +readline();

for(var i = 0; i< t; i ++) {
    var a = readline().split(' ').map((t) => +t);

    print(Task1(a));

}

function Task1(arr){

  var l1 = arr[0];
  var r1 = arr[1];
  var l2 = arr[2];
  var r2 = arr[3];
  var res = l1 + l2;
  if (l1 <= l2 && l2 <= r1) res = l2;
  if (l2 <= l1 && l1 <= r2) res = l1;
  return res;

}

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var _a = readline().split(' ').map(function (v) { return +v; }), l1 = _a[0], r1 = _a[1], l2 = _a[2], r2 = _a[3];
    var ans = void 0;
    if (r1 >= l2 && r2 >= l1) {
        ans = Math.max(l1, l2);
    }
    else {
        ans = l1 + l2;
    }
    print(ans);
}

let ryan = '';//.map(Numaer).sort(function(a, a){return a - a})
process.stdin.on('data', c => ryan += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = ryan.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var k = lines[j].split(' ').map(Number), a = k[0], b = k[1], c = k[2], d = k[3]

        if(Math.max(a, c) <= Math.min(b, d)){
            console.log(Math.max(a, c));
        }else{
            console.log(a + c);
        }
    }
});

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];
    for(i = 1; i <= t; i++){
        var a = lines[i].split(' ').map(Number);
        var l1 = a[0], r1 = a[1], l2 = a[2], r2 = a[3];
        if(Math.max(l1, l2) <= Math.min(r1, r2)){
            console.log(Math.max(l1, l2));
        }else{
            console.log(l1 + l2);
        }
    }
});

'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 [l1, r1, l2, r2] = readline().split(' ').map(Number);

        if (r1 < l2 || r2 < l1) {
            output(l1 + l2);
        } else {
            output(Math.max(l1, l2));
        }
    }
}

let text = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', str => {
    if (str === '\r\n' || str === '\n') {
        process.stdin.emit('end');
    } else {
        text += str;
    }
});

process.stdin.on('end', () => {
    const input = text.trim().replace(/\r/g, '').split('\n');
    const total = +input[0];

    for (let i = 1; i <= total; i++) {
        console.log(solve(input[i]));
    }

    process.exit();
});

function solve(str) {
    let [l1, r1, l2, r2] = str.split(' ').map(ele => +ele);
    if (r1 >= l2 && l1 <= r2) {
        return Math.max(l1, l2);
    }
    return l1 + l2;
}

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 arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(arr) {
    const [a, b, c, d] = arr
    if (a > c) return solve([c, d, a, b])
    if (c <= b) {
        return c
    } else {
        return a + c
    }
}

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let [inputString, currentLine] = ['', 0];
process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
});
const input = () => inputString[currentLine++];

const main = () => {
  let tc = parseInt(input());
  while(tc--){
    const a = Array(51).fill(0);
    const [l1, r1, l2, r2] = input().split(' ').map(Number);
    for(let i = l1; i <= r1; i++){
      a[i] += 1;
    }
    for(let i = l2; i <= r2; i++){
      a[i] += 1;
    }
    let two = false;
    for(let i = 1; i < 51; i++){
      if(a[i] === 2) two = true;
    }
    let ans = l1+l2;
    if(two){
      for(let i = 1; i < 51; i++){
        if(a[i] === 2){
          ans = Math.min(ans, i);
          break;
        }
      }
    }
    console.log(ans);
  }
}

'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(a) {
  const [l1, r1, l2, r2] = a;
  if (l1 <= l2) {
    if (r1 >= l2) {
      return l2;
    } else {
      return l1 + l2;
    }
  } else {
    if (l1 <= r2) {
      return l1;
    } else {
      return l1 + l2;
    }
  }
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const a = (await read()).split(' ').map(Number);
    res.push(solve(a));
  }
  console.log(res.join('\n'));
}

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);
}();

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

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;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [l1, r1, l2, r2] = ra();
  LT({l1, r1, l2, r2})
  for (let i=1; i<=100; i++){
    for (let j=0; j<=i; j++){
      let min_cnt = j;
      let max_cnt = i-j;
      if (j==0){
        min_cnt = i;
        max_cnt = i;
      }
      if (l1<=min_cnt && min_cnt<=r1)
        if (l2<=max_cnt && max_cnt<=r2)
          return i;
    }
  }
  throw 'error';
};

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);

/*---------------------------------------------------*/

const calc = ()=>{
    /* read */
    let [l1, r1, l2, r2] = ra();

    /* solve */
    let result = 0;

    if (l1 <= l2 && l2 <= r1) {
        return l2;
    }
    if (l2 <= l1 && l1 <= r2) {
        return l1;
    }

    return l1 + l2;
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc());
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}


There is a new attraction in Singapore Zoo: The Infinite Zoo.The Infinite Zoo can be represented by a graph with an infinite number of vertices labeled $$$1,2,3,\ldots$$$. There is a directed edge from vertex $$$u$$$ to vertex $$$u+v$$$ if and only if $$$u\&v=v$$$, where $$$\&$$$ denotes the bitwise AND operation. There are no other edges in the graph.Zookeeper has $$$q$$$ queries. In the $$$i$$$-th query she will ask you if she can travel from vertex $$$u_i$$$ to vertex $$$v_i$$$ by going through directed edges.

The first line contains an integer $$$q$$$ ($$$1 \leq q \leq 10^5$$$) — the number of queries. The $$$i$$$-th of the next $$$q$$$ lines will contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i < 2^{30}$$$) — a query made by Zookeeper.

For the $$$i$$$-th of the $$$q$$$ queries, output "YES" in a single line if Zookeeper can travel from vertex $$$u_i$$$ to vertex $$$v_i$$$. Otherwise, output "NO". You can print your answer in any case. For example, if the answer is "YES", then the output "Yes" or "yeS" will also be considered as correct answer.

NoteThe subgraph on vertices $$$1,2,3,4,5,6$$$ is shown below.

'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 = () => Number(read());
  let u = rn(),
      v = rn();
  if (u > v) return 'NO';
  if (u === v) return 'YES';
  if (u % 2 === 0 && v % 2 === 1) return 'NO';
  const count = num => {
    let cnt = 0;
    while (num) {
      cnt++;
      num -= num & -num;
    }
    return cnt;
  };
  if (count(u) < count(v)) return 'NO';
  let a = 0,
      b = 0;
  for (let i = 0; i < 32; i++) {
    if (1 << i > v) break;
    if (v & 1 << i) a++;
    if (u & 1 << i) b++;
    if (a > b) return 'NO';
  }
  return 'YES';
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      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);
}();

'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();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [u, v] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u > v) return console.log('NO')

        var ans = true
        var count = 0

        for (let i = 0; i < 40; i++) {
            if (u >> i & 1) count++

            if (v >> i & 1) {
                if(count<=0) ans = false
                count--
            }
        }
        console.log(ans?'YES':'NO')

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

'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 = () => Number(read());
  let u = rn(),
      v = rn();
  if (u > v) return 'NO';
  if (u === v) return 'YES';
  if (u % 2 === 0 && v % 2 === 1) return 'NO';
  const count = num => {
    let cnt = 0;
    while (num) {
      cnt++;
      num -= num & -num;
    }
    return cnt;
  };
  if (count(u) < count(v)) return 'NO';
  while (u) {
    if (v & 1 && !(u & 1)) return 'NO';
    v >>= 1;
    u >>= 1;
  }
  return 'YES';
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      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);
}();

'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 = () => Number(read());
  const u = rn(),
        v = rn();
  if (u > v) return 'NO';
  if (u === v) return 'YES';
  if (u % 2 === 0 && v % 2 === 1) return 'NO';
  const count = num => {
    let cnt = 0;
    while (num) {
      cnt++;
      num -= num & -num;
    }
    return cnt;
  };
  if (count(u) < count(v)) return 'NO';
  return 'YES';
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      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);
}();

'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();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [u, v] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u > v) return console.log('NO')

        var ans = true
        var count = 0

        for (let i = 0; i < 40; i++) {
            if (u >> i & 1) count++

            if (v >> i & 1) {
                if(count<0) {
                    ans = false
                    break
                }
                count--
            }
        }
        console.log(ans?'YES':'NO')

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}

'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();
    //
    Array(Number(x)).fill(1).map((t, iii) => {
        // var n = parseInt(readline())
        var [u, v] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        if (u > v) return console.log('NO')

        var ans = true
        var count = 0

        for (let i = 0; i < 40; i++) {
            if (u >> i & 1) count++

            if (v >> i & 1) {
                if(count<0) ans = false
                count--
            }
        }
        console.log(ans?'YES':'NO')

    })
}

function checkString(a) {
    // console.log(a)
    var count = 0
    var res = true
    for (let i = 0; i < a.length; i++) {
        if (a[i] === '(') count++
        else {
            count--
            if (count < 0) res = false
        }
    }
    if (count !== 0) res = false

    return res

}