A non-empty digit string is diverse if the number of occurrences of each character in it doesn't exceed the number of distinct characters in it.For example:   string "7" is diverse because 7 appears in it $$$1$$$ time and the number of distinct characters in it is $$$1$$$;  string "77" is not diverse because 7 appears in it $$$2$$$ times and the number of distinct characters in it is $$$1$$$;  string "1010" is diverse because both 0 and 1 appear in it $$$2$$$ times and the number of distinct characters in it is $$$2$$$;  string "6668" is not diverse because 6 appears in it $$$3$$$ times and the number of distinct characters in it is $$$2$$$. You are given a string $$$s$$$ of length $$$n$$$, consisting of only digits $$$0$$$ to $$$9$$$. Find how many of its $$$\frac{n(n+1)}{2}$$$ substrings are diverse.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.Note that if the same diverse string appears in $$$s$$$ multiple times, each occurrence should be counted independently. For example, there are two diverse substrings in "77" both equal to "7", so the answer for the string "77" is $$$2$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the string $$$s$$$. The second line of each test case contains a string $$$s$$$ of length $$$n$$$. It is guaranteed that all characters of $$$s$$$ are digits from $$$0$$$ to $$$9$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print one integer — the number of diverse substrings of the given string $$$s$$$.

NoteIn the first test case, the diverse substring is "7".In the second test case, the only diverse substring is "7", which appears twice, so the answer is $$$2$$$.In the third test case, the diverse substrings are "0" ($$$2$$$ times), "01", "010", "1" ($$$2$$$ times), "10" ($$$2$$$ times), "101" and "1010".In the fourth test case, the diverse substrings are "0" ($$$3$$$ times), "01", "011", "0110", "1" ($$$2$$$ times), "10", "100", "110" and "1100".In the fifth test case, the diverse substrings are "3", "39", "399", "6", "9" ($$$4$$$ times), "96" and "996".In the sixth test case, all $$$15$$$ non-empty substrings of "23456" are diverse.

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

function solve(s) {
    let solution = 0;

    for (let i = 0; i < s.length; i++) {
        const counters = {
            0: 0,
            1: 0,
            2: 0,
            3: 0,
            4: 0,
            5: 0,
            6: 0,
            7: 0,
            8: 0,
            9: 0
        };

        let maxFreq = 0;
        let uniq = 0;

        for (let j = i; j < s.length; j++) {
            counters[s[j]] += 1;
            const currentFreq = counters[s[j]];

            if (currentFreq > 10) {
                break;
            }

            if (maxFreq < currentFreq) {
                maxFreq = currentFreq;
            }

            if (currentFreq === 1) {
                uniq += 1;
            }

            if (maxFreq <= uniq) {
                solution++;
            }
        }
    }

    return solution;
}

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 2) {
        const s = data[i + 1].trim();
        const solution = solve(s);
        console.log(solution);
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b )
{
    if (!b)
        return a

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        let arr = readLine().trim().split("").map(x=>parseInt(x))

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

            //let countmap = Array(10).fill(0);
            let countmap = {}
            let diverse_count=0
            let max=0

            for (let j = i; j < n; ++j) {
                let val = arr[j]

                //console.log("countmap[val] " + countmap[val])
                if(countmap[val]>=10)
                {
                    //console.log("countmap[val] " + countmap[val])
                    break;
                }

                if(countmap[val]==undefined)
                {
                    diverse_count++

                countmap[val]=0
                }

                countmap[val]++
                //console.log("countmap[val] " + countmap[val])

                max = Math.max(countmap[val],max)
                //console.log("max " + max)

                if(max <= diverse_count)
                    diverseCountTot++
            }
      }
      console.log(diverseCountTot)
   }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b )
{
    if (!b)
        return a

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        let arr = readLine().trim().split("").map(x=>parseInt(x))

        let diverseCountTot=0
        for (let i = 0; i < n; ++i) {
            let countmap = Array(10).fill(0);
            let diverse_count=0
            let max=0
            //console.log("countmap " + countmap)
            for (let j = i; j < n; ++j) {
                let val = arr[j]

                if(countmap[val]>=10)
                    break;

                if(!countmap[val])
                    diverse_count++

                //console.log("val " + val)
                countmap[val]++

                max = Math.max(countmap[val],max)
                //console.log("max " + max)

                if(max <= diverse_count)
                    diverseCountTot++
            }
      }
      console.log(diverseCountTot)
   }
}

function solve() {
    var n = Number(read());
    var count = [];
    for (var d = 0; d < 10; d++) {
        count[d] = [0];
    }
    var s = read().split('').map(Number);
    for (var i = 0; i < n; i++) {
        for (d = 0; d < 10; d++) {
            if (s[i] !== d) {
                count[d][i + 1] = count[d][i];
                continue;
            }
            count[d][i + 1] = count[d][i] + 1;
        }
    }

    var ans = 0;
    for (i = 0; i < n; i++) {
        for (var len = 1; len < 101; len++) {
            var end = i + len;
            if (end > n) {
                break;
            }
            var maxCount = 0;
            var different = 0;
            for (d = 0; d < 10; d++) {
                var currentCount = count[d][end] - count[d][i];
                if (currentCount !== 0) {
                    different++;
                    if (currentCount > maxCount) {
                        maxCount = currentCount;
                        if (maxCount > 10) {
                            break;
                        }
                    }
                }
            }
            if (different >= maxCount) {
                ans++;
            }
        }
    }
    write(ans);
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

function gcd(a, b) {
    if (b === 0) {
        return a;
    }
    return gcd(b, a % b)
}

var MEMORY;
var MEMORY_INDEX = 0;
var ANS = '';

try {
    initInput(start);
} catch (e) {
    console.log(e);
}
function readArray(f) {
    return read().split(' ').map(f);
}

function sortNumbers(a, b) {
    return a - b;
}
function sortNumbersDec(a, b) {
    return b - a;
}
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

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

function getMaxFreqAndUniq(c) {
    let uniq = 0;
    let maxFreq = -Infinity;
    for (let i = 0; i < 10; i++) {
        if (c[i] > 0) {
            uniq++;
        }

        if (c[i] > maxFreq) {
            maxFreq = c[i];
        }
    }

    return {uniq, maxFreq};
}

function count(s) {
    const result = {
        0: 0,
        1: 0,
        2: 0,
        3: 0,
        4: 0,
        5: 0,
        6: 0,
        7: 0,
        8: 0,
        9: 0,
    };

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

    return result;
}

function solve(s, c, i = 0, j = s.length - 1, alreadySolved = {}) {
    const key = `${i}-${j}`;
    if (alreadySolved[key] === true) {
        return 0;
    }

    alreadySolved[key] = true;

    if (i === j) {
        return 1;
    }

    let result = 0;

    const {uniq, maxFreq} = getMaxFreqAndUniq(c);
    if (uniq >= maxFreq) {
        result += 1;
    }

    const leftC = {...c};
    leftC[s[i]] -= 1
    result += solve(s, leftC, i + 1, j, alreadySolved);

    const rightC = {...c};
    rightC[s[j]] -= 1;
    result += solve(s, rightC, i, j - 1, alreadySolved);

    return result;
}

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');

    for (let i = 1; i < data.length; i += 2) {
        const solution = solve(data[i+1], count(data[i + 1]));
        console.log(solution);
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b )
{
    if (!b)
        return a

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        let arr = readLine().trim().split("").map(x=>parseInt(x))

        let diverseCountTot=0
        for (let i = 0; i < n; i++) {
            let countmap = Array(10).fill(0);
            let diverse_count=0
            let max=0
            //console.log("countmap " + countmap[0])
            for (let j = i; j < n; j++) {
                let val = arr[j]
                if(diverse_count>=10)
                    break;

                if(!countmap[val])
                    diverse_count++

                //console.log("val " + val)
                countmap[val]++

                max = Math.max(countmap[val],max)
                //console.log("max " + max)

                if(max <= diverse_count)
                    diverseCountTot++
            }
      }
      console.log(diverseCountTot)
   }
}


