Inflation has occurred in Berlandia, so the store needs to change the price of goods.The current price of good $$$n$$$ is given. It is allowed to increase the price of the good by $$$k$$$ times, with $$$1 \le k \le m$$$, k is an integer. Output the roundest possible new price of the good. That is, the one that has the maximum number of zeros at the end.For example, the number 481000 is more round than the number 1000010 (three zeros at the end of 481000 and only one at the end of 1000010).If there are several possible variants, output the one in which the new price is maximal.If it is impossible to get a rounder price, output $$$n \cdot m$$$ (that is, the maximum possible price).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. Each test case consists of one line. This line contains two integers: $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$). Where $$$n$$$ is the old price of the good, and the number $$$m$$$ means that you can increase the price $$$n$$$ no more than $$$m$$$ times.

For each test case, output on a separate line the roundest integer of the form $$$n \cdot k$$$ ($$$1 \le k \le m$$$, $$$k$$$ — an integer). If there are several possible variants, output the one in which the new price (value $$$n \cdot k$$$) is maximal. If it is impossible to get a more rounded price, output $$$n \cdot m$$$ (that is, the maximum possible price).

NoteIn the first case $$$n = 6$$$, $$$m = 11$$$. We cannot get a number with two zeros or more at the end, because we need to increase the price $$$50$$$ times, but $$$50 > m = 11$$$. The maximum price multiple of $$$10$$$ would be $$$6 \cdot 10 = 60$$$.In the second case $$$n = 5$$$, $$$m = 43$$$. The maximum price multiple of $$$100$$$ would be $$$5 \cdot 40 = 200$$$.In the third case, $$$n = 13$$$, $$$m = 5$$$. All possible new prices will not end in $$$0$$$, then you should output $$$n \cdot m = 65$$$.In the fourth case, you should increase the price $$$15$$$ times.In the fifth case, increase the price $$$12000$$$ times.

const readline = require('readline')

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

function solve(n, m) {
    const [rn, c2n, c5n] = helper(n)
    let now = 1n
    if (c2n > c5n) {
        let k = 0n
        while (c2n >= c5n + k + 1n && now * 5n <= m) {
            k++
            now *= 5n
        }
        n *= now
        m = m / now
    } else if (c2n < c5n) {
        let k = 0n
        while (c2n + k + 1n <= c5n && now * 2n <= m) {
            k++
            now *= 2n
        }
        n *= now
        m = m / now
    }
        // console.log(c2n, c5n, now)
    const sm = m.toString()
    const base = sm.length - 1
    return n * (10n ** BigInt(base)) * BigInt(sm[0])
}
function helper(n) {
    let c2 = 0n, c5 = 0n
    while (n > 0n && !(n % 2n)) {
        n /= 2n
        c2++
    }
    while (n > 0n && !(n % 5n)) {
        n /= 5n
        c5++
    }
    return [n, c2, c5]
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const [n, m] = rns();
  let len = 0,
      s = n.toString();
  for (let i = s.length - 1; i >= 0; i--) {
    if (s[i] === '0') len++;else break;
  }
  s = s.slice(0, s.length - len);
  let num = Number(s),
      res = 1;
  if (num % 5 === 0) {
    let cnt = 0;
    while (num % 5 === 0) {
      cnt++;
      num /= 5;
    }
    for (let i = cnt; i >= 0; i--) {
      if (2 ** i <= m) {
        res = 2 ** i;
        break;
      }
    }
  } else if (num % 2 === 0) {
    let cnt = 0;
    while (num % 2 === 0) {
      cnt++;
      num /= 2;
    }
    for (let i = cnt; i >= 0; i--) {
      if (5 ** i <= m) {
        res = 5 ** i;
        break;
      }
    }
  }
  for (; res * 10 <= m; res *= 10) {}
  const x = Math.floor(m / res);
  res *= x;
  return BigInt(n) * BigInt(res);
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      let s = solve(r);
      if (s === undefined) s = '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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


Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that.

The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@».

If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them.

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var text = trim(readline());
	var match = text.match(/^([a-z]+\@[a-z])*([a-z]+\@[a-z]+)$/);
	if (match) {
		var regex = /[a-z]+\@[a-z]/g;
		var groups = [];
		while (true) {
			var result = regex.exec(text);
			if (result === null) {
				break;
			}
			groups.push(result[0]);
		}
		var tail = text.match(/[a-z]+$/)[0].substring(1);
		groups[groups.length-1] += tail;
		print(groups.join(","));
	}
	else {
		print("No solution");
	}
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var text = trim(readline());

	var groups = [];
	var start = 0;

	while (true) {

		var pos = text.indexOf("@", start);

		if (pos == -1) {
			if (groups.length == 0) {
				print("No solution");
			}
			else {
				groups[groups.length-1] += text.substring(start);
				print(groups.join(","));
			}
			return;
		}

		if (pos == start || pos == text.length-1 || text.charAt(pos+1) == '@') {
			print("No solution");
			return;
		}

		groups.push(text.substring(start, pos+2));
		start = pos+2;
	}
}

main();

var s = readline()
print((s.match(/^@|@.?@|@$/) || !~s.indexOf('@')) ? 'No solution' : s.match(/[a-z]+@[a-z]/g).join() + s.slice(s.lastIndexOf('@') + 2))

'use strict'

let lll = readline()

;(function () {
  let spt = lll.split('@')
  if (spt.length < 2) return print('No solution')
  if (!spt[0] || !spt[spt.length - 1]) return print('No solution')
  if (spt.slice(1, -1).length != spt.slice(1, -1).filter(v => v.length > 1).length)
    return print('No solution')

  let as
  if (spt.length > 2) {
    as = [spt[0] + '@' + spt[1][0]]
    for (let i = 1; i < spt.length - 2; i++) {
      as.push(spt[i].slice(1) + '@' + spt[i + 1][0])
    }
    as.push(spt[spt.length - 2].slice(1) + '@' + spt[spt.length - 1])
  } else {
    as = [spt.join('@')]
  }
  print(as.join(','))
}())

//var numbers = readline().split(" ").map(function(x) { return parseInt(x); });
var emails = readline();
var answ = [];
dropStr(emails);

function dropStr(str) {
    for (var i = 0; i < str.length; ++i) {
        if (str[i] == '@') {
            answ.push(str.substr(0, i+2));
            str = str.substr(i+2);
            break;
        }
    }
    if (str.length > 0 && str.indexOf('@') !== -1) {
        dropStr(str);
    } else {
        if (answ[answ.length-1])
          answ[answ.length-1] = answ[answ.length-1].concat(str);
    }
}
var status = false;
for (var i = 0; i < answ.length; ++i) {
    var splited_anws = answ[i].split('@');
    if (splited_anws[0].length === 0 || splited_anws[1].length === 0) {
        status = true;
    }
}

