You are given a string $$$s$$$ consisting of characters 0 and/or 1.You have to remove several (possibly zero) characters from the beginning of the string, and then several (possibly zero) characters from the end of the string. The string may become empty after the removals. The cost of the removal is the maximum of the following two values:  the number of characters 0 left in the string;  the number of characters 1 removed from the string. What is the minimum cost of removal you can achieve?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing the string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$), consisting of characters 0 and/or 1. The total length of strings $$$s$$$ in all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the minimum cost of removal you can achieve.

NoteConsider the test cases of the example:  in the first test case, it's possible to remove two characters from the beginning and one character from the end. Only one 1 is deleted, only one 0 remains, so the cost is $$$1$$$;  in the second test case, it's possible to remove three characters from the beginning and six characters from the end. Two characters 0 remain, three characters 1 are deleted, so the cost is $$$3$$$;  in the third test case, it's optimal to remove four characters from the beginning;  in the fourth test case, it's optimal to remove the whole string;  in the fifth test case, it's optimal to leave the string as it is.

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var a = readline();
    var n = a.length;
    //print(n);
    var ans = 0;
    var max = [0];
    var pos = [0];
    var del = [0];
    var cur = 0;
    var curd = 0;
    for (var i = 0; i < n; i++) {
        ans += +(a[i] === '0');
        cur += +(a[i] === '0');
        curd += +(a[i] === '1');
        if (cur > max[max.length - 1]) {
            max.push(cur);
            pos.push(i + 1);
            del.push(curd);
        }
    }
    /*print('ans',ans);
    print('max', max);
    print('pos',pos);
    print('del', del);*/
    var win = 0;
    var r = max.length - 1;
    cur = 0;
    curd = 0;
    root: for (var i = n;;) {
        while (pos[r] > i || del[r] + curd > ans - cur - max[r]) {
            r--;
            if (r < 0) {
                break root;
            }
        }
        win = Math.max(win, cur + max[r]);
        //print('win', win, cur, max[r], r);
        if ((--i) < 0)
            break;
        cur += +(a[i] === '0');
        curd += +(a[i] === '1');
    }
    print(ans - win);
}

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

function solve(str) {
    let p, c
    const arr = []
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (x === p) {
            c++
        } else {
            if (c) {
                arr.push([p, c])
            }
            c = 1
            p = x
        }
    }
    arr.push([p, c])
    if (arr[0][0] === '0') arr.shift()
    if (arr.length && arr[arr.length - 1][0] === '0') arr.pop()
    //
    return cal(arr)
}
function cal(arr) {
    if (arr.length < 2) return 0
    const s0 = []
    const s1 = []
    arr.forEach(([p, c], i) => {
        const c0 = p === '0' ? c : 0
        const c1 = p === '1' ? c : 0
        s0[i] = i ? c0 + s0[i - 1] : c0
        s1[i] = i ? c1 + s1[i - 1] : c1
    })
    let ans = Infinity
    // [i, j]
    const helper = (i, j) => {
        // j++, a--, b++
        const a = s1[arr.length - 1] - (j < arr.length ? (s1[j] || 0) : s1[arr.length - 1])
            + (s1[i - 1] || 0)
        const b = (s0[j] || 0) - (s0[i - 1] || 0)
// if (isNaN(a) || isNaN(b)) {
//     console.log(arr, i, j)
//     throw 'sb'
// }
        return [a - b, Math.max(a, b)]
    }
    arr.forEach(([p, c], i) => {
        if (p === '1') {
            const k = binarySearch(i - 1, arr.length - 1, x => helper(i, x)[0] >= 0)
    // console.log(i, helper(i, k)[1], helper(i, k + 1)[1])
            ans = Math.min(
                ans,
                helper(i, k)[1],
                k + 1 < arr.length ? helper(i, k + 1)[1] : Infinity
            )
        }
    })
    return ans
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

'use strict';

var readline = require('readline');

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

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

function solve(s) {
  const n = s.length;
  let s0 = [],
      s1 = [];
  for (let i = 0; i < n; i++) {
    var _s, _s2;
    s0[i] = (_s = s0[i - 1]) !== null && _s !== void 0 ? _s : 0;
    s1[i] = (_s2 = s1[i - 1]) !== null && _s2 !== void 0 ? _s2 : 0;
    if (s[i] === '0') s0[i]++;else s1[i]++;
  }
  const dp = [];
  for (let i = 0; i < n; i++) {
    dp[i] = s1[i] + s0[n - 1] - s0[i];
  }
  let res = Math.min(s0[n - 1], n - s0[n - 1]);
  for (let j = n - 1; j >= 0; j--) {
    const a = s1[n - 1] - s1[j],
          b = s0[j];
    if (a >= b) {
      res = Math.min(res, a);
    } else {
      const i = b - a - 1;
      res = Math.min(res, a + s1[i], b - s0[i]);
    }
  }
  return res;
}

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

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

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

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

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

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

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let s = readline();
  let n = s.length;
  // PROCESSING:
  let Sl = new Array(n).fill(0);
  let Sr = new Array(n).fill(0);
  for (let i=n-1; i>=0; i--)
    Sr[i] = (i<n-1 ? Sr[i+1] : 0) + +(s[i]=='1');
  for (let i=0; i<n; i++)
    Sl[i] = (i>0 ? Sl[i-1] : 0) + +(s[i]=='1');
  LT({s, Sl, Sr});
  let l = 0, r = n;
  let check = (cnt)=>{
    let l = 0;
    let r = 0;
    for (let leftTake = 0; leftTake<=cnt; leftTake++){
      while (l<n && Sl[l]<=leftTake){
        l++;
      }
      while (r<n && Sr[r]>cnt-leftTake){
        r++;
      }
      let middleItems = r-l;
      let middleZeros = middleItems-((Sl[r-1]||0)-(Sl[l-1]||0));
      if (middleZeros<=cnt)
        return true;
    }
    return false;
  }
  while (l+2<r){
    let m = (l+r)>>1;
    L({l, m, r})
    if (check(m)){
      r = m+1;
    } else {
      l = m+1;
    }
  }
  if (check(l))
    return l;
  if (check(l+1))
    return l+1;
  return l+2;
};

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

