Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn. Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.

The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.

Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).

NoteIn the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.In the third example for any values l and r there is a situation when Stepan said the truth.

var n = readline().split(' ').map(function(v){return +v;});
var a = readline().split(' ').map(function(v){return +v;});
var b = readline().split(' ').map(function(v){return +v;});

var fl=true;

for (var i = 0; i<n[1]-1; i++) {
    if (a[i]!=b[i]){
      fl=false;

    }
}

for (var i = n[2]; i<n[0]; i++) {
    if (a[i]!=b[i]){
      fl=false;
    }
}

if (fl===true){
   print('TRUTH');
}else{
    print('LIE');
}

var str = readline().split(' ');
var n = +str[0];
var l = +str[1];
var r = +str[2];
var a = readline().split(' ').map(function(v){return +v;});
var b = readline().split(' ').map(function(v){return +v;});
var c = new Array(100010);
for (i = 0; i < 100005; i++){
    c[i] = 0;
}
l--;
var ans = "TRUTH";

for (i = 0; i < n; i++){
    if (i < l || i >= r){
        if (a[i] != b[i]){
            ans = "LIE";
        }
    }
}

for (i = l; i < r; i++){
    c[a[i]]++;
}
for (i = l; i < r; i++){
    if (c[b[i]] > 0){
        c[b[i]]--;
    } else {
        ans = "LIE";
    }
}
print(ans);

var line = readline().split(' ');
var aa = readline().split(' ');
var bb = readline().split(' ');
var n = +line[0];
var l = +line[1];
var r = +line[2];
l = l-1;
r = r-1;
var inA = [];
var inB = [];
var lie=false;
for (i =0;i<n;i++){
    if (((i<l) || (i>r)) && aa[i]!=bb[i]){
        lie=true;
        break;
    }
    if (aa[i]!=bb[i]){
        inA.push(aa[i]);
        inB.push(bb[i]);
    }
}
if (lie){
    print("LIE");
}else{
    inA.sort();
    inB.sort();
    for(i=0;i<inA.length;i++){
        if (inA[i]!=inB[i]){
            lie=true;
            break;
        }
    }
    if (lie){
    print("LIE");
}else{
    print("TRUTH");
}
}

var inp = readline();
    var n = inp.split(' ')[0];
    var l = inp.split(' ')[1];
    var r = inp.split(' ')[2];

    var flag = true;

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

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

    for (var i = 1; i <= n; ++i)
    {
        if (i < l || i > r)
        {
            if (a1[i - 1] != a2[i - 1])
            {
                flag = false;
                break;
            }
        }
    }
    if (flag === true)
    {
        print("TRUTH");
    }
    else
    {
        print("LIE");
    }

var meta = readline().split(" ").map(function(n) {return parseInt(n)});

var count = meta[0];
var left = meta[1] - 1;
var right = meta[2];

var a = readline().split(" ").map(function(n) {return parseInt(n)});
var b = readline().split(" ").map(function(n) {return parseInt(n)});
var lie = false;
for (var i = 0; i < left; ++i) {
	if (a[i] !== b[i]) {
		lie = true;
		break;
	};
};

if (!lie) {
	for (var i = right; i < a.length; ++i) {
		if (a[i] !== b[i]) {
			lie = true;
			break;
		};
	};
}

print(!lie ? "TRUTH": "LIE");

var t = readline().split(' ');
var n = parseInt(t[0]);
var l = parseInt(t[1]) - 1;
var r = parseInt(t[2]);
var a = readline().split(' ');
var b = readline().split(' ');
var good = true;

for (i = 0; i < n; i++) {
    a[i] = parseInt(a[i]);
    b[i] = parseInt(b[i]);
}

for (i = 0; i < l && good; i++)
    if (a[i] != b[i])
        good = false;
for (i = r; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

a.sort();
b.sort();

for (i = 0; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

print(good ? "TRUTH" : "LIE")

var tmp = readline().split(' ');
var n = +tmp[0];
var l = +tmp[1];
var r = +tmp[2];
var b = readline().split(' ').map(function(v){return +v;});
var a = readline().split(' ').map(function(v){return +v;});

var ans = 1;
l--; r--;
for(var i = 0; i<l; i++)
if(a[i] != b[i])
{
    ans = 0;
}
for(var i = r+1; i<n; i++)
{
    if(a[i] != b[i])
    {
        ans = 0;
    }
}
var A = [];
var B = [];

for(var i = l; i<=r; i++)
{
    A.push(a[i]);
    B.push(b[i]);
}

A.sort();
B.sort();

r-=l;
for(var i = 0; i<=l; i++)
if(A[i]!=B[i])
{
    ans = 0;
}

if(ans != 0)
{
    print("TRUTH");
}
else
{
    print("LIE");
}

var s1 = readline().split(' ');
var a = readline().split(' ');
var b = readline().split(' ');
var n = parseInt(s1[0]);
var l = parseInt(s1[1]);
var r = parseInt(s1[2]);

var e = true;
--l;
--r;

for (var i = 0; i < l; ++i) {
if (a[i] != b[i]) e = false;
}
for (var i = r + 1; i < n; ++i) {
if (a[i] != b[i]) e = false;
}

var a2 = a.slice(l, r + 1);
var b2 = b.slice(l, r + 1);
a2.sort();
b2.sort();

for (var i = 0; i < a2.length; ++i) {
if (a2[i] != b2[i]) e = false;
}

if (e)
print('TRUTH');
else
print('LIE');

p = readline().split(" ").map(function(x) { return parseInt(x); });
a = readline().split(" ").map(function(x) { return parseInt(x); });
b = readline().split(" ").map(function(x) { return parseInt(x); });
p[0] = p[0] - 1;
p[1] = p[1] - 1;
p[2] = p[2] - 1;
var x = true;
for (var i = 0; i < p[1]; ++i) {
    if (a[i] != b[i]) {
        x = false;
        break;
    }
}
for (var i = p[2] + 1; i < p[0]; ++i) {
    if (a[i] != b[i]) {
        x = false;
        break;
    }
}
if (x) {
    aa = a.slice(p[1], p[2] + 1).sort();
    bb = b.slice(p[1], p[2] + 1).sort();
    for (var i = 0; i < aa.length; ++i) {
        if (aa[i] != bb[i]) {
            x = false;
            break;
        }
    }
}
if (x) {
    print('TRUTH');
} else {
    print('LIE');
}

var nums = readline().split(' ');
var n = +nums[0];
var l = +nums[1];
var r = +nums[2];
var a = readline().split(' ').map(function(v) {return +v;});
var b = readline().split(' ').map(function(v) {return +v;});

function main() {
  for (var i = 0; i < l - 1; ++i) {
    if (a[i] !== b[i]) {
      print("LIE");
      return;
    }
  }

  for (var i = r; i < n; ++i) {
    if (a[i] !== b[i]) {
      print("LIE");
      return;
    }
  }

  var na = a.slice(l - 1, r);
  var nb = b.slice(l - 1, r);

  na.sort();
  nb.sort();

  for (var i = 0; i < na.length; ++i) {
    if (na[i] !== nb[i]) {
      print("LIE");
      return;
    }
  }

  print("TRUTH");
}

main();

var inp = readline().split(' ');
var a = readline().split(' ');
var b = readline().split(' ');
var ca = a.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));
var cb = b.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));
ca.sort();
cb.sort();
var ans = true;
for (var i = 0; i < ca.length; i++) {
    if (ca[i] != cb[i])
        ans = false;
}
for (var i = 0; i < a.length; i++) {
    if (i < parseInt(inp[1]) - 1 || i >= parseInt(inp[2])) {
        if (a[i] != b[i])
        ans = false;
    }
}
if (ans)
    print("TRUTH");
else
    print("LIE");

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

var n = ii[0];
var l = ii[1];
var r = ii[2];

var a = readline().split(' ');
var b = readline().split(' ');

var f = true;
for(var i = 0; i < l - 1; ++i){
   if(a[i] != b[i]) f = false;
}
for(var i = r; i < n; ++i){
   if(a[i] != b[i]) f = false;
}

var na = Array(r - l + 1);
var nb = Array(r - l + 1);

var cnt = 0;
for(var i = l - 1; i < r; ++i, cnt++){
   na[cnt] = a[i];
   nb[cnt] = b[i];
}

na.sort();
nb.sort();

for(var i = 0; i < cnt; ++i){
   if(na[i] != nb[i]){
      f = false;
   }
}

if(f == true){
   print("TRUTH");
} else {
   print("LIE");
}

function main() {
    var line = readline().split(" ");
    var n = parseInt(line[0]);
    var l = parseInt(line[1]) - 1;
    var r = parseInt(line[2]) - 1;

    line = readline();
    var a = line.split(" ");
    a.forEach(function(x, i) {
        a[i] = parseInt(a[i]);
    });

    line = readline();
    var b = line.split(" ");
    b.forEach(function(x, i) {
        b[i] = parseInt(b[i]);
    });

    for (var i = 0; i < l; ++i) {
        if (a[i] != b[i]) {
            print("LIE");
            return;
        }
    }

    for (var i = r + 1; i < n; ++i) {
        if (a[i] != b[i]) {
            print("LIE");
            return;
        }
    }

    print("TRUTH");
}

main();