if (!status && answ.length !== 0) {
    print(answ);
} else {
    print('No solution');
}

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var text = trim(readline());
	var groups = text.match(/^([a-z]+\@[a-z])*([a-z]+\@[a-z]+)$/);
	if (groups) {
		groups.splice(0, 1);
		print(groups.join(","));
	}
	else {
		print("No solution");
	}
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var text = trim(readline());
	var match = text.match(/^([a-z]+\@[a-z])+$/);
	if (match) {
		var groups = text.match(/[a-z]+\@[a-z]/g);
		print(groups.join(","));
	}
	else {
		print("No solution");
	}
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var text = trim(readline());

	var groups = [];
	var start = 0;

	while (true) {

		var pos = text.indexOf("@", start);

		if (pos == -1) {
			if (groups.length == 0) {
				print("No solution");
			}
			else {
				groups[groups.length-1] += text.substring(start);
				print(groups.join(","));
			}
			return;
		}

		if (pos == start || pos == text.length-1) {
			print("No solution");
			return;
		}

		groups.push(text.substring(start, pos+2));
		start = pos+2;
	}
}

main();

var s = readline()
print(s.match(/^@|@.?@|@$/) ? 'No solution' : s.match(/[a-z]+@[a-z]/g).join())

var s = readline()
print(s.match(/^@|@.?@|@$/) || !~s.indexOf('@')) ? 'No solution' : s.match(/[a-z]+@[a-z]/g).join() + s.slice(s.lastIndexOf('@') + 2)

'use strict'

let lll = readline()

;(function () {
  let spt = lll.split('@')
  if (spt.length < 2) return print('No solution')
  if (!spt[0] || !spt[spt.length - 1]) return print('No solution')
  if (spt.slice(1, -1).length != spt.slice(1, -1).filter(v => v.length > 1).length)
    return print('No solution')

  let as = [spt[0] + '@' + spt[1][0]]
  for (let i = 1; i < spt.length - 2; i++) {
    as.push(spt[i].slice(1) + '@' + spt[i + 1][0])
  }
  as.push(spt[spt.length - 2].slice(1) + '@' + spt[spt.length - 1])
  print(as.join(','))
}())


There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.Now let's create a task this way. We will use the task: you are given a tree, please calculate the distance between any pair of its nodes. Yes, it is very easy, but the inverse version is a bit harder: you are given an n × n distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).

The first line contains an integer n (1 ≤ n ≤ 2000) — the number of nodes in that graph. Then next n lines each contains n integers di, j (0 ≤ di, j ≤ 109) — the distance between node i and node j.

If there exists such a tree, output "YES", otherwise output "NO".

NoteIn the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7.In the second example, it is impossible because d1, 1 should be 0, but it is 1.In the third example, it is impossible because d1, 2 should equal d2, 1.

var n = parseInt(readline());
var a = new Array();
for(var i=0;i<n;i++)
{
    var b = readline().split(' ');
	a[i]=new Array();
	for(var j=0;j<b.length;j++)
	{
	    a[i][j]=parseInt(b[j]);
	}
}
// check
var isOK = 1;
for(var i=0;i<n;i++)
{
    if(a[i][i]!=0)
	{
	    isOK=0;
		break;
	}
	for(var j=i+1;j<n;j++)
	{
	    if(a[i][j]!=a[j][i] || a[i][j]==0)
		{
		    isOK=0;
			break;
		}
	}
}

// used: the list of ids which are used
var used = new Array();
used[0]=0;

// u[i]=1 -> node i is used.
var u = new Array();
for(var i=0;i<n;i++)
{
    u[i]=0;
}
u[0]=1;

if(isOK==0)
{
    print("NO");
}
else{
    var k=1;
    while(k<n)
    {
        // get the nearest node to node 0
	    var next_node = getNextNode();
		// get the parent node of next_node
		var pnode = getNearestNode(next_node);

		for(var i=0;i<used.length;i++)
		{
		    if(a[used[i]][pnode]+a[next_node][pnode]!=a[used[i]][next_node])
			{
			    isOK=0;
				break;
			}
		}
		if(isOK==1)
		{
		    used[used.length]=next_node;
		}
        else
	    {
	        break;
	    }
	    k++;
    }
    if(isOK==1)
    {
        print("YES");
    }
    else
    {
        print("NO");
    }
}

function getNextNode()
{
    var nd = -1;
	for(var i=0;i<n;i++)
	{
	    if(u[i]==0&&nd==-1)
		{
		    nd=i;
		}
		else if(u[i]==0&&nd!=-1)
		{
		    if(a[0][i]<a[0][nd])
			{
			    nd=i;
			}
		}
	}
	u[nd]=1;
	return nd;
}

function getNearestNode( nid )
{
   var pnode =used[0];
   for(var i=1;i<used.length;i++)
   {
       if(a[used[i]][nid]<a[pnode][nid])
	   {
	       pnode= used[i];
	   }
   }
   return pnode;
}

var n = parseInt(readline());
var a = new Array();
for(var i=0;i<n;i++)
{
    var b = readline().split(' ');
	a[i]=new Array();
	for(var j=0;j<b.length;j++)
	{
	    a[i][j]=parseInt(b[j]);
	}
}
// check
var isOK = 1;
for(var i=0;i<n;i++)
{
    if(a[i][i]!=0)
	{
	    isOK=0;
		break;
	}
	for(var j=i+1;j<n;j++)
	{
	    if(a[i][j]!=a[j][i] || a[i][j]==0)
		{
		    isOK=0;
			break;
		}
	}
	if(isOK==0)
	{
	    break;
	}
}

// used the array of ids which are used
var used = new Array();
used[0]=0;

var u = new Array();
for(var i=0;i<n;i++)
{
    u[i]=0;
}
u[0]=1;

if(isOK==0)
{
print("NO");
}
else{
    var k=1;
    while(k<n)
    {
        // get the nearest node of node 0
	    var tid = getNextNode();
		var i = getNearestNode(tid);

	    // parent id is node used[i]
		for(var j=0;j<used.length;j++)
		{
		    if(a[i][used[j]]+a[tid][i]!=a[used[j]][tid])
			{
			    isOK=0;
				break;
			}
		}
		if(isOK==1)
		{
		    used[used.length]=tid;
		}
        else
	    {
	        break;
	    }
	    k++;
    }
if(isOK==1)
{
    print("YES");
}
else
{
    print("NO");
}
}

function getNextNode()
{
    var fd = -1;
	for(var i=0;i<n;i++)
	{
	    if(u[i]==0&&fd==-1)
		{
		    fd=i;
		}
		else if(u[i]==0&&fd!=-1)
		{
		    if(a[0][i]<a[0][fd])
			{
			    fd=i;
			}
		}
	}
	u[fd]=1;
	return fd;
}