function solve(str) {
    let p, c
    const arr = []
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (x === p) {
            c++
        } else {
            if (c) {
                arr.push([p, c])
            }
            c = 1
            p = x
        }
    }
    arr.push([p, c])
    if (arr[0][0] === '0') arr.shift()
    if (arr.length && arr[arr.length - 1][0] === '0') arr.pop()
    //
    return cal(arr)
}
function cal(arr) {
    if (arr.length < 2) return 0
    const s0 = []
    const s1 = []
    arr.forEach(([p, c], i) => {
        const c0 = p === '0' ? c : 0
        const c1 = p === '1' ? c : 0
        s0[i] = i ? c0 + s0[i - 1] : c0
        s1[i] = i ? c1 + s1[i - 1] : c1
    })
    let ans = Infinity
    // [i, j]
    const helper = (i, j) => {
        // j++, a--, b++
        const a = s1[arr.length - 1] - (j < arr.length ? s1[j] : s1[arr.length - 1])
            + (s1[i - 1] || 0)
        const b = (s0[j] || 0) - (s0[i - 1] || 0)
        return [a - b, Math.max(a, b)]
    }
// console.log(arr, s0, s1)
    arr.forEach(([p, c], i) => {
        if (p === '1') {
            const k = binarySearch(i - 1, arr.length - 1, x => helper(i, x)[0] >= 0)
    // console.log(i, helper(i, k)[1], helper(i, k + 1)[1])
            ans = Math.min(
                ans,
                helper(i, k)[1],
                k + 1 < arr.length ? helper(i, k + 1)[1] : Infinity
            )
        }
    })
    return ans
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

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

function solve(str) {
    let p, c
    let total0 = 0
    const arr = []
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (x === p) {
            c++
        } else {
            if (c) {
                arr.push([p, c])
                if (p === '0') total0 += c
            }
            c = 1
            p = x
        }
    }
    arr.push([p, c])
    if (p === '0') total0 += c
// console.log(arr, total0)
    let i = 0
    let j = arr.length - 1
    let ans1 = 0
    while (i <= j) {
        if (arr[i][0] === '0') {
            total0 -= arr[i][1]
            i++
        } else if (arr[j][0] === '0') {
            total0 -= arr[j][1]
            j--
        } else if (arr[i][1] <= arr[j][1]) {
            const cur = Math.max(ans1, total0)
            let ok = false
            if (i + 1 <= j) {
                const next = Math.max(ans1 + arr[i][1], total0 - arr[i + 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[i][1]
                    i++
                }
            }
            if (!ok && j - 1 >= i) {
                const next = Math.max(ans1 + arr[j][1], total0 - arr[j - 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[j][1]
                    j--
                }
            }
            if (!ok) break
        } else {
            const cur = Math.max(ans1, total0)
            let ok = false
            if (j - 1 >= i) {
                const next = Math.max(ans1 + arr[j][1], total0 - arr[j - 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[j][1]
                    j--
                }
            }
            if (!ok && i + 1 <= j) {
                const next = Math.max(ans1 + arr[i][1], total0 - arr[i + 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[i][1]
                    i++
                }
            }
            if (!ok) break
        }
    }
    // let ans0 = 0
    // for (let k = i; k <= j; k++) {
    //     if (arr[k][0] === '0') ans0 += arr[k][1]
    // }
    return Math.max(total0, ans1)
}

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

function solve(str) {
    let p, c
    let total0 = 0
    const arr = []
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (x === p) {
            c++
        } else {
            if (c) {
                arr.push([p, c])
                if (p === '0') total0 += c
            }
            c = 1
            p = x
        }
    }
    arr.push([p, c])
    if (p === '0') total0 += c
// console.log(arr, total0)
    let i = 0
    let j = arr.length - 1
    let ans1 = 0
    while (i <= j) {
        if (arr[i][0] === '0') {
            total0 -= arr[i][1]
            i++
        } else if (arr[j][0] === '0') {
            total0 -= arr[j][1]
            j--
        } else if (arr[i][1] <= arr[j][1]) {
            const cur = Math.max(ans1, total0)
            let ok = false
            if (i + 1 <= j) {
                const next = Math.max(ans1 + arr[i][1], total0 - arr[i + 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[i][1]
                    i++
                }
            }
            if (!ok) break
        } else {
            const cur = Math.max(ans1, total0)
            let ok = false
            if (j - 1 >= i) {
                const next = Math.max(ans1 + arr[j][1], total0 - arr[j - 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[j][1]
                    j--
                }
            }
            if (!ok) break
        }
    }
    // let ans0 = 0
    // for (let k = i; k <= j; k++) {
    //     if (arr[k][0] === '0') ans0 += arr[k][1]
    // }
    return Math.max(total0, ans1)
}


You're given an array $$$a$$$ of length $$$n$$$. You can perform the following operations on it:  choose an index $$$i$$$ $$$(1 \le i \le n)$$$, an integer $$$x$$$ $$$(0 \le x \le 10^6)$$$, and replace $$$a_j$$$ with $$$a_j+x$$$ for all $$$(1 \le j \le i)$$$, which means add $$$x$$$ to all the elements in the prefix ending at $$$i$$$.  choose an index $$$i$$$ $$$(1 \le i \le n)$$$, an integer $$$x$$$ $$$(1 \le x \le 10^6)$$$, and replace $$$a_j$$$ with $$$a_j \% x$$$ for all $$$(1 \le j \le i)$$$, which means replace every element in the prefix ending at $$$i$$$ with the remainder after dividing it by $$$x$$$. Can you make the array strictly increasing in no more than $$$n+1$$$ operations?

The first line contains an integer $$$n$$$ $$$(1 \le n \le 2000)$$$, the number of elements in the array $$$a$$$. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\dots$$$, $$$a_n$$$ $$$(0 \le a_i \le 10^5)$$$, the elements of the array $$$a$$$.

On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations. To print an adding operation, use the format "$$$1$$$ $$$i$$$ $$$x$$$"; to print a modding operation, use the format "$$$2$$$ $$$i$$$ $$$x$$$". If $$$i$$$ or $$$x$$$ don't satisfy the limitations above, or you use more than $$$n+1$$$ operations, you'll get wrong answer verdict.

NoteIn the first sample, the array is already increasing so we don't need any operations.In the second sample:In the first step: the array becomes $$$[8,6,3]$$$.In the second step: the array becomes $$$[0,2,3]$$$.

function main(n){

    print(n+1);
    print("2 " + n + " " + 1);
    print("1 " + n + " " + 1000000);
    for(var i = 1 ; i < n ; i++)print("2 " + i + " " + (1000000-i+1));

}

var n = parseInt(readline());
var arr = readline().split(" ");
main(n);

n = +readline();
res = (n+1)+'\n1 '+n+' 500000\n';
ar = readline().split(' ').forEach((num,ind)=>{
    num = +num;
    res += '2 '+ ind +' '+(num - ind)+'\n';
});
print(res);

n = +readline();
res = '1 '+n+' 500000\n';
ar = readline().split(' ').forEach((num,ind)=>{
    num = +num;
    res += '2 '+ ind +' '+(num - ind)+'\n';
});
print(res);

function main(n){

    print(n+1);
    print("2 " + n + " " + 1);
    print("1 " + n + " " + 1000000);
    for(var i = 1 ; i < n ; i++)print("2 " + i + " " + 1000000 - i + 1 );

}

var n = parseInt(readline());
var arr = readline().split(" ");
main(n);


Bob programmed a robot to navigate through a 2d maze.The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it.The robot can only move up, left, right, or down.When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.

The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze. The next n lines will contain exactly m characters each, denoting the maze. Each character of the maze will be '.', '#', 'S', or 'E'. There will be exactly one 'S' and exactly one 'E' in the maze. The last line will contain a single string s (1 ≤ |s| ≤ 100) — the instructions given to the robot. Each character of s is a digit from 0 to 3.

Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.

NoteFor the first sample, the only valid mapping is , where D is down, L is left, U is up, R is right.

var Dim=readline().split(' ').map(Number)
var Maze=[]
for (var i=0;i<Dim[0];++i) {
 Maze.push(readline().split(''))
}
var Path=readline().split('').map(Number)

function swap(T,i,j) {
    var t=T[i]; T[i]=T[j]; T[j]=t;
}
function nextPerm(T) {
    var i=T.length-2, j=T.length-1;
    while (i>=0 && T[i]>T[i+1]) --i;
    if (i<0) return null;
    while (T[i]>T[j]) --j;
    T = T.slice(0)
    swap(T,i,j)
    for (var k=0; k<((T.length-i-1)>>1); ++k)
        swap(T,i+1+k,T.length-1-k);
    return T;
}
function find(A, c) {
 for (var i=0;i<A.length;++i) {
  for (var j=0;j<A[i].length;++j) {
   if (A[i][j]===c) {
    return [i,j]
   }
  }
 }
}
var Shifts=[[0,1],[0,-1],[1,0],[-1,0]]
var D=[0,1,2,3]
var start0=find(Maze,'S');
var answer=0;

while (D) {
 var start = start0.slice(0)
 var found=false;
 for (var i=0; i<Path.length; ++i) {
  var shift = Shifts[D[Path[i]]]
  start[0] += shift[0]
  start[1] += shift[1]
  if (start[0]<0 || start[1]<0 ||
      start[0]>=Dim[0] || start[1]>=Dim[1]) break;
  if (Maze[start[0]][start[1]]==='#') break;
  found = found || (Maze[start[0]][start[1]]==='E')
 }
 if (found) ++answer;

 D=nextPerm(D)
}

print(answer)

var Dim=readline().split(' ').map(Number)
var Maze=[]
for (var i=0;i<Dim[0];++i) {
 Maze.push(readline().split(''))
}
var Path=readline().split('').map(Number)

function swap(T,i,j) {
    var t=T[i]; T[i]=T[j]; T[j]=t;
}
function nextPerm(T) {
    var i=T.length-2, j=T.length-1;
    while (i>=0 && T[i]>T[i+1]) --i;
    if (i<0) return null;
    while (T[i]>T[j]) --j;
    T = T.slice(0)
    swap(T,i,j)
    for (var k=0; k<((T.length-i-1)>>1); ++k)
        swap(T,i+1+k,T.length-1-k);
    return T;
}
function find(A, c) {
 for (var i=0;i<A.length;++i) {
  for (var j=0;j<A[i].length;++j) {
   if (A[i][j]===c) {
    return [i,j]
   }
  }
 }
}
var Shifts=[[0,1],[0,-1],[1,0],[-1,0]]
var D=[0,1,2,3]
var start=find(Maze,'S'), end=find(Maze,'E');
while (D) {
 for (var i=0; i<Path.length; ++i) {

 }
 D=nextPerm(D)
}


Haiku is a genre of Japanese traditional poetry.A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".Three phases from a certain poem are given. Determine whether it is haiku or not.

The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.

Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).

on  codeforces
beta round is running
   a rustling of keys

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  const ils = ipt.split(EOL).slice(0, -1)
  console.log(
       (ils[0].match(/[aeiou]/g) || '').length == 5
    && (ils[1].match(/[aeiou]/g) || '').length == 7
    && (ils[2].match(/[aeiou]/g) || '').length == 5
      ? 'YES'
      : 'NO'
  )
})

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

const vowels = ['a', 'e', 'i', 'o', 'u'];
const arr = [];

rl.on('line', (str) => {
  arr.push(str);
});

rl.on('close', () => {
  let r = [5, 7, 5];
  let ans = 'YES';

  for (let i = 0; i < arr.length; i++) {
    const v = r[i];
    let count = 0;

    for (let j = 0; j < arr[i].length; j++) {
      if (vowels.includes(arr[i][j])) {
        count++;
      }
    }

    if (count !== v) {
      ans = 'NO';
      break;
    }
  }

  console.log(ans);
});

print(function(a, b, c) {

	return cnt(a) === 5 && cnt(b) === 7 && cnt(c) === 5 ? 'YES' : 'NO';

	function cnt(s) {
		return s.split(/[aeiou]/).length - 1;
	}

}(readline(), readline(), readline()));

;(function () {

	print(function () {

		var s = [], n = 3, l = ['a', 'e', 'i', 'o', 'u'];
		while (n--) s.push(readline().split('').filter(function (e) { return l.indexOf(e) !== -1; }));

		return (s[0].length === 5 && s[1].length === 7 && s[2].length === 5) ? 'YES' : 'NO';

	}());

}.call(this));

function count(s) {
  var n = 0;
  for (var c of s)
    if ("aeiou".includes(c)) n++;
  return n;
}

print(count(readline()) === 5 && count(readline()) === 7 && count(readline()) === 5 ? "YES" : "NO");

'use strict';

/*let input = `how many gallons
of edo s rain did you drink
                                cuckoo`.split('\n');
function print(out) {
    console.log(out);
}
function readline() {
    return input.shift();
}*/

//code

var l1 = readline();
var l2 = readline();
var l3 = readline();
var result = [l1, l2, l3].map(function (line) {
    return line.split('').filter(function (char) {
        return ['a', 'e', 'i', 'o', 'u'].includes(char);
    }).length;
});
if (result[0] === 5 && result[1] === 7 && result[2] === 5) {
    print('YES');
} else {
    print('NO');
}

var i = 3;
var res = [];
var slogs = ['a', 'e', 'i', 'o', 'u'];
while(i--) {
	var str = readline();
	var curr = 0;
	for (var j = 0; j < str.length; j++) {
		if (slogs.indexOf(str[j]) !== -1) {
			curr++;
		}
	}
	res.push(curr);
}

var check = (res[0] === 5 && res[1] === 7 && res[2] === 5);
print( check ? 'YES' : 'NO');


Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.

The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file. Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the answer exists, i. e. the sum of all ai is not less than m.

Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.

NoteIn the first example Sean needs only two USB flash drives — the first and the third.In the second example Sean needs all three USB flash drives.In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.

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

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

  if (c === 1) {
    m = +d;
    c++;
    return;
  }

  arr.push(+d);

  c++;
});