A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0, 0, 0, 1, 1, 1, 0, 0, 0] can be a photo of zebra, while the photo [0, 0, 0, 1, 1, 1, 1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not?

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the width of the photo. The second line contains a sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 1) — the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white.

If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra.

var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === '9') {

	} else if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count && w >= 0) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}

isOk = function(a, n, k){
    var black = a[0];
    for(var i = 1; i < n; i++)
    if((Math.floor(i / k) % 2 === 0 && a[i] !== black) || (Math.floor(i / k) % 2 === 1 && a[i] === black)){
        return false;
    }
    return true;
};

n = parseInt(readline());
a = readline().split(' ');
res = false;
for(var i = 1; i * i <= n; i++)
if(n % i === 0){
    if(isOk(a, n, i) || isOk(a, n, Math.floor(n/i)))
        res = true;
}
if(res)
    print("YES");
else
    print("NO");

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

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

var pre = -1;
var len = 0;
var nowlen = 0;
for(var i = 0;i < n;i++){
    var now = parseInt(line[i]);
    if(pre == -1 || now == pre){
        pre = now;
        nowlen++;
    }
    else{
        if(!len) len = nowlen;
        else if(len != nowlen){
            //:wqprint('NO');
            break;
        }
        pre = now;
        nowlen = 1;
    }
}
if( len && len != nowlen)
    print('NO');
else
    print('YES');

var n=readline();
var w = readline().split(' ').map(function(x) { return parseInt(x);});
var cnt=0,y=-1;
var last=-1,ans=1;
for(var i=0;i<n;i++){
    var x = w[i];
    if(last===-1)
        last=x;
    if(x===last)
        cnt++;
    else{
        if(y===-1)
            y=cnt;
        else{
            if(cnt!==y)
                ans=0;
        }
        cnt=1;
        last=x;
    }
}
if(ans===0)
    print("NO");
else if(y!==-1&&cnt!==y)
    print("NO");
else
    print("YES");

var n = readline();
n = parseInt(n);
var s = readline().split(" ");
var p = 0;
var arr = new Array();
for (var i = 0; i < s.length; i++) {
    if (i == s.length || s[i] != s[i + 1]) {
        arr.push(i - p + 1);
        p = i + 1;
    }
}
var flag = true;
for (var i = 1; i < arr.length; i++) {
    if (arr[i] != arr[i - 1]) {
        flag = false;
        break;
    }
}
if (flag) print("YES");
else print("NO");

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

var white = 0, blk = 0;
var fw = 0, fb = 0;
var fixW=0, fixB=0;
var flg = 1;
for(var i=0; i<n; i++)
{
    if(numbers[i] == 0)
    {
    	if(blk)
        {
            if(fb == 0) fixB = blk;
            else if(blk != fixB) flg = 0;
            fb = 1;
            blk = 0;
        }

        white+=1;
    }
    else
    {
        if(white)
        {
            if(fw == 0) fixW = white;
            else if(white != fixW) flg = 0;
            fw = 1;
            white = 0;
        }

        blk += 1;
    }
}

if(white)
{
    if(fw == 0) fixW = white;
    else if(white != fixW) flg = 0;
    fw = 1;
    white = 0;
}

if(blk)
{
    if(fb == 0) fixB = blk;
    else if(blk != fixB) flg = 0;
    fb = 1;
    blk = 0;
}
if(fixB ==0) fixB = fixW;
if(fixW ==0) fixW = fixB;
if(flg && fixW == fixB) print("YES\n");
else print("NO\n");

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

var lng = 1;
var lng_base;
var isFirst = true;
var fail = false;
for (var i = 1; i < n; i++ ) {
    var k = arr[i];
    last = arr[i-1];
    if (k == last) {
        lng++;

    } else
        if (isFirst) {
            lng_base = lng;
            lng = 1;
            isFirst = false;
        } else if (lng != lng_base) {
            fail = true;

            break;
        } else {
            lng = 1;
        }

}

if (lng != lng_base) {fail = true}
if (lng == n) {fail = false}
if (fail) {
    print('NO');
} else print('YES');

function solve() {
    var n = readline()
    var s = readline().split(' ');

    var sz = 0;
    while (s[sz] === s[0]) sz++;

    if (s.length % sz)
        return false;

    for(var i=0;i<s.length;i++) {
        var m = i % (2 * sz);
        if(m < sz) {
            if(s[i] != s[0]) return false;
        }
        else {
            if(s[i] == s[0]) return false;
        }
    }

    return true;
}

print(solve() ? "YES" : "NO");

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

var last = 0;
var good = 1;
var cur = -1;
for (var i = 1; i < a.length; i++) {
    if (a[i] != a[i - 1]) {
        var curl = i - last;
        if (cur == -1) {
            cur = curl;
        } else if (cur != curl) {
            good = 0;
            cur = curl;
        }
        last = i;
    }
}

var curl = a.length - last;
if (cur != -1 && curl != cur) {
    good = 0;
}

if (good == 0) {
    print("NO");
} else {
    print("YES");
}

var n;
var temp,last;
var curL = 1,L = -1;
var flag = false;

    var n = parseInt(readline().split(' ')[0]);
    var a = readline().split(' ').map(Number);
    for (var i = 0;i < n;i++){
        var temp = a[i];
        if (i == 0){
            last = temp;
            continue;
        }
        if (temp == last) curL++;
        else {
        if (curL!=L&&L!=-1){
            print("NO");
            flag = true;
            break;
        }
        L = curL;
        curL = 1;
        }
        last = temp;
    }
    if (!flag && curL!=0 && curL!=L && L!=-1) {
        print("NO");
    } else if (!flag)
    print("YES");