function getNearestNode( tid )
{
   var fd =used[0];
   for(var i=1;i<used.length;i++)
   {
       if(a[used[i]][tid]<a[fd][tid])
	   {
	       fd= used[i];
	   }
   }
   return fd;
}

var n = parseInt(readline());
var a = new Array();
for(var i=0;i<n;i++)
{
    var b = readline().split(' ');
	a[i]=new Array();
	for(var j=0;j<b.length;j++)
	{
	    a[i][j]=parseInt(b[j]);
	}
}
// check
var isOK = 1;
for(var i=0;i<n;i++)
{
	for(var j=i+1;j<n;j++)
	{
	    if(a[i][j]!=a[j][i] || a[i][j]==0)
		{
		    isOK=0;
			break;
		}
	}
}

// used: the list of ids which are used
var used = new Array();
used[0]=0;

// u[i]=1 -> node i is used.
var u = new Array();
for(var i=0;i<n;i++)
{
    u[i]=0;
}
u[0]=1;

if(isOK==0)
{
    print("NO");
}
else{
    var k=1;
    while(k<n)
    {
        // get the nearest node to node 0
	    var next_node = getNextNode();
		// get the parent node of next_node
		var pnode = getNearestNode(next_node);

		for(var i=0;i<used.length;i++)
		{
		    if(a[used[i]][pnode]+a[next_node][pnode]!=a[used[i]][next_node])
			{
			    isOK=0;
				break;
			}
		}
		if(isOK==1)
		{
		    used[used.length]=next_node;
		}
        else
	    {
	        break;
	    }
	    k++;
    }
    if(isOK==1)
    {
        print("YES");
    }
    else
    {
        print("NO");
    }
}

function getNextNode()
{
    var nd = -1;
	for(var i=0;i<n;i++)
	{
	    if(u[i]==0&&nd==-1)
		{
		    nd=i;
		}
		else if(u[i]==0&&nd!=-1)
		{
		    if(a[0][i]<a[0][nd])
			{
			    nd=i;
			}
		}
	}
	u[nd]=1;
	return nd;
}

function getNearestNode( nid )
{
   var pnode =used[0];
   for(var i=1;i<used.length;i++)
   {
       if(a[used[i]][nid]<a[pnode][nid])
	   {
	       pnode= used[i];
	   }
   }
   return pnode;
}

var n = parseInt(readline());
var a = new Array();
for(var i=0;i<n;i++)
{
    var b = readline().split(' ');
	a[i]=new Array();
	for(var j=0;j<b.length;j++)
	{
	    a[i][j]=parseInt(b[j]);
	}
}
// check
var isOK = 1;
for(var i=0;i<n;i++)
{
    if(a[i][i]!=0)
	{
	    isOK=0;
		break;
	}
	for(var j=i+1;j<n;j++)
	{
	    if(a[i][j]!=a[j][i])
		{
		    isOK=0;
			break;
		}
		if(a[i][j]==0)
		{
		    isOK=0;
			break;
		}
	}
	if(isOK==0)
	{
	    break;
	}
}

var x=new Array();
if(isOK==0)
{
    print("NO");
}
else if(n<=2)
{
    print("YES");
}
else
{
    x[0] = 0;
	x[1] = a[0][1];
	for(var i=2;i<n;i++)
	{
	    isOK=1;
	    for(var k=-1;k<=1;k+=2)
		{
		    isOK = 1;
			x[i]=k*a[0][i];
		    for(var j=0;j<i;j++)
			{
			    if(Math.abs(x[i]-x[j])!=a[i][j])
				{
//				print(i+': '+x[i] +j);
				    isOK=0;
					break;
				}
			}
			if(isOK==1)
			{
			    break;
			}
		}
		if(isOK==0)
		{
		    break;
		}
	}
	if(isOK==0)
	{
	    print("NO");
	}
	else
	{
	    print("YES");
	}
}

var n = parseInt(readline());
var a = new Array();
for(var i=0;i<n;i++)
{
    var b = readline().split(' ');
	a[i]=new Array();
	for(var j=0;j<b.length;j++)
	{
	    a[i][j]=parseInt(b[j]);
	}
}
// check
var isOK = 1;
for(var i=0;i<n;i++)
{
	for(var j=i+1;j<n;j++)
	{
	    if(a[i][j]!=a[j][i] || a[i][j]==0)
		{
		    isOK=0;
			break;
		}
	}
}

// used the list of ids which are used
var used = new Array();
used[0]=0;

// u[i]=1 -> node i is used.
var u = new Array();
for(var i=0;i<n;i++)
{
    u[i]=0;
}
u[0]=1;

if(isOK==0)
{
    print("NO");
}
else{
    var k=1;
    while(k<n)
    {
        // get the nearest node to node 0
	    var next_node = getNextNode();
		// get the parent node of next_node
		var pnode = getNearestNode(next_node);

		for(var i=0;i<used.length;i++)
		{
		    if(a[next_node][used[i]]+a[next_node][pnode]!=a[used[i]][next_node])
			{
			    isOK=0;
				break;
			}
		}
		if(isOK==1)
		{
		    used[used.length]=next_node;
		}
        else
	    {
	        break;
	    }
	    k++;
    }
    if(isOK==1)
    {
        print("YES");
    }
    else
    {
        print("NO");
    }
}

function getNextNode()
{
    var nd = -1;
	for(var i=0;i<n;i++)
	{
	    if(u[i]==0&&nd==-1)
		{
		    nd=i;
		}
		else if(u[i]==0&&nd!=-1)
		{
		    if(a[0][i]<a[0][nd])
			{
			    nd=i;
			}
		}
	}
	u[nd]=1;
	return nd;
}

function getNearestNode( nid )
{
   var pnode =used[0];
   for(var i=1;i<used.length;i++)
   {
       if(a[used[i]][nid]<a[pnode][nid])
	   {
	       pnode= used[i];
	   }
   }
   return pnode;
}

var n = parseInt(readline());
var a = new Array();
for(var i=0;i<n;i++)
{
    var b = readline().split(' ');
	a[i]=new Array();
	for(var j=0;j<b.length;j++)
	{
	    a[i][j]=parseInt(b[j]);
	}
}
// check
var isOK = 1;
for(var i=0;i<n;i++)
{
	for(var j=i+1;j<n;j++)
	{
	    if(a[i][j]!=a[j][i] || a[i][j]==0)
		{
		    isOK=0;
			break;
		}
	}
}

// used: the list of ids which are used
var used = new Array();
used[0]=0;