rl.on('close', () => {
  arr.sort((a, b) => b - a);
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    m -= arr[i];
    ans++;

    if (m <= 0) {
      break;
    }
  }

  console.log(ans);
});

var n = +readline()
var m = +readline()
var a = []

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

function descendingComparator(a, b){return b-a}

a.sort(descendingComparator)

var numOfDrives = 0
var availableSpace = 0

for (var i = 0; i < n && availableSpace < m; i++)
{
	numOfDrives++;
	availableSpace += a[i];
}

print(numOfDrives)

n = +readline();
m = +readline();
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(+readline());
}
a.sort(function(a,b){return b - a;});
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += +a[i];
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort((a,b)=>b-a);
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += a[i];
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = +readline();
m = +readline();
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(+readline());
}
a.sort((a,b)=>b-a);
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += +a[i];
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

var USB = readline();
var size = readline();
var usbArr = [], sum=0, howMany=0;

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

function descendingComparator(usbArr, b){return b-usbArr}

usbArr.sort(descendingComparator)
for(var j=0; j<USB && sum < size; j++){
        howMany++
        sum+=usbArr[j]

}

print(howMany)

var n = +readline();
var m = +readline();
var a = new Array(n);
while (n--) {
    a.push(+readline());
}
a.sort((ai, aj) => aj - ai);
var minCount = 0;
var sumVolume = 0;
while (sumVolume < m) {
    sumVolume += a[minCount++];
}
write(minCount + "\n");

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

for (var i = 0; i < count; i++){read[i] = readline();}
read.sort(function(a, b){return b - a;})

for (var x = 0; x < count; x++){
if (read[x] < filesize){filesize -= read[x];calc+=1;}
else{calc+=1; x = count + 1;}
}
print(calc);

// 620B - Brooks Mershon
function drives(m, a) {
  var count = 0,
      sum = 0;

  a.sort(function(a, b) { return b - a});

  for (var i = 0; i < a.length; i++) {
    if (sum >= m) return count;
    count++;
    sum += a[i];
  }

  return count;
}
var n = parseInt(readline());
var m = parseInt(readline());

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

print(drives(m, d));