var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = 0;
var hopaayega = true;
//for(var i=0;i<n;i++){
//    var curr = parseInt(a[i]);
//    if(a[i] != a[0]){
//        cycl = i;
//        break;
//    }
//}
while(a[cycl] === a[0]) cycl ++;
if(n%cycl) {
    print('NO');
}
else {
    for(var i=0;i<n;i++){
        var curr = parseInt(a[i]);
        var cycl_t = i%(2*cycl)
        if(cycl_t<cycl){
            if(curr != a[0]){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == a[0]){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}

readline();
var arr = readline().split(" ");
var cur = arr[0];
var p = 0;

var ANS = "YES";

var q = 0;
for (var i = 0; i < arr.length; ++i) {
    if (arr[i] !== arr[0]) {
        break;
    }
    q++;
}

for (i = 0; i < arr.length; ++i) {
    if (cur === arr[i]) {
        p++;
        if (p > q) {
            ANS = "NO";
            break;
        }
    }
    else {
        if (p !== q) {
            ANS = "NO";
            break;
        }
        p = 1;
        cur = arr[i];
    }
}
if (p !== q) {
    ANS = "NO";
}

print(ANS);

var n = parseInt(readline());
var arr = readline().split(' ');
var length = -1;
var curr = 0;
var state = arr[0];
var flag = 1;
for (var i = 0; i < n; i++) {
    if (arr[i] == state) {
        curr++;
    } else {
        if (length != -1 && curr != length) {
            flag = 0;
        } else {
            length = curr;
        }
        curr = 1;
        state = arr[i];
    }
    //print(flag, curr, length, arr[i]);
}
if (length != -1 && curr != length) {
    flag = 0;
}
if (!flag) print('NO');
else print("YES");

readline();
var s = readline().split(" ");
var n = s.length;

var com = 0;
var cur = 1;
for (var i = 1; i < n; ++i) {
    if (s[i] == s[i-1]) {
        ++cur;
    } else {
        if (com && com != cur) {
            com = 0;
            break;
        } else {
            com = cur;
            cur = 1;
        }
    }
}
if (cur != n && (!com || cur != com)) {
    print("NO");
} else {
    print("YES");
}

var n = readline().split(" ").map(v => +v.trim())[0];
var a = readline().split(" ").map(v => +v.trim());

var len=1, i=1;
while(i < n && a[i]==a[0]) {
	i++;
	len++;
}

var ok = 1, val = a[0];

for(var j=0; j<n && ok; j+=len) {
	for(var k=0; k<len; k++)
		if(a[j]!=a[j+k] || a[j+k] != val) {
			ok = 0;
			break;
		}
	val ^= 1;
}

if(ok)
	print("YES");
else
	print("NO");

var n = parseInt(readline());
var arr = readline().split(" ").map(v => parseInt(v));

function compute() {
  var good = true;
  for (i = 0; i < n; i++) {
    if (arr[i] != arr[0]) {
      good = false;
    }
  }
  if (good == true) {
    return "YES";
  }
  var period = 0;
  for (i = 0; i < n; i++) {
    if (arr[i] != arr[0]) {
      period = i;
      break;
    }
  }
  if (n % period != 0) {
    return "NO";
  }
  for (i = period; i < n; i = i + period) {
    if (arr[i] == arr[i - 1]) {
      return "NO";
    }
    for (j = 1; j < period; j++) {
      if (arr[i + j] != arr[i + j - 1]) {
        return "NO";
      }
    }
  }
  return "YES";
}

print(compute());

var n = parseInt(readline());

var st = readline();

var check = Number(st[0]), p, inc = 1, s = 0;

for(i = 1; i < n; ++i){
    p = Number(st[i * 2]);
    if(check == p){
        ++inc;
    }else{
        if(s){
            if(inc != s){
                break;
            }
        }else{
            s = inc;
        }
        inc = 1;
        check = p;
    }
}

if(s)
    if(inc == s)
        print("YES");
    else
        print("NO");
else
    print("YES");

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var i = readline().split(' ');
var prev = 0;
var cnt = 0;
for(var j = 0; j < n; j++)
{
    if(j!=0)
    {
        if(i[j] != i[j-1])
        {    if(prev!=0 && cnt != prev)
            {
                print("NO");
                break;
            }
            prev = cnt;
             cnt = 0;
        }
    }
    cnt++
    if(prev!=0&&cnt>prev)
        {
                print("NO");
                break;
            }
    if(j==n-1 && (cnt == prev || prev == 0))
        print("YES");
    if(j == n-1 && prev!=0 && cnt != prev)
        print("NO");
}

var n = +readline();
var a = readline().split(' ').map(v => +v.trim());;

var t = 0;
for (var i = 0; i < n; i++)
    if (a[i] == a[0])
        ++t;
    else
        break;

var ok = true;
for (var i = t, cur = 1 - a[0]; i < n && ok; i += t, cur = 1 - cur)
    for (var j = i; j < i + t; j++)
        if (a[j] != cur) {
            print("NO");
            ok = false;
            break;
        }

if (ok)
    print("YES");

n = readline().split(' ').map(Number)[0];
arr = readline().split(' ').map(Number);

var zero = arr[0];
var zeros = 0;

for (i = 0; i < n; i++) {
    if (arr[i] == zero) {
        zeros++;
    } else {
        break;
    }
}

var i = 0;

var yas = true;

yas &= (n % zeros === 0);

for (i = 0; i < n; i += zeros) {
    for (var j = 0; j < zeros; j++) {
        yas &= (arr[i + j] == zero);
    }
    zero = 1 - zero;
}
if (yas) {
    print("YES");
} else {
    print("NO");
}

var n = parseInt(readline());

var gList = readline();

var f=-1;
var l=0;
var ans=true;

var prev=-1;var now = 1;

for(var i = 0; i < gList.length; i+=2){

    if (gList[i] === '1'){
        now = 1;
    } else {
        now = 0;
    }
    //print(prev+' '+now);

    if (i!=0) {

        if (prev!=now) {

            if (f==-1) {
                f=l;

                l=1;
            } else {
                //print(l);
                //print(f);
                if (l!=f) {ans=false}
                l=1;
            }

        }else {l++};

    }else {l++};
     //print(f+' '+l);
    prev=now;
}

if (f!=-1) {
    if (l!=f) {ans=false}}

if (ans) {
    print('YES')
} else{
    print('NO')
}

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

for( var i = 0; i < n; i += 1 )a[i] = parseInt( a[i] );

var cnt = 0, lnt = 0, t = true;

f = a[0];

while( a[cnt++] === f );

f = 1 - f;

cnt--;

for( var i = cnt; i < n; i ++ ){
    if( a[i] === f )lnt++;
    else{
        if( lnt != cnt ){
            write( "NO" );
            t = false;
            break;
        }
        f = 1 - f;
        lnt = 1;
    }
    //write( i + ' ' + a[i] + ' ' + cnt + ' ' + lnt + '\n' );
}

if( t && cnt != n && lnt != cnt ){
    write( "NO" );
    t = false;
}

if( t === true )
write( "YES" );

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var arr = readline().split(" ");
var l1 = 0;
var l2 = 0;
var x = 0;
var result = "YES";
for(var i = 0; i < n; i++){
    if(x == 0){
        if(arr[i] == '1'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 1;
                l2 = 1;
            }
        } else {
            l1++;
        }
    } else {
        if(arr[i] == '0'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 0;
                l1 = 1;
            }
        } else {
            l2++;
        }
    }
}
if(l1 != l2 && l1*l2 != 0)
    result = "NO";
print(result);

var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}