// u[i]=1 -> node i is used.
var u = new Array();
for(var i=0;i<n;i++)
{
    u[i]=0;
}
u[0]=1;

if(isOK==0)
{
    print("NO");
}
else{
    var k=1;
    while(k<n)
    {
        // get the nearest node to node 0
	    var next_node = getNextNode();
		print(next_node);
		// get the parent node of next_node
		var pnode = getNearestNode(next_node);
		print(pnode);

		for(var i=0;i<used.length;i++)
		{
		    if(a[used[i]][pnode]+a[next_node][pnode]!=a[used[i]][next_node])
			{
			    isOK=0;
				break;
			}
		}
		if(isOK==1)
		{
		    used[used.length]=next_node;
		}
        else
	    {
	        break;
	    }
	    k++;
    }
    if(isOK==1)
    {
        print("YES");
    }
    else
    {
        print("NO");
    }
}

function getNextNode()
{
    var nd = -1;
	for(var i=0;i<n;i++)
	{
	    if(u[i]==0&&nd==-1)
		{
		    nd=i;
		}
		else if(u[i]==0&&nd!=-1)
		{
		    if(a[0][i]<a[0][nd])
			{
			    nd=i;
			}
		}
	}
	u[nd]=1;
	return nd;
}

function getNearestNode( nid )
{
   var pnode =used[0];
   for(var i=1;i<used.length;i++)
   {
       if(a[used[i]][nid]<a[pnode][nid])
	   {
	       pnode= used[i];
	   }
   }
   return pnode;
}


You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index.

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$.

For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.

NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it.

var n = parseInt(readline())
while(n>0)
{
    var a = readline();
    var st = readline();

    flag=0;
    for(i=0;i<st.length;i++)
    {
        if(st[i]=='a')
            flag=1;
    }

    if(flag==1)
    {
        if(st.length==1)
        print("1")
        else
        print("-1")
    }
    else
    print(Math.pow(2,a.length))
    n=n-1;
}

function pow(n) {
  if (n === 1) {
    return 2;
  }
  if (n % 2 === 0) {
    return pow(n / 2) * pow(n / 2);
  }
  return 2 * pow(n - 1);
}

var n = parseInt(readline());

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

  if (t.indexOf("a") !== -1) {
    if (t.length > 1) {
      print(-1);
    } else {
      print(1);
    }
    continue;
  }
  print(pow(s.length));
}

var tests = parseInt(readline());
    var s, t;
    for (var ti=0; ti < tests; ti++) {
        s = readline();
        t = readline();
        if (t == 'a') {
            print(1);
            continue;
        }
        if (t.indexOf('a') != -1) {
            print(-1);
            continue;
        }

        print(Math.pow(2, s.length));
    }

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
//console.log(input);
var T = readline();
var f = [];
for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();

  // var s = 'aa', t = 'bbc'
  var len = s.length-1;
  var l = q == T ? t.length : t.length-1;
  var cnt = 0;
  var ans = 1;
  for(var i=0;i<l;i++) {
    if(t[i]=='a') cnt++;
  }
  if(cnt === 0) ans = Math.pow(2, len);
  else {
    if(l > 1) ans = -1;
    else ans = 1;
  }
  console.log(ans)

}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	// console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

function Main(){
    // input in nodeJs
	var t = nextInt();
    // console.log("\n ===============-===========")
	while(hasNext()){
		const stringArr = nextCharArray().join("");
		const replace = nextCharArray().join("");
        // if (!stringArr.includes("a")){
        //     myout(1);
        //     continue;
        // }

        if (replace.length >= 2 && replace.includes("a")) {
            myout(-1);
            continue;
        }

        if (replace.length === 1 && replace[0] === "a") {
            myout(1);
            continue;
        }

        myout(Math.pow(2, stringArr.length));
        // console.log(stringArr, replace)
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var L = next();
		var R = next();
		if(R == "a"){
			myout(1);
			continue;
		}
		if(L.indexOf("a") != -1 && R.indexOf("a") != -1){
			myout(-1);
			continue;
		}
		var c = 0n;
		for(var i = 0; i < L.length; i++){
			if(L[i] == "a"){
				c++;
			}
		}
		myout(1n << c);
	}
}

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

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

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

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

const calc = (s, t)=>{
    if (t === 'a') return 1;
    if (t.includes('a')) return -1;

    let n = s.length;
    let result = 0;
    for (let i = 0; i <= n; i++) {
        result += cnk(n, i);
    }
    return result;
};

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

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

const nums = [];
let res = 1n;
for (let i = 1n; i <= 50n; i++) {
  res *= i;
  nums[Number(i)] = res;
}
function solve(s, t) {
  if (t.indexOf('a') !== -1 && t.length > 1) {
    console.log(-1);
  } else if (t === 'a') {
    console.log(1);
  } else {
    let n = s.length,
        res = 2n;
    for (let i = 1; i < n; i++) {
      res += nums[n] / (nums[i] * nums[n - i]);
    }
    console.log(res.toString());
  }
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    const s = await read();
    const t = await read();
    solve(s, t);
  }
}

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

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
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 L = process.env.DEBUG ? console.log : ()=>{};

const pcalc = function(){
  print(calc.apply(null, arguments)); }

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

// SOLUTION

const calc = (a, t)=>{
  if (t=='a'){
    return 1;
  }
  if (t.indexOf('a')>=0)
    return -1;
  let num = BigInt(1);
  for (let i=0; i<a.length; i++)
    num *= BigInt(2);
  return num.toString();
};

function main() {
    let T = +readline()
    while (T--){
      let a = readline();
      let t = readline();
      L('Ans:');
      pcalc(a, t);
    }
}

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 str = lines[l++]
        const replace = lines[l++]
        output[i] = solve(str, replace)
    }
    console.log(output.join('\n'))
// })()
})