// console.log(drives(5, [2, 1, 3]));

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort();
a.reverse();
var sum = parseInt(0);
for (var i = 0 ; i < n ; i ++)
{
    sum += parseInt(a[i]);
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort();
a.reverse();
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += a[i];
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = readline();
m = readline();
a = [];
for (i = 0 ; i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort();
a.reverse();

var sum = 0;
for (i = 0 ; i < n ; i ++){
    sum += a[i];
    if (sum >= m){
        write(i + 1);
        break;
    }
}

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort((a,b)=>b-a);
a.reverse();
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += a[i];
    print(sum);
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort((a,b)=>b-a);
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += a[i];
    print(sum);
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}


A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not.You are given a string $$$s$$$ of length $$$n$$$, consisting of digits.In one operation you can delete any character from string $$$s$$$. For example, it is possible to obtain strings 112, 111 or 121 from string 1121.You need to determine whether there is such a sequence of operations (possibly empty), after which the string $$$s$$$ becomes a telephone number.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of string $$$s$$$. The second line of each test case contains the string $$$s$$$ ($$$|s| = n$$$) consisting of digits.

For each test print one line. If there is a sequence of operations, after which $$$s$$$ becomes a telephone number, print YES. Otherwise, print NO.

NoteIn the first test case you need to delete the first and the third digits. Then the string 7818005553535 becomes 88005553535.

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

const lines = [];

readline.on('line', (line) => {
  lines.push(line);
});

const processLine = (len, str) => {
  if (len < 11) {
    return 'NO';
  }

  const prefixPosition = str.indexOf('8');
  if (prefixPosition === -1) {
    return 'NO';
  }

  if (len - prefixPosition >= 11) {
    return 'YES';
  }

  return 'NO';
};

readline.on('close', () => {
  const [t, ...cases] = lines;

  for (let i = 0; i < Number(t) * 2; i += 2) {
    const len = cases[i];
    const str = cases[i + 1];
    console.log(processLine(len, str));
  }
});

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

let i = 0;

readline.on('line', line => {
    if (i > 0 && i%2 == 0) {
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            console.log('YES');
        else
            console.log('NO');
    }
    i++;
});

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

let i = 0, result = '';

readline.on('line', line => {
    if (i > 0 && i%2 == 0) {
        line = line.trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            console.log('YES');
        else
            console.log('NO');
    }
    i++;
});

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

let i = 0, result = '';

readline.on('line', line => {
    if (i > 0 && i%2 == 0) {
        line = line.trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            result += 'YES\n';
        else
            result += 'NO\n';
    }
    i++;
});

readline.on('close', () => {
    console.log(result);
});

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

let i = 0;

readline.on('line', line => {
    if (i > 0 && i%2 == 0) {
        line = line.trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            console.log('YES');
        else
            console.log('NO');
    }
    i++;
});

const { createInterface } = require('readline');
const lines = []

function solve() {
    const t = +lines[0];
for (let i =2; i <= t * 2; i+=2 ) {
    const s = lines[i]
    const l = lines[i].length;
    const pos8 = s.indexOf('8');
    if (pos8 === -1 || (l - pos8) < 11) {
        console.log('NO')
    } else {
        console.log('YES')
    }
}
}
( function processLineByLine() {
    const rl = createInterface({
      input: process.stdin
    });

    rl.on('line', (line) => {
        lines.push(line);
      });
      rl.on('close', solve)

})();

class CodeForcesNodeJS
{
    constructor()
    {
        this.stdin_input = "";
        this.arrInput = [];
        this.nInputIndex = 0;
    }

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

        process.stdin.on("data", this.onData.bind(this));
        process.stdin.on("end", this.solveWrapper.bind(this));
    }

    onData(input)
    {
        this.stdin_input += input;
    }

    prepareInput(input)
    {
        this.arrInput = input.replace(/\n/g, " ").split(" ");
        this.nInputIndex = 0;
    }

    nextInput(strConvertType = null)
    {
        let _response = this.arrInput[this.nInputIndex];
        ++this.nInputIndex;

        if(typeof _response === "undefined")
        {
            throw new Error("End of input reached.");
        }

        if(typeof _response !== "string")
        {
            throw new Error("Internal Error: input at current step not an instance of string!");
        }

        switch(strConvertType)
        {
            case "Integer":
                _response = parseInt(_response, 10);
                break;

            case null:
                break;

            default:
                throw new Error("Unrecognized type for conversion!");
        }

        return _response;

    }

    async solveWrapper()
    {
        this.prepareInput(this.stdin_input);
        await this.solve().catch(console.error);
    }

    solve()
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const _count = this.nextInput("Integer");
        for(let index = 0; index < _count; ++index)
        {
            const _length = this.nextInput("Integer");
            const _string = this.nextInput();

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1 || ((_length - _start_index) < _FIXED_LENGTH))
            {
                process.stdout.write("NO\n");
            }
            else
            {
                process.stdout.write("YEs\n");
            }
        }
    }
}

const _solver = new CodeForcesNodeJS();
_solver.start();

function main(input) {
    try
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const arrInput = input.replace(/\n/g, " ").split(" ");
        let _input_index = 0;

        const _count = parseInt(arrInput[_input_index++], 10);
        for(let index = 0; index < _count; ++index)
        {
            const _length = parseInt(arrInput[_input_index++], 10);
            const _string = arrInput[_input_index++];

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1 || ((_length - _start_index) < _FIXED_LENGTH))
            {
                process.stdout.write("NO\n");
            }
            else
            {
                process.stdout.write("YEs\n");
            }
        }
    }
    catch(_error)
    {
        console.log(_error);
    }
}

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

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

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

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  const idx = str.indexOf('8');
  const len = str.length - idx;

  if (idx === -1) {
    console.log('NO');
  }
  else if (len >= 11) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

let input = [];

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

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

RL.on('close', () => {
    let k = parseInt(input[0]);

    for(let i = 2; i <= k*2; i+=2){
        let flag = false; let pos = 0;
        [...input[i]].forEach( (j, index) => {
            if(j === '8' && !flag){
                flag = true; pos = index; return;
            }
        });
        if(flag && input[i].length - pos >= 11)
            console.log("YES");
        else
            console.log("NO");
    }
});

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

    for(var i = 0; i < n ;i++) {
        var l = read.number();
        var s = readline();

        if(l >= 11 && s.slice(0,l - 10).indexOf('8') > -1) {
            print('YES');
        }
        else {
            print('NO');
        }
    }
}());

/*only to understand how to use JS on codeforces*/

var t = +readline()
for ( var i = 0 ; i < t ; i++ ) {
  var n = +readline()
    , s = readline()
    , p = s.indexOf('8')
  if ( p != -1 && n - p >= 11 )
    print('YES')
  else
    print('NO')
}

var t=+readline()
for(var i=0;i<t;i++){
	var n=+readline(),s=readline(),	p=s.indexOf('8');
	if(p!=-1&&n-p>=11) print('YES')
	else print('NO')
}

let input = [];

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

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

RL.on('close', () => {
    let k = parseInt(input[0]);

    for(let i = 2; i <= k*2; i+=2){
        let flag = false; let pos = 0;
        [...input[i]].forEach( (j, index) => {
            if(j === '8' && !flag){
                flag = true; pos = index; return;
            }
        });
        if(flag && input[i].length - pos >= 8)
            console.log("YES");
        else
            console.log("NO");
    }
});

let input = [];

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

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