a = readline().split(' ');
n = a[0];
l = a[1];
r = a[2];
a = readline().split(' ');
b = readline().split(' ');
good = true;
for (i = 0; i < n; ++i)
  if (a[i] != b[i] && !(i >= l - 1 && i <= r - 1))
    good = false;
if (good)
  print('TRUTH');
else
  print('LIE');

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     // '4 2 4',
//     // '1 1 1 1',
//     // '1 1 1 1'
//     // '10 3 7',
//     // '678 45 78 11 90 98 99999 21 89 9',
//     // '678 45 99999 90 11 89 98 78 21  9',
//     // '6 3 5',
//     // '6 7 9 0 1 8',
//     // '6 7 0 9 1 8'
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourceBefore = source.slice(0, l);
var destBefore = dest.slice(0, l);

var sourceAfter = source.slice(r + 1, source.length + 1);
var destAfter = dest.slice(r + 1, source.length + 1);

var sourcePart = source.slice(l, r + 1);
var destPart = dest.slice(l, r + 1);
sourcePart.sort();
destPart.sort();

var truth = true;

for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        print('LIE');
        truth = false;
        break;
    }
}

if (truth) {
    for (var i = 0; i < sourceBefore.length; i++) {
        if (sourceBefore[i] !== destBefore[i]) {
            print('LIE');
            truth = false;
            break;
        }
    }

    if (truth) {
        for (var i = 0; i < sourceAfter.length; i++) {
            if (sourceAfter[i] !== destAfter[i]) {
                print('LIE');
                truth = false;
                break;
            }
        }
    }
}

if (truth) {
    print('TRUTH');
}

var K = readline().split(' ').map( x => +x);
var n = K[0];
var l = K[1];
var r = K[2];
l--;r--;

var a = readline().split(' ').map( x => +x);

var b = readline().split(' ').map( x => +x);

var ok = true;

for(var i=0;i<l;i++) if(a[i] != b[i]) ok = false;
for(var i=r+1;i<n;i++) if(a[i] != b[i]) ok = false;

var counts = (arr) => {
    var obj = {};
    for(var i=l;i<=r;i++) {
        if(!(arr[i] in obj)) obj[arr[i]] = 1;
        else obj[arr[i]]++;
    }
    return obj;
}

var A = counts(a);
var B = counts(b);

for(var i=l;i<=r;i++) if(A[a[i]] != B[a[i]]) ok = false;

if(ok) print("TRUTH");
else print("LIE");

var S = readline().split(" ").map(function(x) { return parseInt(x); });
n = S[0]; l = S[1]; r = S[2];
var A = readline().split(" ").map(function(x) { return parseInt(x); });
var B = readline().split(" ").map(function(x) { return parseInt(x); });
l--;
S = A;
T = B;
A = A.slice(l, r);
B = B.slice(l, r);
A.sort();
B.sort();
if(JSON.stringify(A) == JSON.stringify(B)){
	var ok = true;
	for(i = 0; i < l && ok; i++){
		if(S[i] != T[i]) ok = false;
	}
	for(i = r; i < n && ok; i++){
		if(S[i] != T[i]) ok = false;
	}
	if(ok) print("TRUTH");
	else print("LIE");
}else{
	print("LIE");
}

var prsi = function(i) { return +i; };
var reg = /\s+/;
var ln = readline().split(reg).map(prsi);
var n = ln[0], l = ln[1] - 1, r = ln[2] - 1;
var a = readline().split(reg).map(prsi),
	b = readline().split(reg).map(prsi);

var flag = 1;
for(var i = 0; i < l; ++i) {
	if(a[i] !== b[i]) {
		flag = 0;
		break;
	}
}

if(flag) {
	for(var i = r + 1; i < n; ++i) {
		if(a[i] !== b[i]) {
			flag = 0;
			break;
		}
	}
}

if(flag) print("TRUTH");
else print("LIE");

"use strict";
if (typeof readline == 'undefined') {
    let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var readline = () => lines[id++];
    var print = console.log;
}
let nums = () => readline().split(' ').map(x => +x);
let t = nums(), n = t[0], l = --t[1], r = --t[2];
let a = nums();
let b = nums();

let c = Array(n).fill(0);
let ans = true;
for (let i = l; i <= r; ++i) {
    ++c[a[i] - 1];
    --c[b[i] - 1];
}
for (let i = 0; i < l && ans; ++i) {
    if (a[i] !== b[i])
        ans = false;
}
for (let i = r + 1; i < n && ans; ++i) {
    if (a[i] != b[i])
        ans = false;
}

if (ans) ans = c.every(x => x === 0);

if (ans) print("TRUTH");
else print("LIE");

var temp = readline().split(' ').map(Number);
var n = temp[0];
var l = temp[1];
var r = temp[2];
//print(n)
//print(l)
//print(r)
var fr = readline().split(' ').map(Number);
var sc = readline().split(' ').map(Number);
l -= 1;
r -= 1;
var ch = 1;
for (var i = 0; i < l; i++) {
	if (fr[i] != sc[i])	{
		ch = 0;
		//exit(0);
	}
}
for (var i = r + 1; i < n; i++) {
	if (fr[i] != sc[i]) {
		ch = 0;
		//exit(0);
	}
}
var c1 = [];
var c2 = [];
for (var i = l; i <= r; i++) {
	c1.push(fr[i]);
	c2.push(sc[i]);
}
c1.sort();
c2.sort();
for (var i = l; i <= r; i++) {
	if (c1[i - l] != c2[i - l]) {
		ch = 0;
		//exit(0);
	}
}
if (ch == 0)
	print("LIE");
else
	print("TRUTH");

(function work() {
    var n, l, r;
    var A, B;
    var hash = {};
    var arr, i;
    arr = readline().split(' ');
    arr = arr.map((s) => parseInt(s));
    n = arr[0];
    l = arr[1] - 1;
    r = arr[2] - 1;
    arr = readline().split(' ');
    A = arr.map((s) => parseInt(s));
    for (i = l; i <= r; i ++) {
        if (!hash[A[i]])
            hash[A[i]] = 1;
        else
            hash[A[i]] ++;
    }
    arr = readline().split(' ');
    B = arr.map((s) => parseInt(s));
    for (i = 0; i < l; i ++) {
        if (A[i] !== B[i]) {
            print('LIE');
            return;
        }
    }
    for (i = l; i <= r; i ++) {
        if (!hash[B[i]] || hash[B[i]] === 0) {
            print('LIE');
            return;
        } else {
            hash[B[i]] --;
        }
    }
    for (i = r + 1; i < n; i ++) {
        if (A[i] !== B[i]) {
            print('LIE');
            return;
        }
    }
    print('TRUTH');
})();

var tmp = readline().split(' ');
var n = +tmp[0];
var l = +tmp[1] - 1;
var r = +tmp[2] - 1;
var a = readline().split(' ');
var b = readline().split(' ');
var ans = true;
var g = [], f = [];
for (var i = 0; i < n; i++) {
    if (i < l || i > r) {
        if (a[i] != b[i]) {
            ans = false;
        }
    } else {
        g.push(a[i]);
        f.push(b[i]);
    }
}
if (ans && f.sort().toString() == g.sort().toString()) {
    print("TRUTH");
} else {
    print("LIE");
}

var t = readline().split(' ');
var n = t[0];
var l = parseInt(t[1]) - 1;
var r = t[2];
var a = readline().split(' ');
var b = readline().split(' ');
var good = true;

for (i = 0; i < n; i++) {
    a[i] = parseInt(a[i]);
    b[i] = parseInt(b[i]);
}

for (i = 0; i < l && good; i++)
    if (a[i] != b[i])
        good = false;