function solve(str, replace) {
    if (replace === 'a') return 1
    if (replace.indexOf('a') >= 0) return -1
    // return pow(str.length, replace.length)
    let a = BigInt(str.length)
    // let b = BigInt(replace.length)
    let ans = 1n
    while (a--) {
        ans *= 2n
    }
    return ans
}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aa', t = 'bbc'
  var len = q == 10000 ? s.length : s.length-1;
  var l = q == 10000 ? t.length: t.length-1;
  var cnt = 0;
  var ans = 1;
  for(var i=0;i<l;i++) {
    if(t[i]=='a') cnt++;
  }
  if(cnt === 0) ans = Math.pow(2, len);
  else {
    if(l > 1) ans = -1;
    else ans = 1;
  }
  console.log(ans);

}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aa', t = 'bbc'
  var len = q == T ? s.length : s.length-1;
  var l = q == T ? t.length: t.length-1;
  var cnt = 0;
  var ans = 1;
  for(var i=0;i<l;i++) {
    if(t[i]=='a') cnt++;
  }
  if(cnt === 0) ans = Math.pow(2, len);
  else {
    if(l > 1) ans = -1;
    else ans = 1;
  }
  console.log(ans);

}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aa', t = 'bbc'
  var len = s.length-1;
  var l = t.length-1;
  var cnt = 0;
  var ans = 1;
  for(var i=0;i<l;i++) {
    if(t[i]=='a') cnt++;
  }
  if(cnt === 0) ans = Math.pow(2, len);
  else {
    if(l > 1) ans = -1;
    else ans = 1;
  }
  if(q == 10000) {

      console.log(t);
  }
  console.log(ans);

}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aa', t = 'bbc'
  var len = s.length-1;
  var l = t.length-1;
  var cnt = 0;
  var ans = 1;
  for(var i=0;i<l;i++) {
    if(t[i]=='a') cnt++;
  }
  if(cnt === 0) ans = Math.pow(2, len);
  else {
    if(l > 1) ans = -1;
    else ans = 1;
  }
  if(q == 10000) {
      console.log(s);
      console.log(t);
  }
  console.log(ans);

}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aa', t = 'bbc'
  var len = s.length-1;
  var l = t.length-1;
  var cnt = 0;
  var ans = 1;
  for(var i=0;i<l;i++) {
    if(t[i]=='a') cnt++;
  }
  if(cnt === 0) ans = Math.pow(2, len);
  else {
    if(l > 1) ans = -1;
    else ans = 1;
  }
  console.log(ans);
  if(q == 10000) {
      console.log(s);
      console.log(t);
  }
}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aa', t = 'bbc'
  var len = s.length-1;
  var l = t.length-1;
  var cnt = 0;
  var ans = 1;
  for(var i=0;i<l;i++) {
    if(t[i]=='a') cnt++;
  }
  if(cnt === 0) ans = Math.pow(2, len);
  else {
    if(l > 1) ans = -1;
    else ans = 1;
  }
  console.log(ans);
}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aaaa', t = 'a'
  var cntS = 0, cntT = 0, l = t.length-1;
  var ans = -1;
  for(var i=0;i<s.length-1;i++) {
    if(s[i]=='a') cntS++;
  }
  for(var i=0;i<t.length-1;i++) {
    if(t[i]=='a') cntT++;
  }
  if(cntS !== 0 && cntT !== 0) {
    if(l > 1) ans = -1;
    else ans = 1;
  } else {
    if(cntS > 0) ans = Math.pow(2, cntS);
    else ans = 1;
  }
  console.log(ans);
}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aaaa', t = 'a'
  var cntS = 0, cntT = 0, l = t.length-1;
  var ans = -1;
  for(var i=0;i<s.length-1;i++) {
    if(s[i]=='a') cntS++;
  }
  for(var i=0;i<t.length-1;i++) {
    if(t[i]=='a') cntT++;
  }
  if(cntS !== 0 && cntT !== 0) {
    if(l > 1) ans = -1;
    else ans = 1;
  } else {
    if(cntS > 1) ans = Math.pow(2, cntS);
    else ans = 1;
  }
  console.log(ans);
}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aaaa', t = 'a'
  var cntS = 0, cntT = 0, l = t.length-1;
  var ans = -1;
  for(var i=0;i<s.length-1;i++) {
    if(s[i]=='a') cntS++;
  }
  for(var i=0;i<t.length-1;i++) {
    if(t[i]=='a') cntT++;
  }
  if(cntS !== 0 && cntT !== 0) {
    if(l > 1) ans = -1;
    else {
      if(l == 1) ans = 1;
      else ans = 2;
    }
  } else {
    if(cntS === 0) ans = 1;
    else {
      ans = Math.pow(2, cntS);
    }
  }
  console.log(ans);
}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aaaa', t = 'a'
  var cntS = 0, cntT = 0, l = t.length;
  var ans = -1;
  for(var i=0;i<s.length;i++) {
    if(s[i]=='a') cntS++;
  }
  for(var i=0;i<t.length;i++) {
    if(t[i]=='a') cntT++;
  }
  if(cntS !== 0 && cntT !== 0) {
    if(l > 1) ans = -1;
    else {
      if(l == 1) ans = 1;
      else ans = 2;
    }
  } else {
    if(cntS === 0) ans = 1;
    else {
      ans = Math.pow(2, cntS);
    }
  }
  console.log(s)
  console.log(t)
  console.log(s.length)
  console.log(t.length)
  console.log(ans);
}

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