RL.on('close', () => {
    let k = parseInt(input[0]);

    for(let i = 2; i <= k*2; i+=2){
        let flag = false; let pos = 0;
        [...input[i]].forEach( (j, index) => {
            if(j === '8' && !flag){
                flag = true; pos = index+1; return;
            }
        });
        if(flag && input[i].length - pos >= 8)
            console.log("YES");
        else
            console.log("NO");
    }
});

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

const lines = [];

readline.on('line', (line) => {
  lines.push(line);
});

const processLine = (len, str) => {
  if (len < 11) {
    return 'NO';
  }

  const prefixPosition = str.indexOf('8');
  if (prefixPosition === -1) {
    return 'NO';
  }

  if (len - prefixPosition >= 11) {
    return 'YES';
  }

  return 'NO';
};

readline.on('close', () => {
  const [t, ...cases] = lines;

  for (let i = 0; i < Number(t); i += 1) {
    const len = cases[i];
    const str = cases[i + 1];
    console.log(processLine(len, str));
  }
});

let i = 0;
process.stdin.on('data', line => {
    if (i > 0 && i%2 == 0) {
        line = line.toString().trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            console.log('YES');
        else
            console.log('NO');
    }
    i++;
});

let i = 0, result = '';

process.stdin.on('data', line => {
    if (i > 0 && i%2 == 0) {
        line = line.toString().trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            result += 'YES\n';
        else
            result += 'NO\n';
    }
    i++;
});

process.stdin.on('end', () => {
    console.log(result);
});

function main(input) {
    try
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const arrInput = input.replace(/\n/g, " ").split(" ");
        let _input_index = 0;

        const _count = parseInt(arrInput[_input_index++], 10);
        for(let index = 0; index < _count; ++i)
        {
            const _length = parseInt(arrInput[_input_index++], 10);
            const _string = arrInput[_input_index++];

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1 || ((_length - _start_index) < _FIXED_LENGTH))
            {
                process.stdout.write("NO\n");
            }
            else
            {
                process.stdout.write("YEs\n");
            }
        }
    }
    catch(_error)
    {
        console.log(_error);
    }
}

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

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

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

function main(input) {
    try
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const arrInput = examinputle.replace(/\n/g, " ").split(" ");
        let _input_index = 0;

        const _count = parseInt(arrInput[_input_index++], 10);
        for(let index = 0; index < _count; ++i)
        {
            const _length = parseInt(arrInput[_input_index++], 10);
            const _string = arrInput[_input_index++];

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1)
            {
                print("NO");
            }
            else if((_length - _start_index) >= _FIXED_LENGTH)
            {
                print("YES");
            }
            else
            {
                print("NO");
            }
        }
    }
    catch(_error)
    {
        console.log(_error);
    }
    process.stdout.write("\n Your input multiplied by 10="+input*10);
}

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

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

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

try
{
    const _FIXED_LENGTH = 11;
    const _START_CHAR = "8";

    const _count = parseInt(readline(), 10);
    for(let index = 0; index < _count; ++i)
    {
        const _length = parseInt(readline(), 10);
        const _string = readline();
        const _start_index = _string.indexOf(_START_CHAR);

        if(_start_index === -1)
        {
            print("NO");
        }
        else if((_length - _start_index) >= _FIXED_LENGTH)
        {
            print("YES");
        }
        else
        {
            print("NO");
        }
    }
}
catch(_error)
{
    console.log(_error);
}

try
{
    const _FIXED_LENGTH = 11;
    const _START_CHAR = "8";

    const _count = parseInt(readline(), 10);
    for(let index = 0; index < _count; ++i)
    {
        const _length = parseInt(readline(), 10);
        const _string = readline();
        const _start_index = _string.indexOf(_START_CHAR);

        if(_start_index === -1)
        {
            print("NO");
        }
        else if((_length - _start_index) >= _FIXED_LENGTH)
        {
            print("YES");
        }
        else
        {
            print("NO");
        }
    }
}
catch(_error)
{
    console.error(_error);
}

function main(input) {
    try
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const arrInput = input.replace(/\n/g, " ").split(" ");
        let _input_index = 0;

        const _count = parseInt(arrInput[_input_index++], 10);
        for(let index = 0; index < _count; ++i)
        {
            const _length = parseInt(arrInput[_input_index++], 10);
            const _string = arrInput[_input_index++];

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1)
            {
                print("NO");
            }
            else if((_length - _start_index) >= _FIXED_LENGTH)
            {
                print("YES");
            }
            else
            {
                print("NO");
            }
        }
    }
    catch(_error)
    {
        console.log(_error);
    }
    process.stdout.write("\n Your input multiplied by 10="+input*10);
}

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

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

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

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  const idx = str.indexOf('8');
  const len = str.length - idx;

  if (idx === -1) {
    console.log('NO');
  }
  else if (len >= 10) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  if (str.length < 11) {
    console.log('NO');
    return;
  }

  const idx = str.indexOf('8');

  if (idx === -1) {
    console.log('NO');
  }
  else {
    const len = str.length - idx;

    if (len <= 11) {
      console.log('NO');
    }
    else {
      console.log('YES');
    }
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  if (str.length < 11) {
    console.log('NO');
    return;
  }

  const idx = str.indexOf('8');

  if (idx === -1) {
    console.log('NO');
  }
  else {
    const len = str.length - idx;

    if (len < 11) {
      console.log('NO');
    }
    else {
      console.log('YES');
    }
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  const idx = str.indexOf('8');
  const len = str.length - idx;

  if (len >= 10) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  if (str.length < 11) {
    console.log('NO');
    return;
  }

  let i = 0;
  while (str.length > 11 && i < str.length) {
    if (str[i] !== '8') {
      str = str.substr(0, i) + str.substr(i + 1);
      i = 0;
    }
    else {
      i++;
    }
  }

  if (str.length === 11 && str[0] === '8') {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  const idx = str.indexOf('8');
  const len = str.length - idx;

  if (idx === -1) {
    console.log('NO');
    return;
  }

  if (len >= 10) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

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

    for(var i = 0; i < n ;i++) {
        var l = read.number();
        var s = readline();

        if(l >= 11 && s.slice(0,l - 11).indexOf('8') > -1) {
            print('YES');
        }
        else {
            print('NO');
        }
    }
}());

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

    for(var i = 0; i < n ;i++) {
        var l = read.number();
        var s = readline();

        if(l >= 11 && s[l - 12] === '8') {
            print('YES');
        }
        else {
            print('NO');
        }
    }
}());


Maria participates in a bicycle race.The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa).Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored.Help Maria get ready for the competition — determine the number of dangerous turns on the track.

The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track. The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the point (xi, yi) and ends at the point (xi + 1, yi + 1). It is guaranteed that:   the first straight section is directed to the north;  the southernmost (and if there are several, then the most western of among them) point of the track is the first point;  the last point coincides with the first one (i.e., the start position);  any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point);  no pair of points (except for the first and last one) is the same;  no two adjacent straight sections are directed in the same direction or in opposite directions.

Print a single integer — the number of dangerous turns on the track.

NoteThe first sample corresponds to the picture:  The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.

/**
 * Created by Grizix
 */

function readIntTabLine(n) {
  var l = readline().split(' ')
  for (var i = 0 ; i < n ; i++) {
    l[i] = parseInt(l[i])
  }
  return l
}

var n = parseInt(readline())

readline()

var p = readIntTabLine(2),
    dir = 1,
    result = 0