for (i = r; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

a.sort();
b.sort();

for (i = 0; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

print(good ? "TRUTH" : "LIE")

var t = readline().split(' ');
var n = t[0];
var l = t[1] - 1;
var r = t[2];
var a = readline().split(' ');
var b = readline().split(' ');
var good = true;
for (i = 0; i < l && good; i++)
    if (a[i] != b[i])
        good = false;
for (i = r; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

a.sort();
b.sort();

for (i = 0; i < n && good; i++)
    if (a[i] != b[i])
        good = false;

print(good ? "TRUTH" : "LIE")

var tmp = readline().split(' ');
var n = +tmp[0];
var l = +tmp[1];
var r = +tmp[2];
var a = readline().split(' ').map(function(v){return +v;});
b = a;
var ans = 1;
l--; r--;
for(var i = 0; i<l; i++)
if(a[i] != b[i])
{
    ans = 0;
}
for(var i = r+1; i<n; i++)
if(a[i] != b[i])
{
    ans = 0;
}

var A = [];
var B = [];

for(var i = l; i<=r; i++)
{
    A.push(a[i]);
    B.push(b[i]);
}

A.sort();
B.sort();

r-=l;
for(var i = 0; i<=l; i++)
if(A[i]!=B[i])
{
    ans = 0;
}

if(ans !== 0)
{
    print("TRUTH");
}
else
{
    print("LIE");
}

var inp = readline().split(' ');
var a = readline().split(' ');
var b = readline().split(' ');
var ca = a.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));
var cb = b.slice(parseInt(inp[1]) - 1, parseInt(inp[2]));
ca.sort();
cb.sort();
var ans = true;
for (var i = 0; i < ca.length; i++) {
    if (ca[i] != cb[i])
        ans = false;
}
if (ans)
    print("TRUTH");
else
    print("LIE");

a = readline().split(' ');
n = a[0];
l = a[1];
r = a[2];
a = readline().split(' ');
b = readline().split(' ');
good = true;
for (i = 0; i < n; ++i)
  if (a[i] != b[i] && !(i >= l - 1 && i <= r - 1)) {
    print(i);
    good = false;
  }
if (good)
  print('TRUTH');
else
  print('LIE');

a = readline().split(' ');
n = a[0];
l = a[1];
r = a[2];
a = readline().split(' ');
b = readline().split(' ');
good = true;
for (i = 0; i < n; ++i)
  if (a[i] != b[i] && i >= l - 1 && i <= r - 1)
    good = false;
if (good)
  print('TRUTH');
else
  print('LIE');

a = readline().split(' ');
n = a[0];
l = a[1];
r = a[2];
a = readline().split(' ');
b = readline().split(' ');
good = true;
for (i = 0; i < n; ++i)
  if (a[i] != b[i] && i >= l - 1 && i < r)
    good = false;
if (good)
  print('TRUTH');
else
  print('LIE');

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     // '4 2 4',
//     // '1 1 1 1',
//     // '1 1 1 1'
//     // '10 3 7',
//     // '678 45 78 11 90 98 99999 21 89 9',
//     // '678 45 99999 90 11 89 98 78 21  9',
//     '5 3 5',
//     '6 7 9 0 1',
//     '7 6 9 0 1'
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourceBefore = source.slice(0, l);
var destBefore = dest.slice(0, l);

var sourceAfter = source.slice(l + r + 1, source.length);
var destAfter = dest.slice(l + r + 1, source.length);

var sourcePart = source.slice(l, l + r + 1);
var destPart = dest.slice(l, l + r + 1);
sourcePart.sort();
destPart.sort();

var truth = true;

for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        print('LIE');
        truth = false;
        break;
    }
}

if (truth) {
    for (var i = 0; i < sourceBefore.length; i++) {
        if (sourceBefore[i] !== destBefore[i]) {
            print('LIE');
            truth = false;
            break;
        }
    }

    if (truth) {
        for (var i = 0; i < sourceAfter.length; i++) {
            if (sourceAfter[i] !== destAfter[i]) {
                print('LIE');
                truth = false;
                break;
            }
        }
    }
}

if (truth) {
    print('TRUTH');
}

var input = readline().split(' ');
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ');
var dest = readline().split(' ');

var sourcePart = source.slice(l, l + r);
var destPart = dest.slice(l, l + r);
destPart.sort();

var truth = true;
for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        truth = false;
        break;
    }
}

if (truth) {
    print('TRUTH');
} else {
    print('LIE');
}

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourcePart = source.slice(l, l + r);
var destPart = dest.slice(l, l + r);
destPart.sort();

var truth = true;
for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        truth = false;
        break;
    }
}

if (truth) {
    print('TRUTH');
} else {
    print('LIE');
}

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     '4 2 4',
//     '1 1 1 1',
//     '1 1 1 1'
//     // '10 3 7',
//     // '678 45 78 11 90 98 99999 21 89 9',
//     // '678 45 99999 90 11 89 98 78 21  9',
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourcePart = source.slice(l, l + r);
var destPart = dest.slice(l, l + r);
sourcePart.sort();
destPart.sort();

source.sort();
dest.sort();

var truth = true;

for (var i = 0; i < source.length; i++) {
    if (source[i] !== dest[i]) {
        truth = false;
        break;
    }
}

if (truth) {
    for (var i = 0; i < sourcePart.length; i++) {
        if (sourcePart[i] !== destPart[i]) {
            truth = false;
            break;
        }
    }
}

if (truth) {
    print('TRUTH');
} else {
    print('LIE');
}

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     // '4 2 4',
//     // '1 1 1 1',
//     // '1 1 1 1'
//     // '10 3 7',
//     // '678 45 78 11 90 98 99999 21 89 9',
//     // '678 45 99999 90 11 89 98 78 21  9',
//     '6 3 5',
//     '6 7 9 0 1 8',
//     '6 7 0 0 1 8'
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourceBefore = source.slice(0, l);
var destBefore = dest.slice(0, l);

var sourceAfter = source.slice(l + r - 1, source.length);
var destAfter = dest.slice(l + r - 1, source.length);

var sourcePart = source.slice(l, l + r - 1);
var destPart = dest.slice(l, l + r - 1);
sourcePart.sort();
destPart.sort();

var truth = true;

for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        print('LIE');
        truth = false;
        break;
    }
}

if (truth) {
    for (var i = 0; i < sourceBefore.length; i++) {
        if (sourceBefore[i] !== destBefore[i]) {
            print('LIE');
            truth = false;
            break;
        }
    }

    if (truth) {
        for (var i = 0; i < sourceAfter.length; i++) {
            if (sourceAfter[i] !== destAfter[i]) {
                print('LIE');
                truth = false;
                break;
            }
        }
    }
}

if (truth) {
    print('TRUTH');
}

// var inputValues = [
//     // '5 2 4',
//     // '3 4 2 3 1',
//     // '3 2 3 4 1',

//     // '3 1 2',
//     // '1 2 3',
//     // '3 1 2',

//     '4 2 4',
//     '1 1 1 1',
//     '1 1 1 1'
// ]

// var inputIndex = 0;

// function readline() {
//     inputIndex++;
//     return inputValues[inputIndex - 1];
// }

// function print(s) {
//     console.log(s);
// }

var input = readline().split(' ').map(function(x) { return parseInt(x); });;
var n = input[0];
var l = input[1] - 1;
var r = input[2] - 1;

var source = readline().split(' ').map(function(x) { return parseInt(x); });;
var dest = readline().split(' ').map(function(x) { return parseInt(x); });;

var sourcePart = source.slice(l, l + r);
var destPart = dest.slice(l, l + r);
sourcePart.sort();
destPart.sort();

var truth = true;
for (var i = 0; i < sourcePart.length; i++) {
    if (sourcePart[i] !== destPart[i]) {
        truth = false;
        break;
    }
}

if (truth) {
    print('TRUTH');
} else {
    print('LIE');
}

var S = readline().split(" ").map(function(x) { return parseInt(x); });
n = S[0]; l = S[1]; r = S[2];
var A = readline().split(" ").map(function(x) { return parseInt(x); });
var B = readline().split(" ").map(function(x) { return parseInt(x); });
l--;
A = A.slice(l, r);
B = B.slice(l, r);
A.sort();
B.sort();
if(JSON.stringify(A) == JSON.stringify(B)){
	print("TRUTH");
}else{
	print("LIE");
}

var S = readline().split(" ").map(function(x) { return parseInt(x); });
n = S[0]; l = S[1]; r = S[2];
var A = readline().split(" ").map(function(x) { return parseInt(x); });
var B = readline().split(" ").map(function(x) { return parseInt(x); });
l--;
A = A.slice(l, r);
B = B.slice(l, r);
A.sort();
B.sort();
if(JSON.stringify(A) == JSON.stringify(B)){
	var ok = true;
	for(i = 0; i < l && ok; i++){
		if(A[i] != B[i]) ok = false;
	}
	for(i = r; i < n && ok; i++){
		if(A[i] != B[i]) ok = false;
	}
	if(ok) print("TRUTH");
	else print("LIE");
}else{
	print("LIE");
}

"use strict";
if (typeof readline == 'undefined') {
    let id = 0, lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var readline = () => lines[id++];
    var print = console.log;
}
let nums = () => readline().split(' ').map(x => +x);
let t = nums(), n = t[0], l = --t[1], r = --t[2];
let a = nums();
let b = nums();

let c = Array(n).fill(0);
for (let i = l; i <= r; ++i) {
    ++c[a[i] - 1];
    --c[b[i] - 1];
}

let ans = c.every(x => x === 0);

if (ans) print("TRUTH");
else print("LIE");

var n, l, r;
var A, B;
var hash = {};
var arr, i, ans = 'TRUTH';
arr = readline().split(' ');
arr = arr.map((s) => parseInt(s));
n = arr[0];
l = arr[1] - 1;
r = arr[2] - 1;
arr = readline().split(' ');
A = arr.map((s) => parseInt(s));
for (i = l; i <= r; i ++) {
    if (!hash[A[i]])
        hash[A[i]] = 1;
    else
        hash[A[i]] ++;
}
arr = readline().split(' ');
B = arr.map((s) => parseInt(s));
for (i = l; i <= r; i ++) {
    if (!hash[B[i]]) {
        ans = 'LIE';
        break;
    } else {
        hash[B[i]] --;
    }
}
print(ans);

var n, l, r;
var A, B;
var hash = {};
var arr, i, ans = 'TRUTH';
arr = readline().split(' ');
arr = arr.map((s) => parseInt(s));
n = arr[0];
l = arr[1] - 1;
r = arr[2] - 1;
arr = readline().split(' ');
A = arr.map((s) => parseInt(s));
for (i = l; i <= r; i ++) {
    if (!hash[A[i]])
        hash[A[i]] = 1;
    else
        hash[A[i]] ++;
}
arr = readline().split(' ');
B = arr.map((s) => parseInt(s));
for (i = l; i <= r; i ++) {
    if (!hash[B[i]] || hash[B[i]] === 0) {
        ans = 'LIE';
        break;
    } else {
        hash[B[i]] --;
    }
}
print(ans);