for(var q=1;q<=T;q++) {
  var s = readline();
  var t = readline();
  // var s = 'aaaa', t = 'a'
  var cntS = 0, cntT = 0, l = t.length;
  var ans = -1;
  for(var i=0;i<s.length;i++) {
    if(s[i]=='a') cntS++;
  }
  for(var i=0;i<t.length;i++) {
    if(t[i]=='a') cntT++;
  }
  if(cntS !== 0 && cntT !== 0) {
    if(l > 1) ans = -1;
    else {
      if(l == 1) ans = 1;
      else ans = 2;
    }
  } else {
    if(cntS === 0) ans = 1;
    else {
      ans = Math.pow(2, cntS);
    }
  }
  console.log(ans);
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	// console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

function Main(){
    // input in nodeJs
	var t = nextInt();
    // console.log("\n ===============-===========")
	while(hasNext()){
		const stringArr = nextCharArray().join("");
		const replace = nextCharArray().join("");
        if (!stringArr.includes("a")){
            myout(1);
            continue;
        }

        if (replace.length >= 2 && replace.includes("a")) {
            myout(-1);
            continue;
        }

        if (replace.length === 1 && replace[0] === "a") {
            myout(1);
            continue;
        }

        myout(stringArr.split("").filter(ele => ele === "a").length + 1);
        // console.log(stringArr, replace)
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	// console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

function Main(){
    // input in nodeJs
	var t = nextInt();
    // console.log("\n ===============-===========")
	while(hasNext()){
		const stringArr = nextCharArray().join("");
		const replace = nextCharArray().join("");

        if (replace.length >= 2 && replace.includes("a")) {
            myout(-1);
            continue;
        }

        if (replace.length === 1 && replace[0] === "a") {
            myout(1);
            continue;
        }

        myout(stringArr.split("").filter(ele => ele === "a").length + 1);
        // console.log(stringArr, replace)
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	// console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

function Main(){
    // input in nodeJs
	var t = nextInt();
    console.log("\n ===============-===========")
	while(hasNext()){
		const stringArr = nextCharArray().join("");
		const replace = nextCharArray().join("");

        if (replace.length >= 2 && replace.includes("a")) {
            myout(-1);
            continue;
        }

        if (replace.length === 1 && replace[0] === "a") {
            myout(1);
            continue;
        }

        myout(stringArr.split("").filter(ele => ele === "a").length + 1);
        // console.log(stringArr, replace)
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var L = next();
		var R = next();
		if(R == "a"){
			myout(1);
			continue;
		}
		if(L.indexOf("a") != -1 && R.indexOf("a") != -1){
			myout(-1);
			continue;
		}
		var c = 0;
		for(var i = 0; i < L.length; i++){
			if(L[i] == "a"){
				c++;
			}
		}
		myout(1 << c);
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var L = next();
		var R = next();
		if(R == "a"){
			myout(1);
			continue;
		}
		if(R.indexOf("a") != -1){
			myout(-1);
			continue;
		}
		var c = 0;
		for(var i = 0; i < L.length; i++){
			if(L[i] == "a"){
				c++;
			}
		}
		myout(1 << c);
	}
}


You are given a book with $$$n$$$ chapters.Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list.Currently you don't understand any of the chapters. You are going to read the book from the beginning till the end repeatedly until you understand the whole book. Note that if you read a chapter at a moment when you don't understand some of the required chapters, you don't understand this chapter.Determine how many times you will read the book to understand every chapter, or determine that you will never understand every chapter no matter how many times you read the book.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot10^4$$$). The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of chapters. Then $$$n$$$ lines follow. The $$$i$$$-th line begins with an integer $$$k_i$$$ ($$$0 \le k_i \le n-1$$$) — number of chapters required to understand the $$$i$$$-th chapter. Then $$$k_i$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i, k_i}$$$ ($$$1 \le a_{i, j} \le n, a_{i, j} \ne i, a_{i, j} \ne a_{i, l}$$$ for $$$j \ne l$$$) follow — the chapters required to understand the $$$i$$$-th chapter. It is guaranteed that the sum of $$$n$$$ and sum of $$$k_i$$$ over all testcases do not exceed $$$2\cdot10^5$$$.

For each test case, if the entire book can be understood, print how many times you will read it, otherwise print $$$-1$$$.

NoteIn the first example, we will understand chapters $$$\{2, 4\}$$$ in the first reading and chapters $$$\{1, 3\}$$$ in the second reading of the book.In the second example, every chapter requires the understanding of some other chapter, so it is impossible to understand the book.In the third example, every chapter requires only chapters that appear earlier in the book, so we can understand everything in one go.In the fourth example, we will understand chapters $$$\{2, 3, 4\}$$$ in the first reading and chapter $$$1$$$ in the second reading of the book.In the fifth example, we will understand one chapter in every reading from $$$5$$$ to $$$1$$$.

const readline = require("readline");
const os = require("os");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let lineNum = 0, consumed = 0, lineNo = 0
let input = []
let res = []
let out = []

rl.on("line", (line) => {
  input.push(line)
  if (input.length === 2) {
    lineNum = +input[1]
  }

  if(input.length > 2) {
    consumed++
    input.pop()

    const tmp = line.split(' ').map(e => +e)
    lineNo++
    if(tmp.length > 1) {
      for(let j = 1; j < tmp.length; j++) {
        res.push([tmp[j], lineNo])
      }
    }

    if(consumed === lineNum) {
      const ans = solution(res, lineNum)
      out.push(ans === -1 ? -1 : ans)
      input.length = 1
      consumed = 0
      lineNo = 0
      res = []
    }
  }

});
rl.on("close", () => {
  let str = ''
  for(const e of out) str += e + os.EOL
  console.log(str)
});

function solution(arr, n) {
  const graph = {}, inDegree = Array(n + 1).fill(0)
  for(const [u, v] of arr) {
    if(graph[u] == null) graph[u] = []
    graph[u].push(v)
    inDegree[v]++
  }
  const q = [], visited = new Set(), times = Array(n + 1).fill(0)
  for(let i = 1; i <= n; i++) {
    if(inDegree[i] === 0) {
      q.push(i)
      visited.add(i)
    }
    times[i] = 1
  }

  while(q.length) {
    const cur = q.pop()
    for(const next of (graph[cur] || [])) {
      inDegree[next]--
      if(cur < next) times[next] = Math.max(times[cur], times[next])
      else times[next] = Math.max(times[next], times[cur] + 1)
      if(inDegree[next] === 0) {
        q.push(next)
        visited.add(next)
      }
    }
  }

  if (visited.size === n) {
    return Math.max(...times)
  } else return -1
}

const readline = require("readline");
const os = require("os");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let lineNo = 0, consumed = 0, lineth = 0
let input = []
let res = []
let out = []

rl.on("line", (line) => {
  input.push(line)
  if (input.length === 2) {
    lineNo = +input[1]
  }

  if(input.length > 2) {
    consumed++
    input.pop()

    const tmp = line.split(' ').map(e => +e)
    lineth++
    if(tmp.length > 1) {
      for(let j = 1; j < tmp.length; j++) {
        res.push([tmp[j], lineth])
      }
    }

    if(consumed === lineNo) {
      const ans = solution(res, lineNo)
      out.push(ans === -1 ? -1 : ans)
      input.length = 1
      consumed = 0
      lineth = 0
      res = []
    }
  }

});
rl.on("close", () => {
  let str = ''
  for(const e of out) str += e + os.EOL
  console.log(str)
});

function solution(arr, n) {
  const graph = {}, inDegree = Array(n + 1).fill(0)
  for(const [u, v] of arr) {
    if(graph[u] == null) graph[u] = []
    graph[u].push(v)
    inDegree[v]++
  }
  const q = [], visited = new Set(), times = Array(n + 1).fill(0)
  for(let i = 1; i <= n; i++) {
    if(inDegree[i] === 0) {
      q.push(i)
      visited.add(i)
    }
    times[i] = 1
  }

  while(q.length) {
    const cur = q.pop()
    for(const next of (graph[cur] || [])) {
      inDegree[next]--
      if(cur < next) times[next] = Math.max(times[cur], times[next])
      else times[next] = Math.max(times[next], times[cur] + 1)
      if(inDegree[next] === 0) {
        q.push(next)
        visited.add(next)
      }
    }
  }

  if (visited.size === n) {
    return Math.max(...times)
  } else return -1
}

const readline = require("readline");
const os = require("os");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let lineNo = 0, consumed = 0, lineth = 0
let input = []
let res = []

rl.on("line", (line) => {
  input.push(line)
  if (input.length === 2) {
    lineNo = +input[1]
  }

  if(input.length > 2) {
    consumed++

    const tmp = line.split(' ').map(e => +e)
    lineth++
    if(tmp.length > 1) {
      for(let j = 1; j < tmp.length; j++) {
        res.push([tmp[j], lineth])
      }
    }

    if(consumed === lineNo) {
      input.length = 1
      consumed = 0
      lineth = 0
      res = []
      const ans = solution(res, lineNo)
      console.log(ans === -1 ? -1 : ans)
    }
  }

});
rl.on("close", () => {
});

function solution(arr, n) {
  const graph = {}, inDegree = Array(n + 1).fill(0)
  for(const [u, v] of arr) {
    if(graph[u] == null) graph[u] = []
    graph[u].push(v)
    inDegree[v]++
  }
  const q = [], visited = new Set(), times = Array(n + 1).fill(0)
  for(let i = 1; i <= n; i++) {
    if(inDegree[i] === 0) {
      q.push(i)
      visited.add(i)
    }
    times[i] = 1
  }

  while(q.length) {
    const cur = q.shift()
    for(const next of (graph[cur] || [])) {
      inDegree[next]--
      if(cur < next) times[next] = Math.max(times[cur], times[next])
      else times[next] = Math.max(times[next], times[cur] + 1)
      if(inDegree[next] === 0) {
        q.push(next)
        visited.add(next)
      }
    }
  }

  if (visited.size === n) {
    return Math.max(...times)
  } else return -1
}

const readline = require("readline");
const os = require("os");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let lineNo = 0, consumed = 0
let input = []
let res = []

rl.on("line", (line) => {
  input.push(line)
  if (input.length === 2) {
    lineNo = +input[1]
  }

  if(input.length > 2) {
    consumed++

    const tmp = line.split(' ').map(e => +e)
    if(tmp.length > 1) {
      for(let j = 1; j < tmp.length; j++) {
        res.push([tmp[j], consumed])
      }
    }

    if(consumed === lineNo) {
      input.length = 1
      consumed = 0
      res = []
      const ans = solution(res, lineNo)
      console.log(ans === -1 ? -1 : ans)
    }
  }

});
rl.on("close", () => {
});

function solution(arr, n) {
  const graph = {}, inDegree = Array(n + 1).fill(0)
  for(const [u, v] of arr) {
    if(graph[u] == null) graph[u] = []
    graph[u].push(v)
    inDegree[v]++
  }
  const q = [], visited = new Set(), times = Array(n + 1).fill(0)
  for(let i = 1; i <= n; i++) {
    if(inDegree[i] === 0) {
      q.push(i)
      visited.add(i)
    }
    times[i] = 1
  }

  while(q.length) {
    const cur = q.shift()
    for(const next of (graph[cur] || [])) {
      inDegree[next]--
      if(cur < next) times[next] = Math.max(times[cur], times[next])
      else times[next] = Math.max(times[next], times[cur] + 1)
      if(inDegree[next] === 0) {
        q.push(next)
        visited.add(next)
      }
    }
  }

  if (visited.size === n) {
    return Math.max(...times)
  } else return -1
}


You are given an array $$$a$$$ of $$$n$$$ integers and an integer $$$s$$$. It is guaranteed that $$$n$$$ is odd.In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to $$$s$$$.The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array $$$6, 5, 8$$$ is equal to $$$6$$$, since if we sort this array we will get $$$5, 6, 8$$$, and $$$6$$$ is located on the middle position.

The first line contains two integers $$$n$$$ and $$$s$$$ ($$$1\le n\le 2\cdot 10^5-1$$$, $$$1\le s\le 10^9$$$) — the length of the array and the required value of median. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1\le a_i \le 10^9$$$) — the elements of the array $$$a$$$. It is guaranteed that $$$n$$$ is odd.

In a single line output the minimum number of operations to make the median being equal to $$$s$$$.

NoteIn the first sample, $$$6$$$ can be increased twice. The array will transform to $$$8, 5, 8$$$, which becomes $$$5, 8, 8$$$ after sorting, hence the median is equal to $$$8$$$.In the second sample, $$$19$$$ can be increased once and $$$15$$$ can be increased five times. The array will become equal to $$$21, 20, 12, 11, 20, 20, 12$$$. If we sort this array we get $$$11, 12, 12, 20, 20, 20, 21$$$, this way the median is $$$20$$$.

var ip = readline().split(' ').map(Number);
var index = ip[0], k = ip[1];
var ar = readline().split(' ').sort((a,b)=>a-b),ans = Math.abs(k-ar[Math.floor(index/2)]),i=Math.floor(index/2)-1,j = Math.floor(index/2)+1;
while (i >= 0 && ar[i] > k){
    ans+= (ar[i--]-k);
}
while (j < index && ar[j] < k){
    ans += (k-ar[j++]);
}
print(ans);

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

// function part(start, end) {
//     var p = nums[start];
//     while (start < end) {
//         while (start < end && nums[end] > p) {
//             end--;
//         }
//         nums[start] = nums[end];
//         while (start < end && nums[start] <= p) {
//             start++;
//         }
//         nums[end] = nums[start];
//     }
//     nums[start] = p;
//     return start;
// }
// function quickSort(k, start, end) {
//     if (start < end) {
//         var p = part(start, end);
//         if (p === k) return;
//         if (p > k) quickSort(k, start, p - 1);
//         if (p < k) quickSort(k - p - 1, p + 1, end);
//     }
// }

// quickSort(k, 0, n - 1);
nums.sort(function (a, b) {
    return a - b;
})
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)
// console.log(rst)

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
var rst = 0;
for (var i = k; i < n; i++){
    rst += Math.max(target - nums[i],0);
}
if (n>10) {
    print(`${nums.join(',')}`)
} else {
    print(rst)
}

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p - 1, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
// nums.sort(function (a, b) {
//     return a - b;
// })
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)
// console.log(rst)

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
var rst = 0;
for (var i = k; i < n; i++){
    rst += Math.max(target - nums[i],0);
}
if (n>10) {
    print(`${k} ${n} ${nums.join(',')}`)
} else {
    print(rst)
}

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
var rst = 0;
for (var i = k; i < n; i++){
    rst += Math.max(target - nums[i],0);
}

print(`${k} ${n} ${nums.join(',')}`)

var n_target = readline();
// // var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// // var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(nums.length / 2) + 1;

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k - 1) return;
        if (p > k - 1) quickSort(k, start, p - 1);
        if (p < k - 1) quickSort(k - p - 1, p + 1, end);
    }
}