var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === '9') {

	} else if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}

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

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

var pre = -1;
var len = 0;
var nowlen = 0;
for(var i = 0;i < n;i++){
    var now = parseInt(line[i]);
    if(pre == -1 || now == pre){
        pre = now;
        nowlen++;
    }
    else{
        if(!len) len = nowlen;
        else if(len != nowlen){
            //:wqprint('NO');
            break;
        }
        pre = now;
        nowlen = 1;
    }
}
if(!len || len != nowlen)
    print('NO');
else
    print('YES');

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

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

var pre = -1;
var len = 0;
var nowlen = 0;
for(var i = 0;i < n;i++){
    var now = parseInt(line[i]);
    if(pre == -1 || now == pre){
        pre = now;
        nowlen++;
    }
    else{
        if(!len) len = nowlen;
        else if(len != nowlen){
            //:wqprint('NO');
            break;
        }
        pre = now;
        nowlen = 1;
    }
}
if(len != nowlen)
    print('NO');
else
    print('YES');

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

var white = 0, blk = 0;
var fw = 0, fb = 0;
var fixW, fixB;
var flg = 1;
for(var i=0; i<n; i++)
{
    if(numbers[i] == 0)
    {
        if(fb == 0) fixB = blk;
        else if(blk != fixB) flg = 0;
        fb = 1;

        white+=1;
    }
    else
    {
        if(fw == 0) fixW = white;
        else if(white != fixW) flg = 0;
        fw = 1;
        white = 0;

        blk += 1;
    }
}

if(flg) print("YES\n");
else print("NO\n");