There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.

NoteIn the first sample, the optimal order is: 10, 20, 30, 40, 50.In the second sample, the optimal order is: 100, 200, 100, 200.

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

var group = function(a) {
    var excess = [];
    var distinct = a.reduce(function(result, item) {
        if (result.indexOf(item) == -1) {
            result.push(item);
        } else {
            excess.push(item);
        }
        return result;
    }, []);

    return [distinct, excess];
};

var result = 0;
var dirty = n.splice(0);
do {
    var grouped = group(dirty);
    result += grouped[0].length - 1;
    dirty = grouped[1];
} while (dirty.length != 0)

print(result);

var n = Number(readline());
var arr = readline().split(" ", n).map(Number);

var num = [], maxNum = 0;
for (var i = 0; i < n; ++i) {
    if (!num[arr[i]]) {
        num[arr[i]] = 0;
    }
    ++num[arr[i]];
    maxNum = Math.max(maxNum, num[arr[i]]);
}

print(n - maxNum);

var n = readline(), beaut = readline().split(" "), h = [], max = 0;
for (var i = 0; i < n; i++) {
    if (!h[beaut[i]])
        h[beaut[i]] = 0;
    h[beaut[i]]++;
    max = Math.max(max, h[beaut[i]]);
}
print(n - max);

function rda(){ return readline().split(" ").map(Number); }
function rdn(){ return Number(readline()); }

var n = rdn(), a = rda();
a.sort(function(x, y){ return x-y; });

var max = 1;
var cur = 1;
for(var i = 0; i < n-1; i++){
    if(a[i] == a[i+1]){
        cur++;
        max = Math.max(max, cur);
    }else{
        cur = 1;
    }
}

var ans = n - max;
write(ans);

var n = Number(readline());
var paintings = readline().split(' ').map(Number);

/* Without the function, the default sort would convert to string and mess up */
paintings.sort(function(a, b) {
	return a - b;
});

/* I want to split paintings into increasing miniarrays */
var max_chunk = 1;
var curr_chunk = 1;

for (var i = 0; i < n; i++) {
	if (paintings[i] == paintings[i + 1]) {
		curr_chunk += 1;
		if (curr_chunk >= max_chunk) {
			max_chunk = curr_chunk;
		}
	} else {
		curr_chunk = 1;
	}
}

var happy = n - max_chunk;

print(happy);

/** B. Beautiful Paintings

There are n pictures delivered for the new exhibition. The i-th painting has
beauty ai. We know that a visitor becomes happy every time he passes from a
painting to a more beautiful one.

We are allowed to arranged pictures in any order. What is the maximum possible
number of times the visitor may become happy while passing all pictures from
first to last? In other words, we are allowed to rearrange elements of a in
any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1),
such that ai + 1 > ai.

Input
The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of
painting.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where
ai means the beauty of the i-th painting.

Output
Print one integer — the maximum possible number of neighbouring pairs, such
that ai + 1 > ai, after the optimal rearrangement.

5
20 30 10 50 40
> 4

4
200 100 100 200
> 2

6
10 10 10 20 30 40
> 3
(via 10 20 30 40 10 10 or 10 20 10 30 10 40)

 */

var countHappiness = function(numPaintings, paintingStats) {
    /**
    e.g.
    numPaintings = 7;
    paintingStats = [10, 10, 10, 20, 30, 40, 40];
    --
    numPaintingsWithEachStat = [
        10: 3,
        20: 1,
        30: 1,
        40: 2,
    ];
    --
    happinessAtThisCount = [
        1: true,
        2: true,
        3: true,
    ];
    --
    */
    var happiness = 0;
    if (numPaintings === 0 || numPaintings === 1) {
        print(happiness);
        return;
    }

    var numPaintingsWithEachStat = [];

    for (var i = 0; i < numPaintings; i++) {
        var paintingStat = paintingStats[i];
        if (numPaintingsWithEachStat[paintingStat] == null) {
            numPaintingsWithEachStat[paintingStat] = 0;
        }
        numPaintingsWithEachStat[paintingStat]++;
    }

    var happinessAtThisCount = [];
    for (var i = 0; i < numPaintingsWithEachStat.length; i++) {
        if (numPaintingsWithEachStat[i] != null) {
            for (var j = numPaintingsWithEachStat[i]; j > 0; j--) {
                if (happinessAtThisCount[j] != null) {
                    happiness++;
                }
                happinessAtThisCount[j] = true;
            }
        }
    }
    print(happiness);
}

var numPaintings = readline().split(' ');
var paintingStats = readline().split(' ');
countHappiness(numPaintings, paintingStats)

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

var n, array, count = [], prev, answer = 0;
n = Number(readline());
array = readline().split(' ').map(Number).sort();
function check (value) {
    return value > 0;
}

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

    if (array[i] != prev) {
        count.push(1);
    } else {
        count[count.length - 1]++;
    }
    prev = array[i];
}

while (count.length > 1) {

    answer += count.length - 1;
    count = count.map(x => x - 1);
    count = count.filter(check);
}

print(answer);

/* TEST CASE
input
5
20 30 10 50 40
output
4
input
4
200 100 100 200
output
2

*/
function main() {
	var n = parseInt(readline());
	var splitted = readline().split(' ');
	var a = new Array(n);
	var i, j;
	for (i = 0; i < n; i++) {
		a[i] = parseInt(splitted[i]);
	}
	a.sort(function(v1, v2) {return v1 - v2});

	for (i = 0; i < n - 1; i++) {
		j = i + 1;
		while (j < n && a[j] == a[i]) {
			j++;
		}

		if (j > i + 1 && j < n) {
			var temp = a[j];
			a[j] = a[i + 1]
			a[i + 1] = temp;
			i++;
		}
	}

	var answer = 0;

	for (i = 1; i < n; i++) {
		if (a[i - 1] < a[i]) {
			answer++;
		}
	}

	print(answer);
}

main();

/* TEST CASE
input
5
20 30 10 50 40
output
4
input
4
200 100 100 200
output
2

*/
function main() {
	var n = parseInt(readline());
	var last = n - 1;
	var a = new Array(n);
	var i, j;
	var splitted = readline().split(' ');

	for (i = 0; i < n; i++) {
		a[i] = parseInt(splitted[i]);
	}

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

	for (i = 0; i < last; i++) {
		j = i + 1;
		while (j < n && a[j] == a[i]) {
			j++;
		}

		if (j > i + 1 && j < last) {
			i++;
			var temp = a[j];
			a[j] = a[i]
			a[i] = temp;
		}
	}

	var answer = 0;

	for (i = 0; i < last; i++) {
		if (a[i + 1] > a[i]) {
			answer++;
		}
	}

	print(answer);
}

main();

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

var filtered = n.reduce(function(result, item) {
    if (!result) {result=[]}
    if (result.indexOf(item) == -1) {
        result.push(item);
    }
    return result;
}, []);

print(filtered.length - 1);

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

var filtered = n.reduce(function(result, item) {
    if (!result) {result=[]}
    if (result.indexOf(item) == -1) {
        result.push(item);
    }
    return result;
}, []);

print(filtered.length);


To become the king of Codeforces, Kuroni has to solve the following problem.He is given $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. Help Kuroni to calculate $$$\prod_{1\le i<j\le n} |a_i - a_j|$$$. As result can be very big, output it modulo $$$m$$$.If you are not familiar with short notation, $$$\prod_{1\le i<j\le n} |a_i - a_j|$$$ is equal to $$$|a_1 - a_2|\cdot|a_1 - a_3|\cdot$$$ $$$\dots$$$ $$$\cdot|a_1 - a_n|\cdot|a_2 - a_3|\cdot|a_2 - a_4|\cdot$$$ $$$\dots$$$ $$$\cdot|a_2 - a_n| \cdot$$$ $$$\dots$$$ $$$\cdot |a_{n-1} - a_n|$$$. In other words, this is the product of $$$|a_i - a_j|$$$ for all $$$1\le i < j \le n$$$.

The first line contains two integers $$$n$$$, $$$m$$$ ($$$2\le n \le 2\cdot 10^5$$$, $$$1\le m \le 1000$$$) — number of numbers and modulo. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$).

Output the single number — $$$\prod_{1\le i<j\le n} |a_i - a_j| \bmod m$$$.

NoteIn the first sample, $$$|8 - 5| = 3 \equiv 3 \bmod 10$$$.In the second sample, $$$|1 - 4|\cdot|1 - 5|\cdot|4 - 5| = 3\cdot 4 \cdot 1 = 12 \equiv 0 \bmod 12$$$.In the third sample, $$$|1 - 4|\cdot|1 - 9|\cdot|4 - 9| = 3 \cdot 8 \cdot 5 = 120 \equiv 1 \bmod 7$$$.

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])
    prod %= sizes[1]
    }
    stop += 1
}
print(prod)
}

'use strict'

const problem = (n, m, a) => {
    if (n > m) return 0;
    let r = 1;

    for (let i = 0; i < n - 1; i++)
        for (let j = i + 1; j < n; j++)
            r = (r * (a[j] -= a[i])) % m;

    return Math.abs(r);
}

const nm = readline().split(' ').map(i => +i);
const n = nm[0], m = nm[1];

print(problem(n, m, readline().split(' ').map(i => +i)))