quickSort(k, 0, nums.length - 1);

// quickSort(m, 0, nums.length - 1);
var rst = 0;
if (nums[k-1]<= target) {
    for (var i = k-1; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i < k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)
// console.log(rst)

// var n_target = readline();
var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
// var nums = readline();
var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

// function part(start, end) {
//     var p = nums[start];
//     while (start < end) {
//         while (start < end && nums[end] > p) {
//             end--;
//         }
//         nums[start] = nums[end];
//         while (start < end && nums[start] <= p) {
//             start++;
//         }
//         nums[end] = nums[start];
//     }
//     nums[start] = p;
//     return start;
// }
// function quickSort(k, start, end) {
//     if (start < end) {
//         var p = part(start, end);
//         if (p === k) return;
//         if (p > k) quickSort(k, start, p - 1);
//         if (p < k) quickSort(k - p - 1, p + 1, end);
//     }
// }

// quickSort(k, 0, n - 1);
nums.sort((a, b) => a - b);
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)
// console.log(rst)

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p - 1, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)

var n_target = readline();
var nums = readline();
// function print(rst){ console.log(rst) }
// var n_target = '7 20';
// var nums = '21 15 12 11 20 19 12';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);

nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(nums.length / 2) + 1;

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    var p = part(start, end);
    if (start < end) {
        while (p !== k - 1) {
            // console.log(p, k, nums);
            if (p === k - 1) return;
            if (p > k - 1) {
                p = part(start, p - 1);
                end = p;
                continue;
            }
            if (p < k - 1) {
                p = part(p + 1 , end);
                start = p + 1;
                continue;
            }
        }
        // var p = part(start, end);
        // if (p === k - 1) return;
        // if (p > k - 1) quickSort(k, start, p - 1);
        // if (p < k - 1) quickSort(k - p - 1, p + 1, end);
    }
}