var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = n;
var hopaayega = true;
for(var i=0;i<n;i++){
    var curr = parseInt(a[i]);
    if(a[i] != a[0]){
        cycl = i;
        break;
    }
}
if(n%cycl) {
    print('NO');
}
else {
    for(var i=1;i<n-1;i++){
        var curr = parseInt(a[i]);
        var cycl_t = i%(2*cycl)
        if(cycl_t<cycl){
            if(curr != a[0]){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == a[0]){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}

var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = 0;
var hopaayega = true;
//for(var i=0;i<n;i++){
//    var curr = parseInt(a[i]);
//    if(a[i] != a[0]){
//        cycl = i;
//        break;
//    }
//}
while(a[cycl] === a[0]) cycl ++;
if(n%cycl) {
    print('NO');
}
else {
    for(var i=1;i<n-1;i++){
        var curr = parseInt(a[i]);
        var cycl_t = i%(2*cycl)
        if(cycl_t<cycl){
            if(curr != a[0]){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == a[0]){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}

var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = n;
var hopaayega = true;
for(var i=0;i<n;i++){
    var curr = parseInt(a[i]);
    if(a[i] != a[0]){
        cycl = i;
        break;
    }
}
if(n%cycl) {
    print('NO');
}
else {
    for(var i=1;i<n-1;i++){
        var curr = parseInt(a[i]);
        var prev = parseInt(a[i-1]);
        if(i%cycl){
            if(curr != prev){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == prev){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}

var s = readline().split(" ");
var n = s.length;

var com = 0;
var cur = 1;
for (var i = 1; i < n; ++i) {
    if (s[i] == s[i-1]) {
        ++cur;
    } else {
        if (com && com != cur) {
            com = 0;
            break;
        } else {
            cur = 1;
        }
    }
}
if (!com || cur != com) {
    print("NO");
} else {
    print("YES");
}

readline();
var s = readline().split(" ");
var n = s.length;

var com = 0;
var cur = 1;
for (var i = 1; i < n; ++i) {
    if (s[i] == s[i-1]) {
        ++cur;
    } else {
        if (com && com != cur) {
            com = 0;
            break;
        } else {
            com = cur;
            cur = 1;
        }
    }
}
if (!com || cur != com) {
    print("NO");
} else {
    print("YES");
}

readline();
var s = readline().split(" ");
var n = s.length;

var com = 0;
var cur = 1;
for (var i = 1; i < n; ++i) {
    if (s[i] == s[i-1]) {
        ++cur;
    } else {
        if (com && com != cur) {
            com = 0;
            break;
        } else {
            com = cur;
            cur = 1;
        }
    }
}
if ((!com && cur != n) || cur != com) {
    print("NO");
} else {
    print("YES");
}

var n = readline().split(" ").map(v => +v.trim())[0];
var a = readline().split(" ").map(v => +v.trim());

var len=1, i=1;
while(i < n && a[i]==a[0]) {
	i++;
	len++;
}

var ok = 1;
for(var j=0; j<n && ok; j+=len) {
	for(var k=0; k<len; k++)
		if(a[j]!=a[j+k]) {
			ok = 0;
			break;
		}
}

if(ok)
	print("YES");
else
	print("NO");

var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === '9') {

	} else if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count && w > 0) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}

var n = parseInt(readline());

var st = readline();

var check = Number(st[0]), p, inc = 1, s = 0;

var i

for(i = 1; i < n; ++i){
    p = Number(st[i * 2]);
    if(check == p){
        ++inc;
    }else{
        if(s){
            if(inc != s){
                break;
            }
        }else{
            s = inc;
        }
        inc = 1;
        check = p;
    }
}

if(inc == s)
    print("YES");
else
    print("NO");

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var arr = readline().split(" ");
var l1 = 0;
var l2 = 0;
var x = 0;
var result = "YES";
for(var i = 0; i < n; i++){
    if(x == 0){
        if(arr[i] == '1'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 1;
                l2 = 0;
            }
        } else {
            l1++;
        }
    } else {
        if(arr[i] == '0'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 0;
                l1 = 0;
            }
        } else {
            l2++;
        }
    }
}
if(l1 != l2 && l1*l2 != 0)
    result = "NO";
print(result);

                print(l1);
                print(l2);

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var arr = readline().split(" ");
var l1 = 0;
var l2 = 0;
var x = 0;
var result = "YES";
for(var i = 0; i < n; i++){
    if(x == 0){
        if(arr[i] == '1'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 1;
                l2 = 0;
            }
        } else {
            l1++;
        }
    } else {
        if(arr[i] == '0'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NO";
            } else {
                x = 0;
                l1 = 0;
            }
        } else {
            l2++;
        }
    }
    print(l1);
    print(l2);
}
if(l1 != l2 && l1*l2 != 0)
    result = "NO";
print(result);

//JavaScript-C24.2.0 (SpiderMonkey)

var n = readline();
var arr = readline().split(" ");
var l1 = 0;
var l2 = 0;
var x = 0;
var result = "YES";
for(var i = 0; i < n; i++){
    if(x == 0){
        if(arr[i] == '1'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NOp";
            } else {
                x = 1;
                l2 = 0;
            }
        } else {
            l1++;
        }
    } else {
        if(arr[i] == '0'){
            if(l1 != l2 && l1 != 0 && l2 != 0){
                result = "NOd";
            } else {
                x = 0;
                l1 = 0;
            }
        } else {
            l2++;
        }
    }
}
if(l1 != l2 && l1*l2 != 0)
    result = "NOg";
print(result);


You are given a deck of $$$n$$$ cards numbered from $$$1$$$ to $$$n$$$ (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation.   Choose $$$2 \le k \le n$$$ and split the deck in $$$k$$$ nonempty contiguous parts $$$D_1, D_2,\dots, D_k$$$ ($$$D_1$$$ contains the first $$$|D_1|$$$ cards of the deck, $$$D_2$$$ contains the following $$$|D_2|$$$ cards and so on). Then reverse the order of the parts, transforming the deck into $$$D_k, D_{k-1}, \dots, D_2, D_1$$$ (so, the first $$$|D_k|$$$ cards of the new deck are $$$D_k$$$, the following $$$|D_{k-1}|$$$ cards are $$$D_{k-1}$$$ and so on). The internal order of each packet of cards $$$D_i$$$ is unchanged by the operation. You have to obtain a sorted deck (i.e., a deck where the first card is $$$1$$$, the second is $$$2$$$ and so on) performing at most $$$n$$$ operations. It can be proven that it is always possible to sort the deck performing at most $$$n$$$ operations.Examples of operation: The following are three examples of valid operations (on three decks with different sizes).   If the deck is [3 6 2 1 4 5 7] (so $$$3$$$ is the first card and $$$7$$$ is the last card), we may apply the operation with $$$k=4$$$ and $$$D_1=$$$[3 6], $$$D_2=$$$[2 1 4], $$$D_3=$$$[5], $$$D_4=$$$[7]. Doing so, the deck becomes [7 5 2 1 4 3 6].  If the deck is [3 1 2], we may apply the operation with $$$k=3$$$ and $$$D_1=$$$[3], $$$D_2=$$$[1], $$$D_3=$$$[2]. Doing so, the deck becomes [2 1 3].  If the deck is [5 1 2 4 3 6], we may apply the operation with $$$k=2$$$ and $$$D_1=$$$[5 1], $$$D_2=$$$[2 4 3 6]. Doing so, the deck becomes [2 4 3 6 5 1].

The first line of the input contains one integer $$$n$$$ ($$$1\le n\le 52$$$)  — the number of cards in the deck. The second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$  — the cards in the deck. The first card is $$$c_1$$$, the second is $$$c_2$$$ and so on. It is guaranteed that for all $$$i=1,\dots,n$$$ there is exactly one $$$j\in\{1,\dots,n\}$$$ such that $$$c_j = i$$$.

On the first line, print the number $$$q$$$ of operations you perform (it must hold $$$0\le q\le n$$$). Then, print $$$q$$$ lines, each describing one operation. To describe an operation, print on a single line the number $$$k$$$ of parts you are going to split the deck in, followed by the size of the $$$k$$$ parts: $$$|D_1|, |D_2|, \dots , |D_k|$$$.  It must hold $$$2\le k\le n$$$, and $$$|D_i|\ge 1$$$ for all $$$i=1,\dots,k$$$, and $$$|D_1|+|D_2|+\cdots + |D_k| = n$$$. It can be proven that it is always possible to sort the deck performing at most $$$n$$$ operations. If there are several ways to sort the deck you can output any of them.

NoteExplanation of the first testcase: Initially the deck is [3 1 2 4].   The first operation splits the deck as [(3) (1 2) (4)] and then transforms it into [4 1 2 3].  The second operation splits the deck as [(4) (1 2 3)] and then transforms it into [1 2 3 4].  Explanation of the second testcase: Initially the deck is [6 5 4 3 2 1].   The first (and only) operation splits the deck as [(6) (5) (4) (3) (2) (1)] and then transforms it into [1 2 3 4 5 6].

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

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 ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1])) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, 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);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let n = $(), a = $(n)

  let suf = arr => {
    // log(arr)
    out.push([arr.length, ...arr].join(' '))
    let s = 0;
    let na = []
    arr.forEach(v => {
      na.push(a.slice(s, s += v))
    })
    a = na.reverse().flat()
    // log(a)
    // log('---')
  }

  let join = x => {
    let vx1 = a.findIndex(v => v == x - 1)
    let v1 = a.findIndex(v => v == 1)
    let vx = a.findIndex(v => v == x)
    if (v1 == vx1) {
      if (vx > v1) {
        suf([v1, 1, vx - v1, n - 1 - vx].filter(v => v))
      } else {
        suf([vx, 1, v1 - vx, n - 1 - v1].filter(v => v))
      }
    } else {
      if (v1 > vx1 && v1 > vx) {
        suf([vx, vx1 - vx, ...Arr(x - 1, i => 1), n - 1 - v1].filter(v => v))
      } else if (v1 > vx1 && v1 < vx) {
        suf([vx1, x - 1, vx - v1, n - 1 - vx].filter(v => v))
      } else if (v1 < vx1 && v1 > vx) {
        suf([vx, v1 - vx, x - 1, n - 1 - vx1].filter(v => v))
      } else {
        suf([v1, ...Arr(x - 1, i => 1), vx - vx1, n - 1 - vx].filter(v => v))
      }
    }
  }
  For(2, n, i => {
    join(i)
  })
  if (n > 1 && a[0] != 1) suf(Arr(n, i => 1))
  log(out.length)
  log(out.join('\n'))
}

'use strict';

var readline = require('readline');

function constantNumberofLinesStdin(lines) {
  return new Promise(resolve => {
    const stdin = readline.createInterface(process.stdin);
    const output = [];
    stdin.on('line', line => {
      output.push(line);

      if (output.length === lines) {
        resolve(output);
        stdin.close();
      }
    });
  });
}