var input = readline().split(' ');
var n = input[0];
var m = input[1];
var arr = readline().split(' ');
var result = 1;
var printed = false;
var possibleRemainders = {};

for (var i=0; i<n; i++) {
    var remainder = arr[i]%m;
    if (possibleRemainders[remainder]) {
        printed = true;
        print('0');
        break;
    }
    possibleRemainders[remainder] = true;
}

if (!printed) {
    for (var i=0; i<n-1; i++) {
        for (var j=i+1; j<n; j++) {
            var diff = Math.abs(arr[i] - arr[j]) % m;
            result = (result * diff) % m;
        }
    }
    print(result);
}

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

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

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

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

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

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

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

function main(input) {
  const [n, m] = readInts(input, 0)
  const ai = readInts(input, 1)
  if(n > m) wr(0)
  else {
    let p = 1
    sort(ai, false)
    for(let i = 0; i < n - 1; i ++) {
      for(let j = i + 1; j < n; j ++) {
        p *= ((ai[i] - ai[j]) % m)
        p = p % m
      }
    }
    wr(p % m)
  }
}

function processData(input) {
  const verbose = 0
input = input.split("\n")
const [n, mod] = input[0].split(" ").map(e => Number(e))
const arr = input[1].split(" ").map(e => Number(e))
var res = 1
if(n > mod)
    console.log(0)
else{
    for(let i = 0; i < n-1; i++){
        for(let j = i+1; j < n; j++){
            res = (res*Math.abs(arr[i]-arr[j]))%mod
        }
    }
    res = res%mod
    console.log(res)
}
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});

process.stdin.on("end", function () {
processData(_input);
});

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])
    prod %= sizes[1]
    }
    stop += 1
}
}
print(prod)

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])%sizes[1]
    }
    stop += 1
}
}
print(prod)

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])
    }
    stop += 1
}
}
print(prod%sizes[1])

var sizes = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var a = readline().split(' ').map((val)=>{
    return parseInt(val)
    })
var prod = 1,stop = 0
if (sizes[0] > sizes[1]){
    print(0)
}
else {
while (stop < sizes[0]){
    for(var k = stop+1; k < sizes[0];k++){
    prod *= Math.abs(a[stop]-a[k])
    }
    stop += 1
}
}
print (stop%sizes[1])

'use strict'

const problem = (n, m, a) => {
    if (n >= m) return 0;

    a = a.map(i => +i % m)
    let p = new Array(m); p[0] = true;
    for (let i = 0; i < n; i++) {
        const x = a[i];
        if (p[x]) return 0;
        p[x] = x;
    }
    a = p.filter(Boolean).slice(1);
    let r = 1;
    for (let i = 0; i < n - 1; i++) {
        const x = a[i];
        for (let j = i + 1; j < n; j++) r = (r * (a[j] = a[j] - x)) % m;
    }
    return r;
}

const nm = readline().split(' ').map(i => +i);
const n = nm[0], m = nm[1];
print(problem(n, m, readline().split(' ')))

var input = readline().split(' ');
var n = input[0];
var m = input[1];
var arr = readline().split(' ');
var result = 1;
var printed = false;
for (var i=0; i<n-1; i++) {
    for (var j=i+1; j<n; j++) {
        var diff = Math.abs(arr[i] - arr[j]) % m;
        result = (result * diff) % m;
        if (result === 0) {
            print(result);
            printed = true;
        }
    }
}
if (!printed) {
    print(result);
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", inputStdin => {
  inputString += inputStdin;
});
process.stdin.on("end", _ => {
  inputString = inputString
    .trim()
    .split("\n")
    .map(string => {
      return string.trim();
    });
  main();
});
function readline() {
  return inputString[currentLine++];
}
function main(){
    const [n, mod] = readline().split(" ").map(e => Number(e))
    const arr = readline().split(" ").map(e => Number(e))
    var stack = []
    for(let i = 0; i < n-1; i++){
        for(let j = i+1; j < n; j++){
            stack.push(Math.abs(arr[i]-arr[j]))
        }
    }
    var res = 1
    for(let i = 0; i < stack.length; i++){
        res *= stack[i]
    }
    res = res%mod
    console.log(res)
}

function processData(input) {
  input = input.split("\n")
  const [n, mod] = input[0].split(" ").map(e => Number(e))
  const arr = input[1].split(" ").map(e => Number(e))
  var res = 1
  if(n > mod)
      console.log(0)
  else{
      for(let i = 0; i < n-1; i++){
          for(let j = i+1; j < n; j++){
              res = res*(Math.abs(arr[i]-arr[j])%mod)
          }
      }
      res = res%mod
      console.log(res)
  }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
  _input += input;
});

process.stdin.on("end", function () {
 processData(_input);
});


As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1 ≤ fi ≤ n and fi ≠ i.We call a love triangle a situation in which plane A likes plane B, plane B likes plane C and plane C likes plane A. Find out if there is any love triangle on Earth.

The first line contains a single integer n (2 ≤ n ≤ 5000) — the number of planes. The second line contains n integers f1, f2, ..., fn (1 ≤ fi ≤ n, fi ≠ i), meaning that the i-th plane likes the fi-th.

Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case.

NoteIn first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.In second example there are no love triangles.

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

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={}

	for(let i =0;i<arr.length;i++){
		obj[i+1] = arr[i];

	}

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			//console.log(obj[obj[obj[arr[i]]]]);
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	//console.log(obj);

}

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

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

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

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

//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 N = nextInt();
	var tmp = nextIntArray();
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		list[i] = {
			no : i,
			next : tmp[i] - 1
		};
	}
	var isOK = false;
	for(var i = 0; i < N; i++){
		var now = i;
		var count = 0;
		while(count < 3){
			now = list[now].next;
			if(now == i && count == 2){
				isOK = true;
			}
			count++;
		}
	}
	myout((isOK) ? "YES" : "NO");

}

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

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

  let ans = 'NO';
  const arr = d.split(' ').map(Number);

  for (let i = 0; i < arr.length; i++) {
    let idx = 0;
    let start = arr[i];
    let end = start;

    while (idx < 3) {
      end = arr[end - 1];
      idx++;
    }

    if (start === end) {
      ans = 'YES';
      break
    }
  }

  console.log(ans);

  c++;
});

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

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

  let ans = 'NO';
  // const arr = d.split(' ').map(Number);
  const arr = [0, ...d.split(' ').map(Number)];

  for (let i = 1; i < arr.length; i++) {
    if (arr[arr[arr[i]]] === i) {
      ans = 'YES';
      break;
    }
  }

  // for (let i = 0; i < arr.length; i++) {
  //   let idx = 0;
  //   let start = arr[i];
  //   let end = start;

  //   while (idx < 3) {
  //     end = arr[end - 1];
  //     idx++;
  //   }

  //   if (start === end) {
  //     ans = 'YES';
  //     break
  //   }
  // }

  console.log(ans);

  c++;
});

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

function main (lines) {
    let n=parseInt(lines[0]);
    let line=lines[1];
    line=line.split(' ');
    for (let i=0; i<n ; i++){
        if (i+1 === parseInt(line[parseInt(line[parseInt(line[i])-1])-1])){
            console.log('YES');
            return;
        }
    }
    console.log('NO');

}

let input = ''
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    const { EOL } = require('os');
    const lines = input.split(EOL);
    main(lines);
});

function main(lines) {
  const n = lines[0];
  const f = [0].concat(lines[1].split(' ').map(v => +v));
  const visited = new Set();

  for (let v = 1; v <= n; v++) {
    if (visit(f, v, visited, [])) {
      console.log("YES");
      return;
    }
  }
  console.log("NO");
}

function visit(f, v, visited, path) {
  if (visited.has(v)) {
    return false;
  }
  const next_v = f[v];
  const len = path.length;
  if (path[len - 2] === next_v) {
    return true;
  }

  visited.add(v);
  path.push(v);

  return visit(f, next_v, visited, path);
}

// main(['5', '2 4 5 1 3']);
// main(['5', '5 5 5 5 1']);

readline(); const ns = [0, ...readline().split(' ')]
print(ns.find((_,i) => (i !== 0) ? ns[ns[ns[i]]] == i : null) ? 'YES' : 'NO')

const s = readline(); const ns = [0, ...readline().split(' ')]
for (var i = 1; i <= s; i++)
if(ns[ns[ns[i]]] == i) break
print(i <= s ? 'YES' : 'NO')

var doesntExist = true;

var n = parseInt(readline());
var planes = readline().split(' ').map(function(x) {
    return parseInt(x);
});

for (var i = 0; i < n; i++) {
    firstPlanesLove = planes[i];
    secondPlanesLove = planes[firstPlanesLove - 1];

    thirdPlanesLove = planes[secondPlanesLove - 1];

    if (thirdPlanesLove === i + 1) {
        print('YES');
        doesntExist = false;
        break;
    }
}

if (doesntExist) {
    print('NO');
}

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

// const Graph = require('../libs/graph');
// const Queue = require('../libs/queue');

var n = parseInt(readline());
var ar = ('0 ' + readline()).split(' ').map(function (v) {
    return parseInt(v);
});

var answer = 'NO';
for (var i = 1; i <= n; i++) {
    var a = i;
    var b = ar[i];
    var c = ar[b];
    var d = ar[c];

    if (a === d) {
        answer = 'YES';
        break;
    }
}

write(answer);

},{}]},{},[1]);

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