for (var i = 1 ; i < n ; i ++) {
  var np = readIntTabLine(2)
  switch (dir) {
    case 1:
      if (np[0] < p[0]) result++, dir = 4
      else dir = 2
      break
    case 2:
      if (np[1] > p[1]) result++, dir = 1
      else dir = 3
      break
    case 3:
      if (np[0] > p[0]) result++, dir = 2
      else dir = 4
      break
    case 4:
      if (np[1] < p[1]) result++, dir = 3
      else dir = 1
      break
  }
  p = np
}

print(result)

function isLeft(point1, point2, point3) {
    if (point1[0] === point2[0] &&
        point2[1] === point3[1]) {
        if (point2[1] > point1[1]) {
            return point3[0] < point2[0];
        } else {
            return point3[0] > point2[0];
        }
    } else {
        if (point2[0] > point1[0]) {
            return point3[1] > point2[1];
        } else {
            return point3[1] < point2[1];
        }
    }
}

var arr = readline().split(" ", 1).map(Number);
var n = arr[0], xArr, yArr, ans = 0;
for (var i = 0; i <= n; ++i) {
    arr = readline().split(" ", 2).map(Number);
    if (i === 0) {
        xArr = arr;
    } else if (i === 1) {
        yArr = arr;
    } else {
        if (isLeft(xArr, yArr, arr)) {
            ++ans;
        }
        xArr = yArr;
        yArr = arr;
    }
}
print(ans);


Given a set of integers (it can contain equal elements).You have to split it into two subsets $$$A$$$ and $$$B$$$ (both of them can contain equal elements or be empty). You have to maximize the value of $$$mex(A)+mex(B)$$$.Here $$$mex$$$ of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:   $$$mex(\{1,4,0,2,2,1\})=3$$$  $$$mex(\{3,3,2,1,3,0,0\})=4$$$  $$$mex(\varnothing)=0$$$ ($$$mex$$$ for empty set) The set is splitted into two subsets $$$A$$$ and $$$B$$$ if for any integer number $$$x$$$ the number of occurrences of $$$x$$$ into this set is equal to the sum of the number of occurrences of $$$x$$$ into $$$A$$$ and the number of occurrences of $$$x$$$ into $$$B$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$) — the size of the set. The second line of each testcase contains $$$n$$$ integers $$$a_1,a_2,\dots a_n$$$ ($$$0\leq a_i\leq 100$$$) — the numbers in the set.

For each test case, print the maximum value of $$$mex(A)+mex(B)$$$.

NoteIn the first test case, $$$A=\left\{0,1,2\right\},B=\left\{0,1,5\right\}$$$ is a possible choice.In the second test case, $$$A=\left\{0,1,2\right\},B=\varnothing$$$ is a possible choice.In the third test case, $$$A=\left\{0,1,2\right\},B=\left\{0\right\}$$$ is a possible choice.In the fourth test case, $$$A=\left\{1,3,5\right\},B=\left\{2,4,6\right\}$$$ is a possible choice.

var cases = parseInt(readline());
for(var i = 0; i<cases; i++){
    var test = parseInt(readline());
    var input = readline().split(" ").map(x=>parseInt(x));
    input.sort(function(a,b){return a-b});
    var A = [];
    var B = [];
    var result = 0;
    for(var j = 0; j< input.length; j ++){
        if(!A.includes(input[j]))A.push(input[j]);
        else B.push(input[j]);
    }
    for(var x of [A,B]){
        var n = find(x);
        result+=n;
    }
    print(result);
}

function find (input){
    for(var k=0; k<=input[input.length-1]+1; k++){
        if(!input.includes(k)) return k;
    }
    return 0;
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const [arr1, arr2] = [Array(101).fill(0), Array(101).fill(0)];
    const arr = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (arr1[n] !== 0) arr2[n]++;
        else arr1[n]++;
        return n;
      });
    let ans = 0;

    for (let i = 0; i < arr1.length; i++) {
      if (arr1[i] === 0) {
        ans += i;
        break;
      }
    }

    for (let i = 0; i < arr2.length; i++) {
      if (arr2[i] === 0) {
        ans += i;
        break;
      }
    }
    console.log(ans);
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray();
		list.sort(function(a, b){
			return a - b;
		});
		var a = [];
		var b = [];
		for(var j = 0; j < N; j++){
			if(a.indexOf(list[j]) == -1){
				a.push(list[j]);
			}else{
				b.push(list[j]);
			}
		}
		var amin = 0;
		var bmin = 0;
		for(var j = 0; j <= 100; j++){
			if(a.indexOf(j) != -1){
				amin++;
			}else{
				break;
			}
		}
		for(var j = 0; j <= 100; j++){
			if(b.indexOf(j) != -1){
				bmin++;
			}else{
				break;
			}
		}
		output[i] = amin + bmin;
	}
	myout(myconv(output, 9));
}

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, cb) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = cb(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = cb(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, cb, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}

function max(a, b) {
  if (a > b) return a;
  return b;
}

(async () => {
  await inputPromise;
  let inp = input.split(/\D+/).map(v => +v); r = 0;
  let t = inp[r++];
  For(1, t, i => {
    let n = inp[r++];
    let a = inp.slice(r,r=r+n);
    let c = Arr(0,100,i=>a.filter(v=>v==i).length);
    let d1 = Arr(0,101).find(i=>c[i]<1);
    let d2 = Arr(0,101).find(i=>c[i]<2);
    console.log(d1+d2);
  })
})();

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

let inputString = ''
let currentLine = 0

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

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n')

    main()
})

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

const s2i = s => parseInt(s, 10)

const readLineOfBigInts = () => {
  const split = readLine().split(' ')
  const result = []
  for (let i = 0, l = split.length; i < l; i++) {
    result.push(BigInt(split[i]));
  }
  return result
}

const cmpi = (a, b) => a - b