function solve(cards) {
  const output = [];
  const n = cards.length;
  const lastIndex = n - 1;

  function isSolved() {
    return n === 1 || cards.slice(1).every((c, i) => c > cards[i]);
  }

  function performAction(groupSizes) {
    output.push(groupSizes.length + ' ' + groupSizes.join(' '));
    const swapped = [];
    let index = 0;

    for (const size of groupSizes) {
      swapped.splice(0, 0, ...cards.slice(index, index + size));
      index += size;
    }

    cards = swapped;
  }

  while (!isSolved()) {
    let currentOrder;

    if (cards[0] === 1 || cards[lastIndex] === n) {
      currentOrder = 'asc';
    } else if (cards[lastIndex] === 1 || cards[0] === n) {
      currentOrder = 'desc';
    } else {
      currentOrder = n & 1 ? 'asc' : 'desc';
    }

    let leadingDone = 0,
        trailingDone = 0;

    if (currentOrder === 'asc') {
      while (cards[leadingDone] === leadingDone + 1) {
        leadingDone++;
      }

      while (cards[lastIndex - trailingDone] === n - trailingDone) {
        trailingDone++;
      }
    } else {
      while (cards[leadingDone] === n - leadingDone) {
        leadingDone++;
      }

      while (cards[lastIndex - trailingDone] === trailingDone + 1) {
        trailingDone++;
      }
    }

    if (leadingDone === n) {
      trailingDone = 0;
    }

    const lastLeadingDone = cards[leadingDone - 1] || (currentOrder === 'asc' ? 0 : n + 1);
    const targetCard = currentOrder === 'asc' ? lastLeadingDone + 1 : lastLeadingDone - 1;
    const targetIndex = cards.indexOf(targetCard);
    const action = [];

    for (let x = 0; x < leadingDone; x++) {
      action.push(1);
    }

    if (targetIndex >= 0) {
      const left = targetIndex - leadingDone + 1;
      const right = n - leadingDone - left - trailingDone;
      action.push(left);

      if (right) {
        action.push(right);
      }
    }

    for (let x = 0; x < trailingDone; x++) {
      action.push(1);
    }

    performAction(action);
  }

  console.log(output.length);
  output.forEach(line => console.log(line)); // [3] [1 2 4]          Moves: 4
  // [1] [2] [4 3]        Moves: 3
  // 4 3 2 1              Moves: 2
  // 1 2 3 4
  // [6 8 4 9 1] [2 3 7 5]
  // [2 3 7 5 6 8 4 9] [1]
  // [1] [2] [3] [7 5 6 8 4] [9]
  // [9] [7] [5 6 8] [4] [3] [2] [1]
  // [1] [2] [3] [4] [5] [6] [8 7] [9]
  // [9] [8] [7] [6] [5] [4] [3] [2] [1]
  // 1 2 3 4 5 6 7 8 9
}

async function main() {
  const input = await constantNumberofLinesStdin(2);
  solve(input[1].split(' ').map(Number));
}

main().then();


There is a bookshelf which can fit $$$n$$$ books. The $$$i$$$-th position of bookshelf is $$$a_i = 1$$$ if there is a book on this position and $$$a_i = 0$$$ otherwise. It is guaranteed that there is at least one book on the bookshelf.In one move, you can choose some contiguous segment $$$[l; r]$$$ consisting of books (i.e. for each $$$i$$$ from $$$l$$$ to $$$r$$$ the condition $$$a_i = 1$$$ holds) and:  Shift it to the right by $$$1$$$: move the book at index $$$i$$$ to $$$i + 1$$$ for all $$$l \le i \le r$$$. This move can be done only if $$$r+1 \le n$$$ and there is no book at the position $$$r+1$$$.  Shift it to the left by $$$1$$$: move the book at index $$$i$$$ to $$$i-1$$$ for all $$$l \le i \le r$$$. This move can be done only if $$$l-1 \ge 1$$$ and there is no book at the position $$$l-1$$$. Your task is to find the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without any gaps).For example, for $$$a = [0, 0, 1, 0, 1]$$$ there is a gap between books ($$$a_4 = 0$$$ when $$$a_3 = 1$$$ and $$$a_5 = 1$$$), for $$$a = [1, 1, 0]$$$ there are no gaps between books and for $$$a = [0, 0,0]$$$ there are also no gaps between books.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of places on a bookshelf. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is $$$1$$$ if there is a book at this position and $$$0$$$ otherwise. It is guaranteed that there is at least one book on the bookshelf.

For each test case, print one integer: the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without gaps).

NoteIn the first test case of the example, you can shift the segment $$$[3; 3]$$$ to the right and the segment $$$[4; 5]$$$ to the right. After all moves, the books form the contiguous segment $$$[5; 7]$$$. So the answer is $$$2$$$.In the second test case of the example, you have nothing to do, all the books on the bookshelf form the contiguous segment already.In the third test case of the example, you can shift the segment $$$[5; 5]$$$ to the left and then the segment $$$[4; 4]$$$ to the left again. After all moves, the books form the contiguous segment $$$[1; 3]$$$. So the answer is $$$2$$$.In the fourth test case of the example, you can shift the segment $$$[1; 1]$$$ to the right, the segment $$$[2; 2]$$$ to the right, the segment $$$[6; 6]$$$ to the left and then the segment $$$[5; 5]$$$ to the left. After all moves, the books form the contiguous segment $$$[3; 4]$$$. So the answer is $$$4$$$.In the fifth test case of the example, you can shift the segment $$$[1; 2]$$$ to the right. After all moves, the books form the contiguous segment $$$[2; 5]$$$. So the answer is $$$1$$$.

'use strict'; /*jslint node:true, browser:true, es6:true*/
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)
let rli = 0;
function readline() {
    return lines[rli++];
}

let mem = new Map();
function query(arr){
    let RES = 0;
    let last_i = arr.lastIndexOf(1);
    let had;
    for (let i=0; i<last_i; i++)
    {
        if (arr[i])
            had = true;
        else
        {
            if (had)
                RES++;
        }
    }
    return RES
}

function main() {
    var q = +readline();
    while (q--)
    {
        var n = +readline();
        let arr = readline().split(' ').map(a=>+a);
        print(query(arr));
    }
}

const solve = (shelf) => {
    let start = shelf.indexOf(1);
    let end = shelf.lastIndexOf(1);
    if (start == end) return 0;
    let cnt = 0;
    for (let i = start; i <= end; i++) {
        if (shelf[i] == 0) {
            cnt++;
        }
    }
    return cnt;
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = Number(input[0][0]);
        let i = 2;
        while (t > 0) {
            let data = input.slice(i, i + 1);
            console.log(solve(data[0]));
            t--;
            i += 2;
        }
    });
};