var isTri = false;
var traverse = (i) => {
    return input[i - 1]
}
for (var i = 1; i <= n; i++) {
    if (traverse(traverse(traverse(i))) == i) {
        isTri = true;
        break;
    }

}

isTri ? print('YES') : print('NO');

//demo(5, '5 5 5 5 1')

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

var isTri = false;
var traverse = (i) => {
    return input[i - 1]
}
for (var i = 1; i <= n; i++) {
    var start = i;
    if (traverse(traverse(traverse(i))) == i) {
        isTri = true;
        break;
    }

}

isTri ? print('YES') : print('NO')

//demo(5, '5 5 5 5 1')

var n = Number(readline()),
array = readline().split(" ").map(x => Number(x)),
result = "NO";
for (var i = 0; i < array.length; i++) {
	if (i != array[array[i] - 1] - 1 && array[array[array[i] - 1] - 1] - 1 == i) {
		result = "YES";
		break;
	}
}
print(result);

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

for(var i = 0; i < a; i++){
	if(b[b[b[b[i]-1]-1]-1] === b[i]){
		if(b[b[b[i]-1]-1] !== b[i]){
			print("YES");
			break
		}
	} else if (i === b.length - 1){
		print('NO');
	}
}

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

var no = true;

for(var i = 0; i < fn.length; i++)
{
    fn[i] = int(fn[i]);
}

for(var i = 0; i < int(n); i++)
{
    var m = [];
    m.push(i+1);
    m.push(fn[i]);
    m.push(fn[fn[i]-1]);
    m.push(fn[fn[fn[i]-1]-1]);

    if(m[0] == m[3])
    {
        no = false;
        write("YES");
        break;
    }
}
if(no)
{
    write("NO");
}

function int(val)
{
    return parseInt(val);
}

	var nr = readline();
	var planes = readline().split(" ");
	var pivot;
    var pivotLoves;

    var res = "NO";

	for (var i = 0; i<nr; i++) {
       	pivot = i;
        pivotLoves = planes[i];
        if (planes[planes[pivotLoves-1]-1]-1 == pivot) {
        	res = "YES";
        }
    }
    print(res);

var planesAmount = parseInt(readline());
var planes = readline().split(' ');
var result = 'NO';
planes.some(function (plane, index) {
    if (planes[planes[plane - 1] - 1] - 1 === index) {
        result = 'YES';
        return true;
    }
});
print(result);

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

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={}

	for(let i =0;i<arr.length;i++){
		obj[i+1] = arr[i];

	}

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			console.log(obj[obj[obj[arr[i]]]]);
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	console.log(obj);

}

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

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

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

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

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

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={}

	for(let i =0;i<arr.length;i++){
		obj[i+1] = arr[i];

	}

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			//console.log(obj[obj[obj[arr[i]]]]);
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	console.log(obj);

}

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

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

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

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

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

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={};

	for(let i =0;i<arr.length;i++){
		obj[arr[i]] = i+1;
	}

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	console.log(obj);

}

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

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

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

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

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

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	let arr = inputReader.readNumberArray();
	let obj={};

	for(let i =0;i<arr.length;i++){
		obj[arr[i]] = i+1;
	}

	let flag = false;
	for(let i =0;i<arr.length;i++){
		if(obj[obj[obj[arr[i]]]]===arr[i]){
			flag=true;
			break;
		}
	}
	if(flag)
		console.log("YES");
	else
		console.log("NO");
	//console.log(obj);

}

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

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

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

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

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

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

  let ans = 'NO';
  const arr = d.split(' ').map(Number);

  for (let i = 0; i < arr.length; i++) {
    let idx = 0;
    let start = arr[i];
    let end = start;

    while (idx < 3) {
      end = arr[end];
      idx++;
    }

    if (start === end) {
      ans = 'YES';
      break
    }
  }

  console.log(ans);

  c++;
});

readline(); const ns = readline().split(' ')
print(ns.map(n => +n + 1).find((_,i) => ns[ns[ns[i]]] == i) ? 'YES' : 'NO')

readline(); const ns = [0, ...readline().split(' ')];
print(ns.find((_,i) => ns[ns[ns[i + 1]]] == i + 1) ? 'YES' : 'NO')

readline(); const ns = readline().split(' ')
print(ns.map(n => n - 1).find((_,i) => ns[ns[ns[i]]] == i) ? 'YES' : 'NO')

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

readline(); const ns = readline().split(' ')
print(ns.find((_,i) => ns[ns[ns[i]]] == i) ? 'YES' : 'NO')

readline(); const ns = [0, ...readline().split(' ')];
print(ns.find((_,i) => ns[ns[ns[i - 1]]] == i - 1) ? 'YES' : 'NO')

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

// const Graph = require('../libs/graph');
// const Queue = require('../libs/queue');

var n = parseInt(readline());
var ar = readline().split(' ').map(function (v) {
    return parseInt(v);
});

var answer = 'NO';
for (var i = 0; i < n; i++) {
    if (i = ar[ar[i]]) {
        answer = 'YES';
        break;
    }
}

write(answer);

},{}]},{},[1]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

// const Graph = require('../libs/graph');
// const Queue = require('../libs/queue');

var n = parseInt(readline());
var ar = ('0' + readline()).split(' ').map(function (v) {
    return parseInt(v);
});

var answer = 'NO';
for (var i = 1; i <= n; i++) {
    if (i = ar[ar[ar[i]]]) {
        answer = 'YES';
        break;
    }
}

write(answer);

},{}]},{},[1]);

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

// const Graph = require('../libs/graph');
// const Queue = require('../libs/queue');

var n = parseInt(readline());
var ar = ('0' + readline()).split(' ').map(function (v) {
    return parseInt(v);
});

var answer = 'NO';
for (var i = 1; i <= n; i++) {
    if (i = ar[ar[i]]) {
        answer = 'YES';
        break;
    }
}

write(answer);

},{}]},{},[1]);

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

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

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

for(var i = 0; i < a; i++){
	if(b[b[b[i]-1]-1] === b[i]){
		print('YES');
		break
	} else if (i === b.length - 1){
		print('NO');
	}
}

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

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

var a = Number(readline());
var b = readline().split(' ').map(e=>Number(e));

for(var i = 0; i < a; i++){
	if(b[b[b[i]-1]-1] === b[i]){
		if(!(b[b[i]-1] === b[i])){
			print("YES");
			break
		}
	} else if (i === b.length - 1){
		print('NO');
	}
}

	var nr = readline();
	var planes = readline().split(" ");
	var pivot;
    var pivotLoves;
    var loved;

    var res = "NO";

	for (var i = 1; i<=nr; i++) {
       	pivot = i;
        pivotLoves = planes[i];
        if (planes[planes[pivotLoves]] == pivot) {
        	res = "YES";
        }
    }
    print(res);


You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. You can perform operations on it.In one operation you can replace any element of the array $$$a_i$$$ with $$$\lfloor \frac{a_i}{2} \rfloor$$$, that is, by an integer part of dividing $$$a_i$$$ by $$$2$$$ (rounding down).See if you can apply the operation some number of times (possible $$$0$$$) to make the array $$$a$$$ become a permutation of numbers from $$$1$$$ to $$$n$$$ —that is, so that it contains all numbers from $$$1$$$ to $$$n$$$, each exactly once.For example, if $$$a = [1, 8, 25, 2]$$$, $$$n = 4$$$, then the answer is yes. You could do the following:  Replace $$$8$$$ with $$$\lfloor \frac{8}{2} \rfloor = 4$$$, then $$$a = [1, 4, 25, 2]$$$.  Replace $$$25$$$ with $$$\lfloor \frac{25}{2} \rfloor = 12$$$, then $$$a = [1, 4, 12, 2]$$$.  Replace $$$12$$$ with $$$\lfloor \frac{12}{2} \rfloor = 6$$$, then $$$a = [1, 4, 6, 2]$$$.  Replace $$$6$$$ with $$$\lfloor \frac{6}{2} \rfloor = 3$$$, then $$$a = [1, 4, 3, 2]$$$.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases. Each test case contains exactly two lines. The first one contains an integer $$$n$$$ ($$$1 \le n \le 50$$$), the second one contains integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).

For each test case, output on a separate line:   YES if you can make the array $$$a$$$ become a permutation of numbers from $$$1$$$ to $$$n$$$,  NO otherwise.  You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

NoteThe first test case is explained in the text of the problem statement.In the second test case, it is not possible to get a permutation.

/*
===== READ INPUT DATA START =====
=================================
*/

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

let inputString = '';

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

process.stdin.on('end', (_) => {
  const lines = inputString.trim().split('\n').map((string) => string.trim()).filter(Boolean);
  main(lines);
});

/*
===== READ INPUT DATA END =====
===============================
*/

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let N,
    arr;

  while (T--) {
    N = Number(lines[index++]);
    arr = lines[index++].split(' ').map(Number);

    solve(N, arr);
  }
}