function main() {
  let T = s2i(readLine())
  let out = ''

  while (T--) {
    const n = s2i(readLine())
    const a = readLine().split(' ').map(s2i)

    let result = 0
    const counts = []
    for (let i = 0; i <= 100; i++) {
      counts.push(0)
    }

    for (let i = 0, l = a.length; i < l; i++) {
      counts[a[i]] += 1
    }

    let add = 2

    if (counts[0] === 0) {
      out += '0\n'
      continue
    } else if (counts[0] === 1) {
      add = 1
    }

    for (let i = 1; i <= 100; i++) {
      const x = counts[i]
      result += add
      if (x === 0) break
      else if (x === 1) {
        add = 1
      }
    }

    out += result + '\n'
  }

  console.log(out)
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for (let i = 0; i < testQtd; i++) {
        const length = parseInt(readline());
        if (length === 0) {
            console.log(0);
            continue;
        }

        const array = readline().split(' ').map(x => parseInt(x)).sort((a, b) => a - b);

        let a = [];
        let b = [];
        let bigger = array[0]

        for (let i = 0; i < array.length; i++) {
            if (array[i] > bigger) {
                bigger = array[i];
            }

            const found = a.find(x => x === array[i]);

            if (found !== undefined) {
                b.push(array[i]);
            } else {
                a.push(array[i]);
            }
        }

        let respA = null;
        let respB = null;
        for (let i = 0; i <= bigger + 1; i++) {
            if (respA === null && a.find(x => x === i) === undefined) {
                respA = i;
            }
            if (respB === null && b.find(x => x === i) === undefined) {
                respB = i;
            }

            if (respA !== null && respB !== null) {
                console.log(respA + respB);
                break;
            }
        }
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {

    const testQtd = readline();

    for (let i = 0; i < testQtd; i++) {
        const length = parseInt(readline());
        if (length === 0) {
            console.log(0);
            continue;
        }

        const array = readline().split(' ').map(x => parseInt(x)).sort((a, b) => a - b);

        let a = [];
        let aIsDead = false;
        let b = [];
        let bIsDead = false;
        let bigger = array[0]

        for (let i = 0; i < array.length; i++) {
            if (array[i] > bigger) {
                bigger = array[i];
            }

            if (!aIsDead) {
                const found = a.find(x => x === array[i]);

                if (found !== undefined) {
                    if (!bIsDead) {
                        b.push(array[i]);
                    }
                } else {
                    a.push(array[i]);
                }
            } else {
                if (!bIsDead) {
                    b.push(array[i]);
                }
            }
        }

        let respA = null;
        let respB = null;
        for (let i = 0; i <= bigger + 1; i++) {
            if (respA === null && a.find(x => x === i) === undefined) {
                respA = i;
            }
            if (respB === null && b.find(x => x === i) === undefined) {
                respB = i;
            }

            if (respA !== null && respB !== null) {
                console.log(respA + respB);
                break;
            }
        }
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let arr = ti(readline().split(' '));

        let map = new Array(105);
        map.fill(0);
        let max = 0;
        for(let i = 0; i < n; i++){
            map[arr[i]] += 1;
            max = Math.max(max, arr[i]);
        }

        if(map[0] === 0){
            console.log(0);
            continue;
        }

        let a = [];
        let b = [];
        let aMax = 0;
        let bMax = 0;
        for(let i = 0; i <= max; i++){
            if(map[i] >= 2){
                a.push(i);
                b.push(i);
                aMax = i;
                bMax = i;
            }else if(map[i] !== 0){
                a.push(i);
                aMax = i;
            }
        }

        let res = 0;
        let mapA = new Array(aMax+2);
        let mapB = new Array(bMax+2);
        mapA.fill(0);
        mapB.fill(0);
        for(let i = 0; i < a.length; i++)
            mapA[a[i]] = 1;

        for(let i = 0; i < b.length; i++)
            mapB[b[i]] = 1;

        for(let i = 0; i < aMax+2; i++){
            if(mapA[i] === 0){
                res += i;
                break;
            }
        }

        for(let i = 0; i < bMax+2; i++){
            if(mapB[i] === 0){
                res += i;
                break;
            }
        }

        if(res === 0)
            console.log(max + 1);
        else
            console.log(res);
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        let neg = [];
        let pos = [];

        for(let i = 0; i < n; i++){
            if(a[i] < 0){
                neg.push({val: a[i], index: i});
            }else{
                pos.push({val: a[i], index: i});
            }
        }

        neg.sort((a,b) => a.val - b.val);
        pos.sort((a,b) => b.val - a.val);

    }
}


Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:   They are equal.  If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2, then one of the following is correct:   a1 is equivalent to b1, and a2 is equivalent to b2  a1 is equivalent to b2, and a2 is equivalent to b1  As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.Gerald has already completed this home task. Now it's your turn!

The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200 000 and consists of lowercase English letters. The strings have the same length.

Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.

NoteIn the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".

var print = this.print || require("lol-io").print;
var readline = this.readline || require("lol-io").readline;

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length % 2) return s1 === s2;

  const n = s1.length;
  const a1 = s1.substr(0, n / 2); const a2 = s1.substr(n / 2, n / 2);
  const b1 = s2.substr(0, n / 2); const b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length % 2 === 1) return s1 === s2;

  const n = s1.length;
  const a1 = s1.substr(0, n / 2); const a2 = s1.substr(n / 2, n / 2);
  const b1 = s2.substr(0, n / 2); const b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

var print = this.print || require("lol-io").print;
var readline = this.readline || require("lol-io").readline;

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length & 1) return s1 === s2;

  const n = s1.length;
  const a1 = s1.substr(0, n / 2); const a2 = s1.substr(n / 2, n / 2);
  const b1 = s2.substr(0, n / 2); const b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

function equal(a, b) {
    var size = a.length;
    var half = a.length / 2;

    var a1 = a.substr(0,half);
    var a2 = a.substr(half,a.length);
    var b1 = b.substr(0,half);
    var b2 = b.substr(half,b.length);

    if (a === b) {
        return true;
    } else if (size % 2 === 1 || size <= 1) {
        return false;
    } else if (equal(a1, b2) && equal(a2, b1)) {
        return true;
    } else if (equal(a1, b1) && equal(a2, b2)) {
        return true;
    } else {
        return false;
    }
}

var input_a = readline();
var input_b = readline();

equal(input_a, input_b) ? print('YES') : print('NO');

// process.stdin.setEncoding('utf8');
let lines = [];
// process.stdin.on('readable', () => {
//   let chunk;
//   // Use a loop to make sure we read all available data.
//   while ((chunk = process.stdin.read()) !== null) {
//     lines.push(chunk);
//     process.stdout.write('end');
//     if (lines.length === 2) {
//       process.stdout.write(`${equivalent(lines[0], lines[1]) ? 'YES' : 'NO'}`);
//       lines = [];
//     }
//   }
// });

// process.stdin.on('end', () => {
//   process.stdout.write('end');
// });

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

rl.on('line', function (line) {
  lines.push(line);
  if (lines.length === 2) {
    console.log(`${buildKey(lines[0]) === buildKey(lines[1]) ? 'YES' : 'NO'}`);
    lines = [];
    rl.close();
  }
})

function buildKey(str) {
  if ((str.length % 2) != 0) return str;
  const mid = str.length / 2;
  const lkey = buildKey(str.slice(0, mid)), rkey = buildKey(str.slice(mid));
  if (lkey <= rkey) {
    return `${lkey}${rkey}`;
  } else {
    return `${rkey}${lkey}`;
  }
}

function equivalent(strA, strB) {
  // process.stdout.write('[' + strA + '-' + strB + ']')
  if (strA.length !== strB.length) {
    return false;
  }
  // condition 1
  if (strA === strB) {
    return true;
  }
  // condition 2
  const length = strA.length;
  if ((length % 2) === 0) {
    const mid = length / 2;
    const a1 = strA.slice(0, mid), a2 = strA.slice(mid);
    const b1 = strB.slice(0, mid), b2 = strB.slice(mid);
    if (equivalent(a1, b1) && equivalent(a2, b2))
      return true;
    if (equivalent(a1, b2) && equivalent(a2, b1))
      return true;
  }

  return false;
}

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length === 1 || s1 === s2) return s1 === s2;

  n = s1.length;
  a1 = s1.substr(0, n / 2); a2 = s1.substr(n / 2, n / 2);
  b1 = s2.substr(0, n / 2); b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length % 2 === 1 || s1 === s2) return s1 === s2;

  n = s1.length;
  a1 = s1.substr(0, n / 2); a2 = s1.substr(n / 2, n / 2);
  b1 = s2.substr(0, n / 2); b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

const s1 = readline(); const s2 = readline();
print(is_equivalent(s1, s2)  ? 'YES' : 'NO');

function is_equivalent(s1, s2) {
  if(s1.length % 2 === 1) return s1 === s2;

  n = s1.length;
  a1 = s1.substr(0, n / 2); a2 = s1.substr(n / 2, n / 2);
  b1 = s2.substr(0, n / 2); b2 = s2.substr(n / 2, n / 2);
  return ((is_equivalent(a1, b2) && is_equivalent(a2, b1) || is_equivalent(a1, b1) && is_equivalent(a2, b2)));
}

var a = 'aaba'.split('');
var b = 'abaa'.split('');