main()

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

let lineNum = 0;
let countOfData = null;
let data = [];
readline.on('line', line => {
  lineNum++;
  if(lineNum === 1) {
    countOfData = +line * 2;
    return;
  }

  data.push(line);

  if(lineNum - 1 === countOfData) {
    goToSolution(data);
  }

});

function goToSolution(data) {
  data.forEach((shelf, i) => {
    if(i % 2 !== 0) {
      let spaceZeroes = 0;
      let tempZeroes = 0;
      let booksDetected = false;
      for(let i = 0; i < shelf.length; i+=2) {
        if(shelf[i] == 1) {
          if(booksDetected) {
            spaceZeroes += tempZeroes;
          } else {
            booksDetected = true;
          }
          tempZeroes = 0;
        } else {
          tempZeroes++;
        }
      }

      console.log(spaceZeroes);
    }
  })
}

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

let isT = true;
let inputLength;
let inputShelf;
let inputCounter = 0;

readLine.on("line", line => {
    if (isT) {
        isT = false;
    } else {
        if (inputCounter == 1) {
            inputShelf = line;
            countMoves(inputLength ,inputShelf);
            inputCounter = 0;
        } else {
            inputLength = line;
            inputCounter++;
        }
    }
});

function countMoves(length, shelf) {
    length = parseInt(length);
    let shelfArr= [];
    for (let i = 0; i < shelf.length; i += 2) {
        shelfArr.push(shelf[i]);
    }
    let movesSum = 0;
    let outerFlag = false;
    let met = 0;
    let numberOfBooks = 0;
    for (let i = 0; i < shelfArr.length; i++) {
        if(shelfArr[i] == 1) {
            numberOfBooks++;
        }
    }
    for (let i = 0; i < shelfArr.length; i++) {
        if (shelfArr[i] == 1) {
            met++;
            if(met == numberOfBooks) {
                break;
            }
            outerFlag = true;
        } else if (shelfArr[i] == 0 && outerFlag === true) {
            movesSum++;
        }
    }
    if (met < 2) {
        movesSum = 0;
    }
    console.log(movesSum);
}

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));
const sub = (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 pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine().split(" ").map(Number);
    let [first1, last1] = [arr.indexOf(1), arr.lastIndexOf(1)];

    if (first1 === last1) console.log(0);
    else {
      let count = 0;
      for (let i = first1; i <= last1; i++) {
        if (arr[i] === 0) count++;
      }
      console.log(count);
    }
  }
}

//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();
		var L = -1;
		var R = -1;
		var zero = 0;
		for(var j = 0; j < N; j++){
			if(list[j] == 1){
				L = j;
				break;
			}
		}
		for(var j = N - 1; j >= 0; j--){
			if(list[j] == 1){
				R = j;
				break;
			}
		}
		for(var j = L; j <= R; j++){
			if(list[j] == 0){
				zero++;
			}
		}
		output[i] = zero;
	}
	myout(myconv(output, 9));
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;
    while (i <= testCases) {
      // let a = data[i].trim();
      // const n = data[i] * 1;
      // const k = a[1];
      const s = data[i + 1].trim().split(' ').map(Number);
      // s.sort((a, b) => b - a);
      let first = s.indexOf(1);
      let arr = [];
      let min = 0;

      for (let j = first + 1; j < s.length; j += 1) {
        if (s[j] === 1) arr.push(j);
      }

      while (arr.length) {
        let diff = arr.shift();
        if (diff - first === 1) {first = diff; continue;}
        diff =  diff - first - 1;
        min += diff;
        arr = arr.map(a => a - diff);
        first += 1;
      }

      console.log(min);
      i += 2;
    }
}

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.question("", loop =>{
  getUserInput(loop);
})

function getUserInput(n) {
    rl.question('', (number) => {
        rl.question("", number => {
            let fi = number.indexOf("1");
            let li = number.lastIndexOf("1");
            //console.log(fi, li);
            number = number.substring(fi,li+1);
            //console.log(number);
            let arr = number.split(" ")
            //console.log(arr);
            console.log(countZeros(arr));
            if (n > 1) {
                getUserInput(n-1);
            } else {
                rl.close();
            }
        })
    });
}

function countZeros(arr){
    let count = 0;
    for (let index = 0; index < arr.length; index++) {
        if(arr[index] == 0)
            ++count;
    }
    return count;
}

rl.on("close", function() {
    process.exit(0);
});

//cat q2.text | node q2.js
'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    for (let i = 0; i < x; i++) {
        let y = readline();
        let z = readline().split(" ");
        console.log(Bookshelf(y,z))
    }
}

function Bookshelf(len, data) {

    let ans = 0;

    let firstIndex = data.indexOf("1");
    let lastIndex = data.lastIndexOf("1");

    for (let i = firstIndex; i < lastIndex; i++) {
        if (data[i] == 0) {
            ans++
        }
    }

    return ans;

}

var t = parseInt(readline());

while (t--) {
    var n = parseInt(readline());
    var f = 0;
    var ar = readline().split(' ').map(function(x) { return parseInt(x); });
    ar.forEach(function(x) { if (x == 1) f = 1 });
    if (!f) {
        print("0");
        continue;
    }
    var first = -1, last = -1;
    for (var i = 0; i < ar.length; ++i) if (ar[i] == 1) {
        first = i;
        break;
    }
    for (var i = ar.length-1; i >= 0; --i) if (ar[i] == 1) {
        last = i;
        break;
    }
    var cnt = 0;
    for (var i = first; i <= last; ++i) {
        cnt += ar[i] == 0;
    }
    print(cnt);
}

var problem = function(arr) {

    var count = 0, first = arr.indexOf('1'), last = arr.lastIndexOf('1'), a = arr.slice(first, last);
    for (var i = 0; i < arr.length; i++) {
        if (a[i] == 1) count++;
    }
    return (a.length - count);

}

var tests = readline();

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

        var n, items;
        n = readline();
        items = readline().split(" ");
        print(problem(items));

}

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

let isT = true;
let inputLength;
let inputShelf;
let inputCounter = 0;

readLine.on("line", line => {
    if (isT) {
        isT = false;
    } else {
        if (inputCounter == 1) {
            inputShelf = line;
            countMoves(inputLength ,inputShelf);
            inputCounter = 0;
        } else {
            inputLength = line;
            inputCounter++;
        }
    }
});

function countMoves(length, shelf) {
    length = parseInt(length);
    let shelfArr= [];
    for (let i = 0; i < shelf.length; i += 2) {
        shelfArr.push(shelf[i]);
    }
    let movesSum = 0;
    let outerFlag = false;
    let metAnother = false;
    for (let i = 0; i < shelfArr.length; i++) {
        if (shelfArr[i] == 1) {
            if(outerFlag === true) {
                metAnother = true;
            }
            outerFlag = true;
        } else if (shelfArr[i] == 0 && outerFlag === true) {
            movesSum++;
        }
    }
    if (!metAnother) {
        movesSum = 0;
    }
    console.log(movesSum);
}

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.question("", loop =>{
  getUserInput(loop);
})