function solve(N, input) {
  const arr = input.slice();
  const seen = new Set();

  for (let i = 0; i < N; ++i) {
    while (arr[i]) {
      if (arr[i] <= N && !seen.has(arr[i])) {
        seen.add(arr[i]);
        break;
      }

      arr[i] = Math.floor(arr[i] / 2);
    }
  }

  for (let i = 1; i <= N; ++i) {
    if (!seen.has(i)) {
      console.log('NO');
      return;
    }
  }

  console.log('YES');
}

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

    let j = 2;
    for (let i = 0; i < lines[0]; ++i) {
        const arr = lines[j].split(' ').map((el) => +el);

        const n = arr.length;

        let copy = new Array(n);

        for (let i = 0; i < n; ++i) {
            copy[i] = [];
            while (arr[i] > 0) {
                if (arr[i] <= n) {
                    copy[i].push(arr[i]);
                }
                arr[i] = Math.floor(arr[i] / 2);
            }
        }

        let found = false;

        const visited = new Set();

        const dp = (pos, set, str) => {
            if (pos === n || found) {
                if (set.size === n) {
                    found = true;
                }
                return;
            }
            for (let i = 0; i < copy[pos].length; ++i) {
                if (!set.has(copy[pos][i]) && !visited.has(str)) {
                    set.add(copy[pos][i]);
                    visited.add(str);
                    dp(pos + 1, set, str + copy[pos][i]);
                    set.delete(copy[pos][i]);
                }
            }
        }

        dp(0, new Set(), '');

        console.log(found ? 'YES' : 'NO');

        j += 2;
    }
});

const readline = require('readline')
// Generated by CoffeeScript 1.8.0
;(function() {
  var Heap, defaultCmp, floor, heapify, heappop, heappush, heappushpop, heapreplace, insort, min, nlargest, nsmallest, updateItem, _siftdown, _siftup;

  floor = Math.floor, min = Math.min;

  /*
  Default comparison function to be used
   */

  defaultCmp = function(x, y) {
    if (x < y) {
      return -1;
    }
    if (x > y) {
      return 1;
    }
    return 0;
  };

  /*
  Insert item x in list a, and keep it sorted assuming a is sorted.

  If x is already in a, insert it to the right of the rightmost x.

  Optional args lo (default 0) and hi (default a.length) bound the slice
  of a to be searched.
   */

  insort = function(a, x, lo, hi, cmp) {
    var mid;
    if (lo == null) {
      lo = 0;
    }
    if (cmp == null) {
      cmp = defaultCmp;
    }
    if (lo < 0) {
      throw new Error('lo must be non-negative');
    }
    if (hi == null) {
      hi = a.length;
    }
    while (lo < hi) {
      mid = floor((lo + hi) / 2);
      if (cmp(x, a[mid]) < 0) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    return ([].splice.apply(a, [lo, lo - lo].concat(x)), x);
  };

  /*
  Push item onto heap, maintaining the heap invariant.
   */

  heappush = function(array, item, cmp) {
    if (cmp == null) {
      cmp = defaultCmp;
    }
    array.push(item);
    return _siftdown(array, 0, array.length - 1, cmp);
  };

  /*
  Pop the smallest item off the heap, maintaining the heap invariant.
   */

  heappop = function(array, cmp) {
    var lastelt, returnitem;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    lastelt = array.pop();
    if (array.length) {
      returnitem = array[0];
      array[0] = lastelt;
      _siftup(array, 0, cmp);
    } else {
      returnitem = lastelt;
    }
    return returnitem;
  };

  /*
  Pop and return the current smallest value, and add the new item.

  This is more efficient than heappop() followed by heappush(), and can be
  more appropriate when using a fixed size heap. Note that the value
  returned may be larger than item! That constrains reasonable use of
  this routine unless written as part of a conditional replacement:
      if item > array[0]
        item = heapreplace(array, item)
   */

  heapreplace = function(array, item, cmp) {
    var returnitem;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    returnitem = array[0];
    array[0] = item;
    _siftup(array, 0, cmp);
    return returnitem;
  };

  /*
  Fast version of a heappush followed by a heappop.
   */

  heappushpop = function(array, item, cmp) {
    var _ref;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    if (array.length && cmp(array[0], item) < 0) {
      _ref = [array[0], item], item = _ref[0], array[0] = _ref[1];
      _siftup(array, 0, cmp);
    }
    return item;
  };

  /*
  Transform list into a heap, in-place, in O(array.length) time.
   */

  heapify = function(array, cmp) {
    var i, _i, _j, _len, _ref, _ref1, _results, _results1;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    _ref1 = (function() {
      _results1 = [];
      for (var _j = 0, _ref = floor(array.length / 2); 0 <= _ref ? _j < _ref : _j > _ref; 0 <= _ref ? _j++ : _j--){ _results1.push(_j); }
      return _results1;
    }).apply(this).reverse();
    _results = [];
    for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
      i = _ref1[_i];
      _results.push(_siftup(array, i, cmp));
    }
    return _results;
  };

  /*
  Update the position of the given item in the heap.
  This function should be called every time the item is being modified.
   */

  updateItem = function(array, item, cmp) {
    var pos;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    pos = array.indexOf(item);
    if (pos === -1) {
      return;
    }
    _siftdown(array, 0, pos, cmp);
    return _siftup(array, pos, cmp);
  };

  /*
  Find the n largest elements in a dataset.
   */

  nlargest = function(array, n, cmp) {
    var elem, result, _i, _len, _ref;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    result = array.slice(0, n);
    if (!result.length) {
      return result;
    }
    heapify(result, cmp);
    _ref = array.slice(n);
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      elem = _ref[_i];
      heappushpop(result, elem, cmp);
    }
    return result.sort(cmp).reverse();
  };

  /*
  Find the n smallest elements in a dataset.
   */

  nsmallest = function(array, n, cmp) {
    var elem, i, los, result, _i, _j, _len, _ref, _ref1, _results;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    if (n * 10 <= array.length) {
      result = array.slice(0, n).sort(cmp);
      if (!result.length) {
        return result;
      }
      los = result[result.length - 1];
      _ref = array.slice(n);
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        elem = _ref[_i];
        if (cmp(elem, los) < 0) {
          insort(result, elem, 0, null, cmp);
          result.pop();
          los = result[result.length - 1];
        }
      }
      return result;
    }
    heapify(array, cmp);
    _results = [];
    for (i = _j = 0, _ref1 = min(n, array.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
      _results.push(heappop(array, cmp));
    }
    return _results;
  };

  _siftdown = function(array, startpos, pos, cmp) {
    var newitem, parent, parentpos;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    newitem = array[pos];
    while (pos > startpos) {
      parentpos = (pos - 1) >> 1;
      parent = array[parentpos];
      if (cmp(newitem, parent) < 0) {
        array[pos] = parent;
        pos = parentpos;
        continue;
      }
      break;
    }
    return array[pos] = newitem;
  };

  _siftup = function(array, pos, cmp) {
    var childpos, endpos, newitem, rightpos, startpos;
    if (cmp == null) {
      cmp = defaultCmp;
    }
    endpos = array.length;
    startpos = pos;
    newitem = array[pos];
    childpos = 2 * pos + 1;
    while (childpos < endpos) {
      rightpos = childpos + 1;
      if (rightpos < endpos && !(cmp(array[childpos], array[rightpos]) < 0)) {
        childpos = rightpos;
      }
      array[pos] = array[childpos];
      pos = childpos;
      childpos = 2 * pos + 1;
    }
    array[pos] = newitem;
    return _siftdown(array, startpos, pos, cmp);
  };

  Heap = (function() {
    Heap.push = heappush;

    Heap.pop = heappop;

    Heap.replace = heapreplace;

    Heap.pushpop = heappushpop;

    Heap.heapify = heapify;

    Heap.updateItem = updateItem;

    Heap.nlargest = nlargest;

    Heap.nsmallest = nsmallest;

    function Heap(cmp) {
      this.cmp = cmp != null ? cmp : defaultCmp;
      this.nodes = [];
    }

    Heap.prototype.push = function(x) {
      return heappush(this.nodes, x, this.cmp);
    };

    Heap.prototype.pop = function() {
      return heappop(this.nodes, this.cmp);
    };

    Heap.prototype.peek = function() {
      return this.nodes[0];
    };

    Heap.prototype.contains = function(x) {
      return this.nodes.indexOf(x) !== -1;
    };

    Heap.prototype.replace = function(x) {
      return heapreplace(this.nodes, x, this.cmp);
    };

    Heap.prototype.pushpop = function(x) {
      return heappushpop(this.nodes, x, this.cmp);
    };

    Heap.prototype.heapify = function() {
      return heapify(this.nodes, this.cmp);
    };

    Heap.prototype.updateItem = function(x) {
      return updateItem(this.nodes, x, this.cmp);
    };

    Heap.prototype.clear = function() {
      return this.nodes = [];
    };

    Heap.prototype.empty = function() {
      return this.nodes.length === 0;
    };

    Heap.prototype.size = function() {
      return this.nodes.length;
    };

    Heap.prototype.clone = function() {
      var heap;
      heap = new Heap();
      heap.nodes = this.nodes.slice(0);
      return heap;
    };

    Heap.prototype.toArray = function() {
      return this.nodes.slice(0);
    };

    Heap.prototype.insert = Heap.prototype.push;

    Heap.prototype.top = Heap.prototype.peek;

    Heap.prototype.front = Heap.prototype.peek;

    Heap.prototype.has = Heap.prototype.contains;

    Heap.prototype.copy = Heap.prototype.clone;

    return Heap;

  })();

  (function(root, factory) {
    // if (typeof define === 'function' && define.amd) {
    //   return define([], factory);
    // } else if (typeof exports === 'object') {
    //   return module.exports = factory();
    // } else {
      return root.Heap = factory();
    // }
  })(this, function() {
    return Heap;
  });

}).call(this);
const Heap = this.Heap

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