quickSort(k, 0, nums.length - 1);

// quickSort(m, 0, nums.length - 1);
var rst = 0;
if (nums[k - 1] <= target) {
    for (var i = k - 1; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i < k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)
// console.log(rst)

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p);
        if (p < k) quickSort(k - p - 1, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
// nums.sort(function (a, b) {
//     return a - b;
// })
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)
// console.log(rst)

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p, p + 1, end);
    }
}

// quickSort(k, 0, n - 1);
nums.sort((a, b) => { return a - b });
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}
if (n === 499) {
    print(nums[k])
} else {
    print(rst)
}

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2) + 1;

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k-1) return;
        if (p > k-1) quickSort(k, start, p -1);
        if (p < k-1) quickSort(k - p - 1, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
// nums.sort(function (a, b) {
//     return a - b;
// })
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)
// console.log(rst)

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
var rst = 0;
for (var i = k; i < n; i++){
    rst += Math.max(target - nums[i],0);
}

print(rst)

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2) + 1;

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k-1) return;
        if (p > k-1) quickSort(k, start, p );
        if (p < k-1) quickSort(k - p - 1, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
// nums.sort(function (a, b) {
//     return a - b;
// })
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)
// console.log(rst)

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(n / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p, p + 1, end);
    }
}

quickSort(k, 0, n - 1);
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}
if (n === 499) {
    print(nums[k])
} else {
    print(rst)
}

var n_target = readline();
// var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(nums.length / 2);

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k) return;
        if (p > k) quickSort(k, start, p - 1);
        if (p < k) quickSort(k - p, p + 1, end);
    }
}

quickSort(k, 0, nums.length - 1);
var rst = 0;
for (var i = k; i < nums.length; i++){
    rst += Math.max(target - nums[i],0);
}

print(rst)

var n_target = readline();
// // var n_target = '7 20';
var n = +(n_target.split(' ')[0]);
var target = +(n_target.split(' ')[1]);
var nums = readline();
// // var nums = '21 15 12 11 20 19 12';
nums = nums.split(' ').map(function (ele) {
    return +ele;
});

var k = Math.floor(nums.length / 2) + 1;

function part(start, end) {
    var p = nums[start];
    while (start < end) {
        while (start < end && nums[end] > p) {
            end--;
        }
        nums[start] = nums[end];
        while (start < end && nums[start] <= p) {
            start++;
        }
        nums[end] = nums[start];
    }
    nums[start] = p;
    return start;
}
function quickSort(k, start, end) {
    if (start < end) {
        var p = part(start, end);
        if (p === k - 1) return;
        if (p > k - 1) quickSort(k, start, p - 1);
        if (p < k - 1) quickSort(k - p - 1, p + 1, end);
    }
}

quickSort(k, 0, nums.length - 1);

// quickSort(m, 0, nums.length - 1);
var rst = 0;
if (nums[k]<= target) {
    for (var i = k; i < n; i++) {
        rst += Math.max(target - nums[i], 0);
    }
} else {
    for (var i = 0; i <= k; i++) {
        rst += Math.max(nums[i] - target, 0);
    }
}

print(rst)
// console.log(rst)


A telephone number is a sequence of exactly $$$11$$$ digits such that its first digit is 8.Vasya and Petya are playing a game. Initially they have a string $$$s$$$ of length $$$n$$$ ($$$n$$$ is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string $$$s$$$ becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins.You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves).

The first line contains one integer $$$n$$$ ($$$13 \le n < 10^5$$$, $$$n$$$ is odd) — the length of string $$$s$$$. The second line contains the string $$$s$$$ ($$$|s| = n$$$) consisting only of decimal digits.

If Vasya has a strategy that guarantees him victory, print YES. Otherwise print NO.

NoteIn the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number.In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone number, because there is no digit 8 at all.

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var n = read.number();
    var s = read.arr();

    var lCount = n - 11;
    var hCount = lCount / 2;
    var vCount = 0;

    var g = false;

    for(var i = 0; i < n; i++) {
        if(s[i] === '8' && (i + 10) < n) {
            vCount ++;
        }
    }

    if(hCount >= vCount ) {
        print('NO');
    }
    else {
        print('YES')
    }
}());

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

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

let input_stdin = "";
let input_cursor = 0;

function nextString() {
    let next_string = "";
    clearWhitespaces();
    while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {
        next_string += input_stdin[input_cursor];
        input_cursor += 1;
    }
    return next_string;
}

function nextChar() {
    clearWhitespaces();
    if (input_cursor < input_stdin.length) {
        return input_stdin[input_cursor++];
    } else {
        return '\0';
    }
}

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

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

function clearWhitespaces() {
    while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) {
        input_cursor += 1;
    }
}

function main() {
    let n = nextInt();
    let fd = new Array(n + 2);
    fd.fill(0);
    let x = nextString();
    let ck = x.length - 11;
    let mvv = ck / 2, mvp = ck / 2;
    for (let i = 0; i < n; i++){
        if (x[i] === '8' && mvv)fd[i] = 1, mvv--;
        if (x[i] !== '8' && mvp)fd[i] = 1, mvp--;
    }
    for (let i = 0; i < n; i++){
        if (fd[i] === 0){
            if (x[i] === '8')console.log("Yes"); else console.log("NO");
            process.exit(0);
        }
    }
}