function totalPressedDigit(number){
    let digit = number[0];
    let length = number.length;
    console.log( (digit-1) * 10 + length*(length+1)/2);
}

function getUserInput(n) {
    rl.question('', (number) => {
        rl.question("", number => {
            let fi = number.indexOf("1");
            let li = number.lastIndexOf("1");
            number = number.substring(fi,li);
            let arr = number.split(" ");
            console.log(countZeros(arr));
            if (n > 1) {
                getUserInput(n-1);
            } else {
                rl.close();
            }
        })

    });
}

function countZeros(arr){
    let count = 0;
    for (let index = 0; index < arr.length; index++) {
        if(arr[index] == 0)
            ++count;
    }
    return count;
}

rl.on("close", function() {
    console.log("\nBYE BYE !!!");
    process.exit(0);
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    var x = readline();
   // var y = readline(); // first line of input usually gives the no. of test cases,i.e, the no. of lines ahead.
   // var inp; // declaring the variable outside the loop
    for (var i = 0; i < x; i++) {
        var y = readline();
        let inp = readline().split(" ");
        console.log(foo(inp))
    }

}

function foo(digit){

    let count = 0;
    let firstIndex = digit.indexOf("1");
    let secondIndex = digit.lastIndexOf(`1`);
    let max = firstIndex
    for(let i =0; i < digit.length; i++){
      if(digit[i] ==1 && i !== secondIndex){
          max = Math.max(i,max)
      }
    }

    if(firstIndex == secondIndex){
        return 0;
    }
    if(firstIndex == max){
        return secondIndex - max -1;
    }
 //   console.log(max,firstIndex,secondIndex)
    return secondIndex - max;

}

var problem = function(arr) {

    var count = 0, first = arr.indexOf('1'), last = arr.lastIndexOf('1'), a = arr.slice(first, last);
    for (var i = 0; i < arr.length; i++) {
        if (a[i] == 1) count++;
    }
    return (a.length - count);

}

var tests = readline();

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

        var n, items;
        //n = readline();
        items = readline().split(" ");
        print(problem(items));

}


You are given an array $$$a$$$ consisting of $$$n$$$ integers.Your task is to say the number of such positive integers $$$x$$$ such that $$$x$$$ divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.For example, if the array $$$a$$$ will be $$$[2, 4, 6, 2, 10]$$$, then $$$1$$$ and $$$2$$$ divide each number from the array (so the answer for this test is $$$2$$$).

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 4 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the number of such positive integers $$$x$$$ such that $$$x$$$ divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).

if (process.env.ANT)
{
    global.print = this.print ||
        function(){console.log([...arguments].join(' '))} ||
        require('lol-io').print;
    global.write = this.write || require('lol-io').write
    global.readline = this.readline || require('lol-io').readline
    main();
}
else
{
    const rl = require('readline').createInterface({ input: process.stdin,
        output: process.stdout });
    global.print = console.log
    global.write = (...args) => {
        process.stdout.write(args.join(' '));
    }
    const lines = []
    rl.on('line', line =>{
        lines.push(line);
    });
    rl.on('close', main)
    let rli = 0;
    global.readline = ()=>lines[rli++];
}

///////////// CODE

function main(){

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

    function gcd(a, b){
        if (a%b==0)
            return b;
        return gcd(b, a%b);
    }
    let g = arr[0];

    for (let i=1; i<arr.length; i++)
        g = gcd(g, arr[i]);

    const sqrt = Math.sqrt(g)|0;
    let ans = 0;
    for (i=1; i<=sqrt; i++)
    {
        if (g%i)
            continue;
        ans++;
        if (g/i!=i)
            ans++;
    }

    print(ans)

}

'use strict'

const gcd = (a,b) => {
    let c;
    if (a < b) { c = b; b = a; a = c; }
    while(b) { c = b; b = a % b; a = c; }
    return a;
};

readline();
const x = readline().split(' ').map(Number);
const m = x.slice(1).reduce((r, i) => gcd(r, i), x[0]);
const mRoot = Math.floor(Math.sqrt(m));
let r = 1;
for (let i = 2; i < mRoot + 1; i++) { if (m % i === 0) r++; }
write(2 * r - +(Math.pow(mRoot, 2) === m));

if (process.env.ANT)
{
    global.print = this.print ||
        function(){console.log([...arguments].join(' '))} ||
        require('lol-io').print;
    global.write = this.write || require('lol-io').write
    global.readline = this.readline || require('lol-io').readline
    main();
}
else
{
    const rl = require('readline').createInterface({ input: process.stdin,
        output: process.stdout });
    global.print = console.log
    global.write = (...args) => {
        process.stdout.write(args.join(' '));
    }
    const lines = []
    rl.on('line', line =>{
        lines.push(line);
    });
    rl.on('close', main)
    let rli = 0;
    global.readline = ()=>lines[rli++];
}

///////////// CODE

function main(){

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

    function gcd(a, b){
        if (b)
            return a%b;
        return a;
    }
    let g = arr[0];

    for (let i=1; i<arr.length; i++)
        g = gcd(g, arr[i]);

    const sqrt = Math.sqrt(g)|0;
    let ans = 0;
    for (i=1; i<=sqrt; i++)
    {
        if (g%i)
            continue;
        ans++;
        if (g/i!=i)
            ans++;
    }

    print(ans)

}

'use strict'

const gcd = (a,b) => {
    let c;
    if (a < b) { c = b; b = a; a = c; }
    while(b) { c = b; b = a % b; a = c; }
    return a;
};

readline();
const x = readline().split(' ').map(Number);
const m = x.slice(1).reduce((r, i) => gcd(r, i), x[0]);
let r = 1;
const mRoot = Math.floor(Math.sqrt(m));
for (let i = 2; i < mRoot + 1; i++) { if (m % i === 0) r++; }
write(2 * r - +(Math.pow(mRoot, 2) === r)) ;

'use strict'

const gcd = (a,b) => {
    let c;
    if (a < b) { c = b; b = a; a = c; }
    while(b) { c = b; b = a % b; a = c; }
    return a;
};

readline();
const x = readline().split(' ').map(Number);
const m = x.slice(1).reduce((r, i) => gcd(r, i), x[0]);
let r = 0;
for (let i = 1; i < Math.sqrt(m) + 1; i++) { if (m % i === 0) r++; }
write(2 * r - +(Math.pow(Math.floor(Math.sqrt(r)), 2) === r)) ;