if (a.length != b.length) {
  print('NO');
} else {
  for (var index = 0; index < a.length; index++) {
    for (var j = 0; j < a.length - 1; j++) {
      if (a[j] < a[j + 1]) {
        aux = a[j];
        a[j] = a[j + 1];
        a[j + 1] = aux;
      }
      if (b[j] < b[j + 1]) {
        aux = b[j];
        b[j] = b[j + 1];
        b[j + 1] = aux;
      }
    }
  }
  if (a.join() == b.join()) {
    print('YES');
  } else {
    print('NO');
  }
}

// process.stdin.setEncoding('utf8');
let lines = [];
// process.stdin.on('readable', () => {
//   let chunk;
//   // Use a loop to make sure we read all available data.
//   while ((chunk = process.stdin.read()) !== null) {
//     lines.push(chunk);
//     process.stdout.write('end');
//     if (lines.length === 2) {
//       process.stdout.write(`${equivalent(lines[0], lines[1]) ? 'YES' : 'NO'}`);
//       lines = [];
//     }
//   }
// });

// process.stdin.on('end', () => {
//   process.stdout.write('end');
// });

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

rl.on('line', function (line) {
  lines.push(line);
  if (lines.length === 2) {
    console.log(`${buildKey(lines[0]) === buildKey(lines[1]) ? 'YES' : 'NO'}`);
    lines = [];
    rl.close();
  }
})

function buildKey(str) {
  if ((str % 2) != 0) return str;

  const mid = str.length / 2;
  const lkey = buildKey(str.slice(0, mid)), rkey = buildKey(str.slice(mid));
  if (lkey <= rkey) {
    return `${lkey}${rkey}`;
  } else {
    return `${rkey}${lkey}`;
  }
}

function equivalent(strA, strB) {
  // process.stdout.write('[' + strA + '-' + strB + ']')
  if (strA.length !== strB.length) {
    return false;
  }
  // condition 1
  if (strA === strB) {
    return true;
  }
  // condition 2
  const length = strA.length;
  if ((length % 2) === 0) {
    const mid = length / 2;
    const a1 = strA.slice(0, mid), a2 = strA.slice(mid);
    const b1 = strB.slice(0, mid), b2 = strB.slice(mid);
    if (equivalent(a1, b1) && equivalent(a2, b2))
      return true;
    if (equivalent(a1, b2) && equivalent(a2, b1))
      return true;
  }

  return false;
}


It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly.Serval will go to the bus station at time $$$t$$$, and there are $$$n$$$ bus routes which stop at this station. For the $$$i$$$-th bus route, the first bus arrives at time $$$s_i$$$ minutes, and each bus of this route comes $$$d_i$$$ minutes later than the previous one.As Serval's best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them.

The first line contains two space-separated integers $$$n$$$ and $$$t$$$ ($$$1\leq n\leq 100$$$, $$$1\leq t\leq 10^5$$$) — the number of bus routes and the time Serval goes to the station.  Each of the next $$$n$$$ lines contains two space-separated integers $$$s_i$$$ and $$$d_i$$$ ($$$1\leq s_i,d_i\leq 10^5$$$) — the time when the first bus of this route arrives and the interval between two buses of this route.

Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.

NoteIn the first example, the first bus of the first route arrives at time $$$6$$$, and the first bus of the second route arrives at time $$$9$$$, so the first route is the answer.In the second example, a bus of the third route arrives at time $$$5$$$, so it is the answer.In the third example, buses of the first route come at times $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$, and so fourth, buses of the second route come at times $$$2$$$, $$$5$$$, $$$8$$$, and so fourth and buses of the third route come at times $$$2$$$, $$$6$$$, $$$10$$$, and so on, so $$$1$$$ and $$$2$$$ are both acceptable answers while $$$3$$$ is not.

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', sol);

function sol() {
  const [meta, ...routes] = input
    .split('\n')
    .map(line => line.split(' '));
  const [n, t] = meta.map(Number);
  let minRouteNum;
  let minWaitTime = Number.MAX_SAFE_INTEGER;
  for (let i = 0; i < n; ++i) {
    const [si, di] = routes[i].map(Number);
    let waitTime;
    if (t <= si) {
      waitTime = si - t;
    } else {
      const k = Math.ceil((t - si) / di);
      waitTime = si + k * di - t;
    }
    if (waitTime < minWaitTime) {
      minRouteNum = i + 1;
      minWaitTime = waitTime;
    }
  }
  process.stdout.write(
    minRouteNum.toString(),
    'utf8',
    () => process.stdout.end()
  );
}

(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 a = read.arrNumber(' ');
    var n = a[0];
    var t = a[1];

    var min;
    var res;
    for(var i = 0, line; i < n; i++) {
        line = read.arrNumber(' ');
        if(line[0] === t) {
            print(i + 1);
            return;
        }

        var time;
        if(line[0] > t) {
           time = line[0];
        }
        else {
            time = Math.ceil((t - line[0]) / line[1]) * line[1] + line[0];
        }

        if(!min || min > time) {
            min = time;
            res = i + 1;
        }
    }

    print(res);
}());

const nt = readline().split(" ").map(e => parseInt(e));
const n = nt[0];
const t = nt[1];

var ans = 0;
var timeA;
for (var i = 0; i < n; i++) {
    var sd = readline().split(" ").map(e => parseInt(e));
    var s = sd[0];
    var d = sd[1];

    var time;
    for (time = s; time < t; time += d) {

    }
    if (ans === 0 || timeA > time) {
        ans = i + 1;
        timeA = time;
    }
}
print(ans);

var nt = readline().split(' ').map(v=>(parseInt(v)))
var n = nt[0]
var t = nt[1]

var bestR = 1, bestT=-1;
for(var i=0;i<n; i++) {
    var sd = readline().split(' ').map(v=>(parseInt(v)))
    var s = sd[0]
    var d = sd[1]

    var D = (t>=s) ? Math.floor((t-s)/d):0;
    var cur = s + D*d;
    var waitingTime = (cur>=t) ? cur-t: (cur+d-t);

    //print('>>', s, '+', D, '*', d, cur, waitingTime)
    if(bestT===-1 || (waitingTime<bestT)) {
        bestT = waitingTime;
        bestR = i + 1;
    }
//    print(i, s,d, cur, bestT, bestR);
}
print(bestR);

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', sol);

function sol() {
  const [meta, ...routes] = input
    .split('\n')
    .map(line => line.split(' '));
  const [n, t] = meta.map(Number);
  let minRouteNum = -1;
  let minWaitTime = 0;
  for (let i = 0; i < n; ++i) {
    const [si, di] = routes[i].map(Number);
    const k = Math.ceil((t - si) / di);
    const waitTime = si + k * di - t;
    if (minRouteNum === -1 ||
      waitTime < minWaitTime) {
      minRouteNum = i + 1;
      minWaitTime = waitTime;
    }
  }
  process.stdout.write(
    minRouteNum.toString(),
    'utf8',
    () => process.stdout.end()
  );
}

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', sol);

function sol() {
  const [meta, ...routes] = input
    .split('\n')
    .map(line => line.split(' '));
  const [n, t] = meta.map(Number);
  let minRouteNum;
  let minWaitTime;
  for (let i = 0; i < n; ++i) {
    const [si, di] = routes[i].map(Number);
    const k = Math.ceil(Math.abs(t - si) / di);
    const waitTime = si + k * di - t;
    if (i === 0 || waitTime < minWaitTime) {
      minRouteNum = i + 1;
      minWaitTime = waitTime;
    }
  }
  process.stdout.write(
    minRouteNum.toString(),
    'utf8',
    () => process.stdout.end()
  );
}