function solve(n, arr) {
    // arr.sort((a, b) => b - a)
    const h = new Heap((a, b) => b - a)
    h.nodes = arr
    h.heapify()
    for (let i = n; i >= 1; i--) {
        if (!h.size()) return false
        let found = false
        while (h.size()) {
            let x = h.peek()
            if (x < i) break

            x = h.pop()
            let skip = false
            while (x >= i) {
                if (x === i && !found) {
                    found = true
                    skip = true
                }
                x = Math.floor(x / 2)
            }
            if (!skip) h.push(x)
        }
        // console.log(arr)
        if (!found) return false
    }
    return true
}

const solve = (n,arr)=>{
    let obj = {};
     for(let i=0;i<n;i++){
          let t = arr[i];
          while(t>n) t>>=1;
          if(obj[t]){
               if(t===1) return "NO";
               let k = t;
               let flag = 0;
               while(k>=1){
                    if(!obj[k]){
                         obj[k] = 1;
                         flag  = 1;
                         break;
                    }
                    k>>=1
               }
               if(flag===0) return "NO";
          }
          else obj[t] = 1;
     }
     return "YES";
}

function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(n,arr));
  }
}
main();

'use strict';

var readline = require('readline');

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

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

function solve(n, a) {
  let set = new Set(),
      st = [];
  for (let [i, num] of a.entries()) {
    if (num <= n && !set.has(num)) {
      st[i] = 1;
      set.add(num);
    }
  }
  let max = n.toString(2).length;
  next: for (let [i, num] of a.entries()) {
    if (st[i]) continue;
    const len = num.toString(2).length;
    for (let i = Math.min(max, len); i > 0; i--) {
      const num1 = num >> len - i;
      if (num1 > n) continue;
      if (!set.has(num1)) {
        set.add(num1);
        continue next;
      }
    }
    return 'NO';
  }
  return 'YES';
}

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

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

/* Common Template Starts */
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++];
}
/* Common Template Ends */

function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        const n = +(readline());
        const arr = readline().split(' ');
        divisionBy2(arr)
    }
}
const divisionBy2= (arr)=>{

    let arrNum = arr.map(el=>parseInt(el));
    let n = arrNum.length;
    let set = new Set();

    for(let i =0; i<arrNum.length; ++i){
        let num = arrNum[i];

        while(num){
            if(num <= n){
                if(!set.has(num)){
                    set.add(num);
                    break;
                }
            }
            num = Math.floor(num/2);
        }

    }

    if(set.size == n){
        console.log("YES");
    }
    else{
        console.log("NO");
    }
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();
		a.sort((x, y) => y - x);

		function canreduce (a, n) {
			while (n > a) {
				n = n >> 1;
			}
			return a == n;
		}

		let ok = true;
		for (let i = n; ok && i >= 1; i--) {
			ok = false;
			for (let j = 0; !ok && j < n; j++) {
				if (canreduce(i, a[j])) {
					ok = true;
					a[j] = 0;
				}
			}
		}

		console.log(ok ? 'YES' : 'NO');
	}
}

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

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

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

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

let solve = async () => {
    const tsc = await readInt();
    const can_num = (n, mask) => {
        while (n > mask) {
           n = n >> 1;
        }
        return n === mask;
    }

    for(let sc = 0; sc < tsc; sc++) {
        const n = await readInt();
        const a = await readIntArray();
        let can = true;
        for(let i = n; i >= 1; i--) {
            let fnd = false;
            for(let j = 0; j < n; j++)
                if (a[j] !== 0 && can_num(a[j], i)) {
                    a[j] = 0;
                    fnd = true;
                    break;
                }
            if (!fnd) {
                can = false;
                break;
            }
        }
        if (can)
            console.log("YES");
        else
            console.log("NO");
    }
}

solve();

var t = parseInt(readline());

  function solve() {
    var n = parseInt(readline());
    var inp = readline()
      .split(" ")
      .map((data) => +data);

    var ans = [];

    for (var i = 0; i < n; i++) {
      if (inp[i] <= n && !ans.includes(inp[i])) {
        ans.push(inp[i]);
      } else {
        var val = inp[i];
        while (val > 0) {
          if (val <= n && !ans.includes(val)) {
            ans.push(val);
            break;
          }
          val = Math.floor(val / 2);
        }
      }
    }

    for (var i = 1; i <= n; i++) {
      if (!ans.includes(i)) {
        return "NO";
      }
    }

    return "YES";
  }

  while (t--) {
    print(solve());
  }

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

    let j = 2;
    for (let i = 0; i < lines[0]; ++i) {
        const arr = lines[j].split(' ').map((el) => +el);

        const n = arr.length;

        let copy = new Array(n);

        for (let i = 0; i < n; ++i) {
            copy[i] = [];
            while (arr[i] > 0) {
                if (arr[i] <= n) {
                    copy[i].push(arr[i]);
                }
                arr[i] = Math.floor(arr[i] / 2);
            }
        }

        let set = new Set();
        for (let i = 0; i < n; ++i) {
            for (let j = 0; j < copy[i].length; ++j) {
                set.add(copy[i]);
            }
        }

        let found = false;

        if (set.size === n) {
            found = true;
        }

        //const visited = new Set();

        // const dp = (pos, set, str) => {
        //     if (pos === n || found) {
        //         if (set.size === n) {
        //             found = true;
        //         }
        //         return;
        //     }
        //     for (let i = 0; i < copy[pos].length; ++i) {
        //         if (!set.has(copy[pos][i]) || visited.has(str)) {
        //             set.add(copy[pos][i]);
        //             visited.add(str);
        //             dp(pos + 1, set, str + copy[pos][i]);
        //             set.delete(copy[pos][i]);
        //         }
        //     }
        // }

        // dp(0, new Set(), '');

        console.log(found ? 'YES' : 'NO');

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

function solve(n, arr) {
    const map = {}
    const rmap = []
    arr.forEach((x, i) => {
        rmap[i] = []
        while (x) {
            map[x] = map[x] || []
            map[x].push(i)
            rmap[i].push(x)
            x = Math.floor(x / 2)
        }
    })
    rmap.sort((a, b) => a.length - b.length)
    // console.log(rmap)
    const single = {}
    const now = {}
    for (let i = 1; i <= n; i++) {
        if (!map[i]) return false
        rmap[i - 1].forEach(x => {
            now[x] = 1
        })
        if (Object.keys(now).length < i) return false
        if (map[i] && map[i].length === 1) {
            const x = map[i][0]
            if (single[x]) return false
            single[x] = 1
        }
    }
    // console.log(map)
    // console.log(single)
    return true
}

const readline = require('readline')

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

function solve(n, arr) {
    const map = {}
    arr.forEach((x, i) => {
        while (x) {
            map[x] = map[x] || []
            map[x].push(i)
            x = Math.floor(x / 2)
        }
    })
    const single = {}
    for (let i = 1; i <= n; i++) {
        if (!map[i]) return false
        if (map[i] && map[i].length === 1) {
            const x = map[i][0]
            if (single[x]) return false
            single[x] = 1
        }
    }
    // console.log(map)
    // console.log(single)
    return true
}


Stepan has a set of n strings. Also, he has a favorite string s. Stepan wants to do the following. He will take some strings of his set and write them down one after another. It is possible that he will take some strings more than once, and will not take some of them at all.Your task is to determine the minimum number of strings in the set which Stepan needs to take and write so that the string s appears as a subsequence in the resulting written down string. For example, in the string "abcd" strings "ad", "acd", "abcd" appear as subsequences, and strings "ba", "abdc" don't appear as subsequences.

The first line contains the integer n (1 ≤ n ≤ 50) — the number of strings in Stepan's set. The next n lines contain n non-empty strings consisting of lowercase letters of the English alphabet. The length of each of these strings does not exceed 50 symbols. It is possible that some strings from Stepan's set are the same. The next line contains the non-empty string s, consisting of lowercase letters of the English alphabet — Stepan's favorite string. The length of this string doesn't exceed 2500 symbols.

Print the minimum number of strings which Stepan should take from the set and write them down one after another so that the string s appears as a subsequence in the resulting written down string. Each string from the set should be counted as many times as Stepan takes it from the set.  If the answer doesn't exsist, print -1.

NoteIn the first test, Stepan can take, for example, the third and the second strings from the set, write them down, and get exactly his favorite string.In the second example Stepan can take, for example, the second, the third and again the second strings from the set and write them down. Then he will get a string "aabaaaab", in which his favorite string "baaab" is a subsequence.In the third test Stepan can not get his favorite string, because it contains the letter "c", which is not presented in any of the strings in the set.

function solve() {
    var n = +readline();
    var dict = [];

    for (var i = 0; i < n; i++) {
        dict[i] = readline();
    }

    var s = readline();
    var ans = 0;

    for (var i = 0; i < s.length; i++) {
        var mx = 0;

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

            for (var t = 0; t < dict[k].length && j < s.length; t++) {
                if (dict[k][t] == s[j]) j++;
            }

            if (j - i > mx) mx = j - i;
        }

        if (mx === 0) {
            print(-1);
            return;
        }

        ans++;
        i += mx - 1;
    }

    print(ans);
}

solve();