You are given an integer $$$k$$$ and a string $$$s$$$ that consists only of characters 'a' (a lowercase Latin letter) and '*' (an asterisk).Each asterisk should be replaced with several (from $$$0$$$ to $$$k$$$ inclusive) lowercase Latin letters 'b'. Different asterisk can be replaced with different counts of letter 'b'.The result of the replacement is called a BA-string.Two strings $$$a$$$ and $$$b$$$ are different if they either have different lengths or there exists such a position $$$i$$$ that $$$a_i \neq b_i$$$.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:   $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$. Now consider all different BA-strings and find the $$$x$$$-th lexicographically smallest of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of testcases. The first line of each testcase contains three integers $$$n$$$, $$$k$$$ and $$$x$$$ ($$$1 \le n \le 2000$$$; $$$0 \le k \le 2000$$$; $$$1 \le x \le 10^{18}$$$). $$$n$$$ is the length of string $$$s$$$. The second line of each testcase is a string $$$s$$$. It consists of $$$n$$$ characters, each of them is either 'a' (a lowercase Latin letter) or '*' (an asterisk). The sum of $$$n$$$ over all testcases doesn't exceed $$$2000$$$. For each testcase $$$x$$$ doesn't exceed the total number of different BA-strings. String $$$s$$$ contains at least one character 'a'.

For each testcase, print a single string, consisting only of characters 'b' and 'a' (lowercase Latin letters) — the $$$x$$$-th lexicographically smallest BA-string.

NoteIn the first testcase of the example, BA-strings ordered lexicographically are:   a  ab  abb  abbb  abbbb In the second testcase of the example, BA-strings ordered lexicographically are:   aa  aba  abba Note that string "aba" is only counted once, even though there are two ways to replace asterisks with characters 'b' to get it.

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

//can't trust js, but let's see what it got
//sad calculations
function solve() {
    let [n, k, x] = readLine().split(" ").map(BigInt);
    n = Number(n);
    let s = readLine();
    let arr = [];
    arr.push([s[0], 1]);
    for (let i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) {
            arr[arr.length - 1][1]++;
        } else {
            arr.push([s[i], 1]);
        }
    }
    n = arr.length;
    let suffix = new Array(n + 1).fill(BigInt(0));
    suffix[n] = 1n;
    for (let i = n - 1; i >= 0; i--) {
        suffix[i] = suffix[i + 1];
        if (arr[i][0] == "*") {
            let nax = arr[i][1] * Number(k);
            for (let j = 0; j < nax; j++) {
                suffix[i] += suffix[i + 1];
            }
        }
    }
    let ans = "";
    for (let i = 0; i < n; i++) {
        if (arr[i][0] == "a") {
            ans += "a".repeat(arr[i][1]);
        } else {
            let nax = arr[i][1] * Number(k);
            for (let j = 0; j < nax; j++) {
                // ans += x + " ";
                if (x <= suffix[i + 1]) {
                    break;
                }
                ans += "b";
                x -= suffix[i + 1];
            }
        }
    }

    console.log(ans);
}
function main() {
    var t = +readLine();
    while (t--) {
        solve();
    }
}

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

//can't trust js, but let's see what it got

function solve() {
    let [n, k, x] = readLine().split(" ").map(BigInt);
    n = Number(n);
    let s = readLine();
    let arr = [];
    arr.push([s[0], 1]);
    for (let i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) {
            arr[arr.length - 1][1]++;
        } else {
            arr.push([s[i], 1]);
        }
    }
    n = arr.length;
    let suffix = new Array(n + 1).fill(BigInt(0));
    suffix[n] = BigInt(1);

    for (let i = n - 1; i >= 0; i--) {
        suffix[i] = suffix[i + 1];
        if (arr[i][0] == "*") {
            suffix[i] += BigInt(arr[i][1]) * (k + 1n);
        }
    }
    let ans = "";
    for (let i = 0; i < n; i++) {
        if (arr[i][0] == "a") {
            ans += "a".repeat(arr[i][1]);
        } else {
            let nax = arr[i][1] * Number(k);
            for (let j = 0; j < nax; j++) {
                if (x <= suffix[i + 1]) {
                    break;
                }
                ans += "b";
                x -= suffix[i + 1];
            }
        }
    }

    console.log(ans);
}

function main() {
    var t = +readLine();
    while (t--) {
        solve();
    }
}

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

//can't trust js, but let's see what it got

function solve() {
    let [n, k, x] = readLine().split(" ").map(BigInt);
    n = Number(n);
    let s = readLine();
    let arr = [];
    arr.push([s[0], 1]);
    for (let i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) {
            arr[arr.length - 1][1]++;
        } else {
            arr.push([s[i], 1]);
        }
    }
    n = arr.length;
    let suffix = new Array(n + 1).fill(BigInt(0));
    suffix[n] = BigInt(1);

    for (let i = n - 1; i >= 0; i--) {
        suffix[i] += suffix[i + 1];
        if (arr[i][0] == "*") {
            suffix[i] += BigInt(arr[i][1]) * k;
        }
    }

    let ans = "";

    for (let i = 0; i < n; i++) {
        if (arr[i][0] == "a") {
            ans += "a".repeat(arr[i][1]);
        } else {
            let nax = arr[i][1] * Number(k);
            for (let j = 0; j < nax; j++) {
                if (x <= suffix[i + 1]) {
                    break;
                }
                ans += "b";
                x -= suffix[i + 1];
            }
        }
    }

    console.log(ans);
}

function main() {
    var t = +readLine();
    while (t--) {
        solve();
    }
}


Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $$$s$$$ of length $$$n$$$ and $$$t$$$ of length $$$m$$$.A sequence $$$p_1, p_2, \ldots, p_m$$$, where $$$1 \leq p_1 < p_2 < \ldots < p_m \leq n$$$, is called beautiful, if $$$s_{p_i} = t_i$$$ for all $$$i$$$ from $$$1$$$ to $$$m$$$. The width of a sequence is defined as $$$\max\limits_{1 \le i < m} \left(p_{i + 1} - p_i\right)$$$.Please help your classmate to identify the beautiful sequence with the maximum width. Your classmate promised you that for the given strings $$$s$$$ and $$$t$$$ there is at least one beautiful sequence.

The first input line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq m \leq n \leq 2 \cdot 10^5$$$) — the lengths of the strings $$$s$$$ and $$$t$$$. The following line contains a single string $$$s$$$ of length $$$n$$$, consisting of lowercase letters of the Latin alphabet. The last line contains a single string $$$t$$$ of length $$$m$$$, consisting of lowercase letters of the Latin alphabet. It is guaranteed that there is at least one beautiful sequence for the given strings.

Output one integer — the maximum width of a beautiful sequence.

NoteIn the first example there are two beautiful sequences of width $$$3$$$: they are $$$\{1, 2, 5\}$$$ and $$$\{1, 4, 5\}$$$.In the second example the beautiful sequence with the maximum width is $$$\{1, 5\}$$$.In the third example there is exactly one beautiful sequence — it is $$$\{1, 2, 3, 4, 5\}$$$.In the fourth example there is exactly one beautiful sequence — it is $$$\{1, 2\}$$$.

'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 n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        pos1[i] = j
        j++
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        pos2[i] = j
        j--

    }
    var max = 1
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

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

process.stdin.on('end', () => {
    const input = text.trim().replace(/\r/g, '').split('\n');
    // const total = +input[0];
    // for (let i = 1; i <= total; i++) {
    //    console.log(solve(input[i]));
    // }
    console.log(solve(input[1], input[2]));
    process.exit();
});

function solve(a, b) {
    const charArys = new Array(26).fill(0).map(() => []);
    for (let i = 0; i < a.length; i++) {
        const code = a[i].charCodeAt() - 97;
        charArys[code].push(i);
    }

    const pres = new Array(b.length);
    pres[0] = charArys[b[0].charCodeAt() - 97][0];
    for (let i = 1; i < b.length; i++) {
        const ary = charArys[b[i].charCodeAt() - 97];
        const pre = pres[i - 1];
        let left = 0; right = ary.length - 1;
        while (left < right) {
            const mid = (left + right) >> 1;
            if (ary[mid] > pre) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        pres[i] = ary[left];
    }
    const last = b[b.length - 1].charCodeAt() - 97;
    let max = charArys[last].pop();
    let result = max - pres[b.length - 2];
    for (let i = b.length - 2; i; i--) {
        const ary = charArys[b[i].charCodeAt() - 97];
        let left = 0; right = ary.length - 1;
        if (ary[right] < max) {
            left = right;
        } else {
            while (left < right) {
                const mid = (left + right) >> 1;
                if (ary[mid] >= max) {
                    right = mid;
                } else {
                    left = mid + 1;
                }
            }
            left--;
        }
        max = ary[left];
        result = Math.max(result, max - pres[i - 1]);
    }
    return result;
}

'use strict';

function solve(n, m, a, b) {
  const l = new Array(m),
        r = new Array(m);
  for (let i = 0, j = 0; i < n; i++, j++) {
    while (a[i] !== b[j]) i++;
    l[j] = i;
  }
  for (let i = n - 1, j = m - 1; i >= 0; i--, j--) {
    while (a[i] !== b[j]) i--;
    r[j] = i;
  }
  let res = 0;
  for (let i = 0; i < m - 1; i++) {
    res = Math.max(res, r[i + 1] - l[i]);
  }
  return res;
}

async function main(read) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = await read();
      const b = await read();
      res[i] = solve(n, m, a, b);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

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 [n, m] = rna();
	let s = rl();
	let t = rl();

	const lstp = Array(m);
	for (let i = n - 1, j = m - 1; j >= 0; i--) {
		if (s[i] == t[j]) {
			lstp[j--] = i;
		}
	}

	let ans = 0;
	for (let i = 0, j = 0; j < m - 1; i++) {
		if (s[i] == t[j]) {
			ans = Math.max(ans, lstp[j+1] - i);
			j++;
		}
	}

	console.log(ans);
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var N = nextInt();
	var M = nextInt();
	var s = next();
	var t = next();
	var max = 1;
	var kouho = new Array(M);
	var index = 0;
	for(var i = 0; i < N; i++){
		if(s[i] == t[index]){
			kouho[index] = {
				L : i
			};
			index++;
			if(index == M){
				break;
			}
		}
	}
	index--;
	for(var i = N - 1; i >= 0; i--){
		if(s[i] == t[index]){
			kouho[index].R = i;
			index--;
			if(index == -1){
				break;
			}
		}
	}
	//myerr(kouho);
	for(var i = 0; i < M - 1; i++){
		max = Math.max(max, kouho[i + 1].L - kouho[i].L);
	}
	for(var i = M - 1; i > 0; i--){
		max = Math.max(max, kouho[i].R - kouho[i - 1].L);
	}
	myout(max);
}

'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 n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        j++
        pos1[i] = j
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        j--
        pos2[i] = j
    }
    var max = 1
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

'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 n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        pos1[i] = j
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        pos2[i] = j
    }
    var max = 1
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

'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 n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        pos1[i] = j
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        pos2[i] = j
    }
    var max = 0
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

'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 n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        pos1[t[i]] = j
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        pos2[t[i]] = j
    }
    var max = 0
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[t[i+1]] - pos1[t[i]]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

'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 n = readline();

    // Array(Number(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    //
    // var map = {}
    // var [n, a, b, k] = readline().split(' ').map((x, i) => {
    //     return parseInt(x)
    // })

    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var a = readline().split('').map((x, iii) => {
        return x
    })
    var b = readline().split('').map((x, iii) => {
        return x
    })

    var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
    var letterMax = {}
    var letterfirst = {}

    var letterB = {}

    for (let i = 0; i < a.length; i++) {
        if (!letterMax[a[i]]) {
            letterMax[a[i]] = i
            letterfirst[a[i]] = i
        }
        letterMax[a[i]] = i
    }

    for (let i = 0; i < b.length; i++) {
        if (!letterB[b[i]]) {
            letterB[b[i]] = true
        }
    }

    var max = 0
    Object.keys(letterMax).map((key) => {
        if (letterB[key]) {
            max = Math.max(max, letterMax[key] - letterfirst[key])
        }
    })
    // console.log(letterMax)
    // console.log(letterfirst)
    console.log(max+1)

}

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

process.stdin.on('end', () => {
    const input = text.trim().replace(/\r/g, '').split('\n');
    // const total = +input[0];
    // for (let i = 1; i <= total; i++) {
    //    console.log(solve(input[i]));
    // }
    console.log(solve(input[1], input[2]));
    process.exit();
});

function solve(a, b) {
    const charArys = new Array(26).fill(0).map(() => []);
    for (let i = 0; i < a.length; i++) {
        const code = a[i].charCodeAt() - 97;
        charArys[code].push(i);
    }

    const pres = new Array(b.length);
    pres[0] = charArys[b[0].charCodeAt() - 97][0];
    for (let i = 1; i < b.length; i++) {
        const ary = charArys[b[i].charCodeAt() - 97];
        const pre = pres[i - 1];
        let left = 0; right = ary.length - 1;
        while (left < right) {
            const mid = (left + right) >> 1;
            if (ary[mid] > pre) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        pres[i] = ary[left];
    }
    const last = b[b.length - 1].charCodeAt() - 97;
    let max = charArys[last].pop();
    let result = max - pres[b.length - 2];
    for (let i = b.length - 2; i; i--) {
        const ary = charArys[b[i].charCodeAt() - 97];
        let left = 0; right = ary.length - 1;
        if (ary[right] < max) {
            left = right;
        } else {
            while (left < right) {
                const mid = (left + right) >> 1;
                if (ary[mid] > max) {
                    right = mid;
                } else {
                    left = mid + 1;
                }
            }
            left--;
        }
        max = ary[left];
        result = Math.max(result, max - pres[i - 1]);
    }
    return result;
}

'use strict';

function solve(n, m, a, b) {
  const dp = new Array(m);
  for (let i = 0, j = 0; i < n; i++, j++) {
    let t = i,
        t1 = j;
    while (t + 1 < n && a[t + 1] === a[i]) t++;
    while (t1 + 1 < m && b[t1 + 1] === b[t1]) t1++;
    const dif = t - i - (t1 - j);
    for (let k = 0; k <= t1 - j; k++) {
      dp[j + k] = [i + k, i + k + dif];
    }
    i = t;
    j = t1;
  }
  let res = 0;
  for (let i = 0; i < m - 1; i++) {
    res = Math.max(res, dp[i + 1][1] - dp[i][0]);
  }
  return res;
}

async function main(read) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = await read();
      const b = await read();
      res[i] = solve(n, m, a, b);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});


A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet should be odd. Each of the initial bouquets can be a part of at most one large bouquet. If an initial bouquet becomes a part of a large bouquet, all its flowers are included in the large bouquet.Determine the maximum possible number of large bouquets Vasya can make.

The first line contains a single positive integer n (1 ≤ n ≤ 105) — the number of initial bouquets. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the number of flowers in each of the initial bouquets.

Print the maximum number of large bouquets Vasya can make.

NoteIn the first example Vasya can make 2 large bouquets. For example, the first bouquet can contain the first and the fifth initial bouquets (the total number of flowers is then equal to 9), and the second bouquet can consist of the second and the third initial bouquets (the total number of flowers is then equal to 7). The fourth initial bouquet is unused in this scheme. In the second example it is not possible to form a single bouquet with odd number of flowers.In the third example Vasya can make one large bouquet. For example, he can make it using all three initial bouquets. The size of the large bouquet is then equal to 11 + 4 + 10 = 25.

    var n = readline();
    var b = readline().split(' ');
    var o = 0, e = 0;
    for (var i = 0; i < n; i ++){
        if (b[i] % 2 == 1) o ++;
        else e ++;
    }
    if (o < e)
        print(o);
    else{
        var ans = e;
        o -= e;
        ans += Math.trunc(o/3);
        print(ans);

    }

var n = readline().split(" ").map(v => +v.trim())[0];
var arr = readline().split(" ").map(v => +v.trim());
var cnt0 = 0;
var cnt1 = 0;
for (var i = 0; i < n; i++){
    var el = arr[i]
	if (el % 2 === 0){
		cnt0++;
	}
	else{
		cnt1++;
	}
}
//print(arr)

if (cnt0 > cnt1){
	print(cnt1);
}
else{
    //print(cnt1 - cnt0)
    //print(parseInt((cnt1 - cnt0) / 3))
	print(cnt0 + parseInt((cnt1 - cnt0) / 3))
}

var nk = readline().split(' ').map(v => +v.trim());
var n = nk[0];
var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < n; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
} else {
  ans += even;
  odd -= even;

  ans += Math.floor(odd / 3);

  print(ans);
}

var nn = readline();
var n = parseInt(nn, 10);
var a = readline().split(" ");
var even = 0;
var odd = 0;
for (var i = 0; i < n; ++i) {
    var cur = parseInt(a[i], 10);
    if (cur % 2 === 0) {
        ++even;
    }
    else {
        ++odd;
    }
}
var ans = 0;
if (even >= odd) {
    ans = odd;
}
else {
    ans = even + ((odd - even) / 3);
}
ans = Math.floor(ans);
print(ans);

var now=readline().split(' ').map(function(v){return +v;});
var n=now[0];
var num=readline().split(' ').map(function(v){return +v;});
var i=0;
var cnto=0,cnte=0;
while(i<n) {
    if(num[i]%2==1)
        cnto=cnto+1;
    else
        cnte=cnte+1;
    i++;
}
var ans=0;
if(cnto<cnte)
    ans=cnto;
else
    ans=cnte+Math.floor((cnto-cnte)/3);
print(ans);

//var print = require('lol-io').print
//var readline = require('lol-io').readline
var n = parseInt(readline());
var t = readline().split(' ');
var a = [];
var odd = 0;
var even = 0;
for (var i=0;i<n;i++){
    a.push(parseInt(t[i]));
}
for (var i=0;i<n;i++){
    if (a[i]%2==0){
        even++;
    }
    else {
        odd++;
    }
}
if (even > odd){
    print(odd);
}
else {
    var ans = even;
    odd -= even;
    print(ans + parseInt(odd / 3));
}

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

var x = 0;
var y = 0;
for(var i = 0; i < n; i++) {
    if (arr[i] % 2 == 0) x++; else y++;
}

var res = 0;
if (x > y) res = y;
else {
    res = x;
    y = y - x;
    res = res + Math.floor(y/3);
}

print(res);

const firstLine = readline();
const n = firstLine.split(' ')[0];
var arr = readline().split(" ").map(v => +v.trim());

var ctn = 0;
var ctch = 0;
for(var i = 0; i < n; i++){
    if (arr[i] % 2 === 0)
    	ctch++;
    else ctn++;
}
// print(ctch);
// print(ctn);
var k = 0;
if (ctch <= ctn)
k = ctch;
else k = ctn;
ctch -= k;
ctn -= k;
var min = 0;
if (ctn % 3 >= parseInt(ctch / 2))
min = parseInt(ctch / 2);
else min = ctn % 3;
var ans1 = parseInt(ctn / 3) + min;
if (parseInt(ctch / 2) > ctn)
min = ctn;
else min = parseInt(ctch / 2);
var ans2 = min;
if (ctn - ans2 > 0)
ans2 += parseInt((ctn - ans2) / 3);

if (ans1 > ans2)
k += ans1;
else k += ans2;
print(k);

ns = readline().split(' ')
n = parseInt(ns[0], 10);

fl = readline().split(' ')

ev = 0
odd = 0

for (i = 0; i < n; ++i)
{
	if (parseInt(fl[i], 10) % 2 === 0)
		++ev;
	else
		++odd;
}

if (ev >= odd)
{
	ans = odd;
}
else
{

	ans = ev + Math.floor((odd - ev) / 3);
}

print(ans)

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

var odd = 0;
var even = 0;

for (var i = 0; i < n; i++)
{
	if(a[i] % 2 === 0)
		even += 1;
	else
		odd += 1;
}

if (even > odd)
	print(odd);
else
	print(even + parseInt((odd - even)/3));

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
var hlp=(ans2-ans1)-(ans2-ans1)%3;
hlp=hlp/3;
if(ans1>ans2)
print(ans2);
else print(ans1+hlp);

var n = readline();
var chet = 0 , nechet = 0 , maxx=0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0; i < n; i++){
    if (arr[i]%2 === 0){
        chet++;
    }else{
        nechet++;
    }
}
if (chet>=nechet){
    print(nechet);
}else{
    if (nechet===1){
        print(0);
    }else{
        while (chet<nechet){
            if (chet>maxx)maxx=chet;
            chet++;
            nechet-=2;
        }
    if (nechet>maxx)maxx=nechet;
    print(maxx);
    }
}

var L = readline().split(' ');
var n = parseInt(L[0]);
var arr = readline().split(' ');
var ans = 0, k  = 0;
for(var i = 0;i < n;i++){
  if(parseInt(arr[i])%2 === 1) ans++;
  else k++;
}
if(k > ans) print(ans);
else{
    var d = k;
    d += ((ans-k) - ((ans-k)%3))/3;
    print(d);
}

var arr = readline().split(" ").map(v => +v.trim());
var n = arr[0];
var a = readline().split(" ").map(v => +v.trim());
kch=0
knch=0
for (var i=0;i<n;i++){
    if (a[i]%2===0){
        kch++;
    }
    else{
        knch++;
    }
}
if (knch<kch){
    print(knch);
}
else{
    print(kch+Math.floor((knch-kch)/3));
}

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

var nc = 0;

for(var i = 0; i < n; i++){
    nc += (arr[i] % 2 == 1);
}

var c = n - nc;
var t = nc - c;
if (t <= 0)
{
    print(nc);
}
else
{
    print(c + Math.floor(t / 3));
}

var a = [];
var n = readline();
a = readline().split(" ");
var num0s = 0;
var num1s = 0;
for (var i = 0; i < n; i++) {
    if (a[i] % 2 === 0) {
        num0s++;
    }
    else {
        num1s++;
    }
}

var ans = Math.min(num0s,num1s);
num1s -= ans;
ans += Math.floor(num1s/3);
print(ans);

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

var odd = 0;
var even = 0;
for(var i = 0; i < a; i++) {
	if(Number(b[i])%2===0)
	{
		even++;
	}else odd ++;

}
var ans = 0;
while(odd>0)
{
	if(even>0)
	{
		even--;
		odd--;
		ans ++;
		continue;
	}
	else{
		if(odd == 1)
		{
			//ans--;
			break;
		}
		if(odd == 2)
		{
			break;
		}
		odd-=3;
		ans++;
	}

}
if(ans<0)ans = 0;
print(ans)

n=readline().split(' ').map(Number);
a=readline().split(' ').map(Number);
k=0;
for(i=0;i<n;i++) if (a[i]%2==0) k++;
z=n-k;
if (k>z){
	print(z);
}else{
	print(k+Math.floor((z-k)/3));
}

n = readline().split(' ').map(Number);
str = readline().split(' ').map(Number);

var i=0,ans=0;
while(i<n){
	if(str[i]%2==1){
		ans++;
	}
	i++
}
if(ans>n-ans){
	var tot=ans-(n-ans);
	tot-=tot%3;
	ans=(n-ans)+tot/3;
}
print(ans)

var arr = readline().split(" ").map(v => +v.trim());

arr1 = readline().split(" ").map(v => +v.trim());
var c_ch = 0, c_n = 0;
for (var i = 0; i < arr1.length; ++i) {
    if (arr1[i] % 2 === 0) {
        c_ch++;
    } else {
        c_n++;
    }
}
if (c_ch < c_n) {
    print(c_ch + (c_n - c_ch - ((c_n - c_ch) % 3)) / 3);
} else {
    print(c_n);
}

var n = parseInt(readline());
var a = readline().split(' ').map(x => parseInt(x));
var odd = 0, evn = 0;
for (var x of a) {
    if (x % 2 == 1)
        odd++;
    else
        evn++;
}
var ans = 0;
while (odd > 0 && evn > 0) ans++, odd--, evn--;
while (odd > 2) ans++, odd -= 3;
print(ans);

n=readline();
//print(n);
x=readline().split(' ');
imp=0;
pai=0;
for (i = 0; i < n; i++) {
    imp+=(x[i]%2)?1:0;
    pai+=(1-x[i]%2)?1:0;
}
print(Math.min(imp,pai)+Math.floor(Math.max(imp-pai,0)/3));

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

var odd = 0, even = 0;
bouquets.forEach(flour => {
    if(flour % 2 == 1) odd++;
    else even++;
});

var ans = Math.min(odd, even);
if(odd > ans) {
    ans += Math.floor((odd - ans) / 3);
}
print(ans);

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

var p = 0
var np = 0

for(var i = 0; i < n; ++i) {
    if(v[i] % 2 === 0) {
        ++p
    } else {
        ++np
    }
}

var ans = p
if(ans > np) {
    ans = np
}

np = np - ans;
ans = ans + Math.floor(np / 3)
print(ans)

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
	if(arr[i] & 1)	odd++;
	else even++;
}

if(odd > even){
      odd -= even;
      var ans = even + Math.floor (odd / 3);
	print(ans);
}else	print(odd);

// your code goes here
var n = parseInt(readline());
var arr = readline().split(' ');
var odd =0;
var even=0;
for (var i =0;i<n;++i){
	odd+=(parseInt(arr[i])%2)!==0;
	even+=(parseInt(arr[i])%2)===0;
}
var ans =0;
if (even >= odd){
	ans = odd;
}
else {
	ans = even ;
	odd -=even;
	var x  = odd %3;
	ans += Math.floor(odd/3);

}
print(ans)

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

var o = 0;
var e = 0;
for(var i = 0 ; i < n ; i++) {
    if(arr[i] % 2 === 0) {
        e++;
    }
    else {
        o++;
    }
}

var ans = 0;
    if(o <= e) {
        ans = o;
    }
    else {
        ans = e;
        ans = ans + Math.floor((o - e) / 3);
    }

    print(ans);

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

for (var i = 1; i <= n; i++){
   var x = arr[i - 1];
   if(x % 2 == 1)a += 1;
}
var b = n - a;

if(a <= b)print(a);
else {
	var ans = b;
	x = (a - b) - (a - b)%3;
	ans += x/3;
	print(ans);
}

const n = readline();
const input = readline();
const arr = input.split(' ');

var odd = 0;
var even = 0;

for(var i = 0; i < n; i++) {
    if(arr[i]%2) {
        odd++;
    } else {
        even++;
    }
}
var ans = 0;
if(odd >= even) {
    odd-= even;
    ans = even;
    ans+= ((odd-odd%3)/3);
} else {
    ans = odd;
}
print(ans)

var n = parseInt(readline());
var a = readline().split(" ");

var i = 0;
var odd = 0;
for (; i < n; ++i)
  if (parseInt(a[i]) % 2 != 0)
    ++odd;

var even = n - odd;
if (even >= odd)
  print(odd);
else
  print(even + Math.floor((odd - even) / 3)); // lol, js divides it as float

function main() {
    // write your code here.
    // call functions `nextString`, `nextFloat` and `nextInt`
    // to read the next token of input (ignoring whitespace)
    // Alternatively, you can create your own input parser functions
    // use console.log() to write to stdout

    var n = readline();
    var b = readline().split(' ');
    var o = 0, e = 0;
    for (var i = 0; i < n; i ++){
        if (b[i] % 2 == 1) o ++;
        else e ++;
    }
    if (o < e)
        print(o);
    else
        print(e);
}

// default parsers for JS.
function nextInt() {
    return parseInt(nextString());
}

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

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

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

//process.stdin.resume();
//process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_cursor = 0;
//process.stdin.on('data', function (data) { input_stdin += data; });
//process.stdin.on('end', function () { main(); });

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

function clearWhitespaces() {
    while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) {
        // ignore the next whitespace character
        input_cursor += 1;
    }
}

main();

readline()
var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < arr.length; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
} else {
  ans += even;
  odd -= even;

  ans += Math.floor(odd / 2);

  print(ans);
}

var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < arr.length; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
  process.exit(0);
} else {
  ans += even;
  odd -= even;
}

ans += Math.floor(even / 2);

print('' + ans);

var nk = readline().split(' ').map(v => +v.trim());
var n = nk[0];
var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < n; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
} else {
  ans += even;
  odd -= even;

  ans += Math.floor(odd / 2);

  print(ans);
}

readline()
var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < arr.length; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
} else {
  ans += even;
  odd -= even;

  ans += Math.floor(even / 2);

  print(ans);
}

const firstLine = readline();
const n = firstLine.split(' ')[0];
var arr = readline().split(" ").map(v => +v.trim());

var ctn = 0;
var ctch = 0;
for(var i = 0; i < n; i++){
    if (arr[i] % 2 === 0)
    	ctch++;
    else ctn++;
}
// print(ctch);
// print(ctn);
var k = 0;
if (ctch <= ctn)
k = ctch;
else k = ctn;
ctch -= k;
ctn -= k;
var min = 0;
if (ctn % 3 >= ctch / 2)
min = ctch / 2;
else min = ctn % 3;
var ans1 = ctn / 3 + min;
if (ctch / 2 > ctn)
min = ctn;
else min = ctch / 2;
var ans2 = min;
if (ctn - ans2 > 0)
ans2 += (ctn - ans2) / 3;

if (ans1 > ans2)
k += ans1;
else k += ans2;
print(k);

ns = readline().split(' ')
n = parseInt(ns[0], 10);

fl = readline().split(' ')

ev = 0
odd = 0

for (i = 0; i < n; ++i)
{
	if (parseInt(fl[i], 10) % 2 === 0)
		++ev;
	else
		++odd;
}

if (ev > odd)
	ans = odd;
else
	ans = ev;

print(ans)

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

var odd = 0;
var even = 0;

for (var i = 0; i < n; i++)
{
	if(a[i] % 2 === 0)
		even += 1;
	else
		odd += 1;
}

if (odd > even)
	print(even);
else
	print(odd);

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
var hlp=(ans1-ans2)-(ans1-ans2)%3;
hlp=hlp/3;
if(ans1>ans2)
print(ans2+hlp);
else print(ans1);

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
if(ans1>ans2)
print(ans2+(ans1-ans2)/3);
else print(ans1);

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
if(ans1>ans2)
print(ans2);
else print(ans1);

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
if(ans1>ans2)
print(ans2+((ans1-ans2)/3));
else print(ans1);

var n = readline();
var chet = 0 , nechet = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0; i < n; i++){
    if (arr[i]%2 === 0){
        chet++;
    }else{
        nechet++;
    }
}
if (chet>nechet){
    print(nechet);
}else{
    if (nechet===1){
        print(0);
    }else{
        while (chet<nechet){
            chet++;
            nechet-=2;
        }
    print(nechet);
    }
}

var n = readline();
var chet = 0 , nechet = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0; i < n; i++){
    if (arr[i]%2 === 0){
        chet++;
    }else{
        nechet++;
    }
}
if (chet>=nechet){
    print(nechet);
}else{
    if (nechet===1){
        print(0);
    }else{
        while (chet<nechet){
            chet++;
            nechet-=2;
        }
    print(nechet);
    }
}

var n = readline();
var chet = 0 , nechet = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0; i < n; i++){
    if (arr[i]%2 === 0){
        chet++;
    }else{
        nechet++;
    }
}
if (chet>nechet){
    print(nechet);
}else{
    while (chet<nechet){
        chet++;
        nechet-=2;
    }
    print(nechet)
}

var L = readline().split(' ');
var n = parseInt(L[0]);
var arr = readline().split(' ');
var ans = 0;
for(var i = 0;i < n;i++){
  if(parseInt(arr[i])%2 === 1) ans++;
}
print(ans);

var arr = readline().split(" ").map(v => +v.trim());
var n = arr[0];
var a = readline().split(" ").map(v => +v.trim());
kch=0
knch=0
for (var i=0;i<n;i++){
    if (a[i]%2===0){
        kch++;
    }
    else{
        knch++;
    }
}
if (knch<kch){
    print(knch);
}
else{
    print(kch+(knch-kch)/3);
}

var now=readline().split(' ').map(function(v){return +v;});
var n=now[0];
var num=readline().split(' ').map(function(v){return +v;});
var i=0;
var cnto=0,cnte=0;
while(i<n) {
    if(num[i]%2==1) {
        cnto=cnto+1;
    }
    else {
        cnte=cnte+1;
    }
    i++;
}
var ans=0;
if(cnto<cnte)
    ans=cnto;
else
    ans=cnte;
print(ans);

var now=readline().split(' ').map(function(v){return +v;});
var n=now[0];
var num=readline().split(' ').map(function(v){return +v;});
var i=0;
var cnto=0,cnte=0;
while(i<n) {
    if(num[i]%2==1)
        cnto=cnto+1;
    else
        cnte=cnte+1;
    i++;
}
var ans=0;
if(cnto<cnte)
    ans=cnto;
else
    ans=cnte+(cnto-cnte)/3;
print(ans);

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

var nc = 0;

for(var i = 0; i < n; i++){
    nc += (arr[i] % 2 == 1);
}

var c = n - nc;
var t = nc - c;
if (t <= 0)
{
    print(nc);
}
else
{
    print(c + Math.floor(t / 3));
}

var a = [];
var n = readline();
a = readline().split(" ");
var num0s = 0;
var num1s = 0;
for (var i = 0; i < n; i++) {
    if (a[i] % 2 === 0) {
        num0s++;
    }
    else {
        num1s++;
    }
}

var ans = Math.min(num0s,num1s);
num1s -= ans;
ans += Math.floor(num1s/2);
print(ans);

var a = [];
var n = readline();
a = readline().split(" ");
var num0s = 0;
var num1s = 0;
for (var i = 0; i < n; i++) {
    if (a[i] % 2 === 0) {
        num0s++;
    }
    else {
        num1s++;
    }
}
print(Math.min(num0s,num1s));

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

var odd = 0;
var even = 0;
for(var i = 0; i < a; i++) {
	if(Number(b[i])%2===0)
	{
		even++;
	}else odd ++;

}
var ans = 0;
while(odd>0)
{
	if(even>0)
	{
		even--;
		odd--;
		ans ++;
		continue;
	}
	else{
		if(odd == 1)
		{
			ans--;
			break;
		}
		if(odd == 2)
		{
			break;
		}
		odd-=3;
		ans++;
	}

}
if(ans<0)ans = 0;
print(ans)

n = readline().split(' ').map(Number);
str = readline().split(' ').map(Number);

var i=0,ans=0;
while(i<n){
	if(str[i]%2==1){
		ans++;
	}
	i++
}
if(ans>n-ans){
	var tot=ans-(n-ans);
	tot-=tot%3;
	ans+=tot/3;
}
print(ans)

n = readline().split(' ').map(Number);
str = readline().split(' ').map(Number);

var i=0,ans=0;
while(i<n){
	if(str[i]%2==1){
		ans++;
	}
	i++
}
print(ans)

n=readline();
//print(n);
x=readline().split(' ');
imp=0;
pai=0;
for (i = 0; i < n; i++) {
    imp+=(x[i]%2)?1:0;
    pai+=(1-x[i]%2)?1:0;
}
print(Math.min(imp,pai));

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

var odd = 0, even = 0;
bouquets.forEach(flour => {
    if(flour % 2 == 1) odd++;
    else even++;
});

print(Math.min(odd, even));

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

var p = 0
var np = 0

for(var i = 0; i < n; ++i) {
    if(v[i] % 2 === 0) {
        ++p
    } else {
        ++np
    }
}

var ans = p
if(ans > np) {
    ans = np
}

print(ans)

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
    //  print(arr[i] + " ");
	if(arr[i] & 1)	odd++;
	else even++;
}
//print(n + "\n");
if(odd > even){
      var ans = even + (odd - even) / 2;
	print(ans);
}else	print(odd);

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
	if(arr[i] & 1)	odd++;
	else even++;
}

if(odd > even){
      odd -= even;
      var ans = even + odd / 3;
	print(ans);
}else	print(odd);

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
	if(arr[i] & 1)	odd++;
	else even++;
}
if(odd > even){
	odd -= even;
	var ans = even + odd / 2;
	print(ans);
}else	print(odd);

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
    //  print(arr[i] + " ");
	if(arr[i] & 1)	odd++;
	else even++;
}
//print(n + "\n");
if(odd > even){
      var ans = even + (odd - even) / 3;
	print(ans);
}else	print(odd);

// your code goes here
var n = parseInt(readline());
var arr = readline().split(' ');
var odd =0;
var even=0;
for (var i =0;i<n;++i){
	odd+=(parseInt(arr[i])%2)!==0;
	even+=(parseInt(arr[i])%2)===0;
}
var ans =0;
if (even >= odd){
	ans = odd;
}
else {
	ans = even ;
	odd -=even;
	var x  = odd %3;
	ans += (odd/3);
	if (x===1 && ans !==0)ans --;

}
print(ans)

// your code goes here
var n = parseInt(readline());
var arr = readline().split(' ');
var odd =0;
var even=0;
for (var i =0;i<n;++i){
	odd+=(parseInt(arr[i])%2)!==0;
	even+=(parseInt(arr[i])%2)===0;
}
var ans =0;
if (even >= odd){
	ans = odd;
}
else {
	ans = even ;
	odd -=even;
	var x  = odd %3;
	ans += Math.floor(odd/3);
	if (x==1 && ans !==0)ans --;

}
print(ans)

// your code goes here
var n = parseInt(readline());
var arr = readline().split(' ');
var odd =0;
var even=0;
for (var i =0;i<n;++i){
	odd+=(parseInt(arr[i])%2)!==0;
	even+=(parseInt(arr[i])%2)===0;
}
var ans =0;
if (even >= odd){
	ans = odd;
}
else {
	ans = even ;
	odd -=even;
	var x  = odd %3;
	ans += Math.floor(odd/3);
	if (x===1 && ans !==0)ans --;

}
print(ans)

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

var o = 0;
var e = 0;
for(var i = 0 ; i < n ; i++) {
    if(arr[i] % 2 === 0) {
        e++;
    }
    else {
        o++;
    }
}

var ans = 0;
    if(o <= e) {
        ans = o;
    }
    else {
        ans = e;
        anss = ans + (o - e) / 3;
    }

    print(ans);

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

for (var i = 1; i <= n; i++){
   var x = arr[i - 1];
   if(x % 2 == 1)a += 1;
}
var b = n - a;

if(a <= b)print(a);
else {
	var ans = b;
	ans += (a - b)/3;
	print(ans);
}

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

for (var i = 1; i <= n; i++){
   var x = arr[i - 1];
   if(x % 2 == 1)a += 1;
}
var b = n - a;

if(a <= b)print(a);
else {
	var ans = b;
	ans += (a - b) - (a - b)%3;
	print(ans);
}

var n = parseInt(readline());
var a = readline().split(" ");

var i = 0;
var odd = 0;
for (; i < n; ++i)
  if (parseInt(a[i]) % 2 != 0)
    ++odd;

var even = n - odd;
if (even >= odd)
  print(odd);
else
  print(even + (odd - even) / 3);


This is the easy version of the problem. The difference between versions is the constraints on $$$n$$$ and $$$a_i$$$. You can make hacks only if all versions of the problem are solved.First, Aoi came up with the following idea for the competitive programming problem:Yuzu is a girl who collecting candies. Originally, she has $$$x$$$ candies. There are also $$$n$$$ enemies numbered with integers from $$$1$$$ to $$$n$$$. Enemy $$$i$$$ has $$$a_i$$$ candies.Yuzu is going to determine a permutation $$$P$$$. A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$\{2,3,1,5,4\}$$$ is a permutation, but $$$\{1,2,2\}$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$\{1,3,4\}$$$ is also not a permutation (because $$$n=3$$$ but there is the number $$$4$$$ in the array).After that, she will do $$$n$$$ duels with the enemies with the following rules:  If Yuzu has equal or more number of candies than enemy $$$P_i$$$, she wins the duel and gets $$$1$$$ candy. Otherwise, she loses the duel and gets nothing.  The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $$$P$$$ exist?This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea:Let's define $$$f(x)$$$ as the number of valid permutations for the integer $$$x$$$.You are given $$$n$$$, $$$a$$$ and a prime number $$$p \le n$$$. Let's call a positive integer $$$x$$$ good, if the value $$$f(x)$$$ is not divisible by $$$p$$$. Find all good integers $$$x$$$.Your task is to solve this problem made by Akari.

The first line contains two integers $$$n$$$, $$$p$$$ $$$(2 \le p \le n \le 2000)$$$. It is guaranteed, that the number $$$p$$$ is prime (it has exactly two divisors $$$1$$$ and $$$p$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 2000)$$$.

In the first line, print the number of good integers $$$x$$$. In the second line, output all good integers $$$x$$$ in the ascending order. It is guaranteed that the number of good integers $$$x$$$ does not exceed $$$10^5$$$.

NoteIn the first test, $$$p=2$$$.  If $$$x \le 2$$$, there are no valid permutations for Yuzu. So $$$f(x)=0$$$ for all $$$x \le 2$$$. The number $$$0$$$ is divisible by $$$2$$$, so all integers $$$x \leq 2$$$ are not good.  If $$$x = 3$$$, $$$\{1,2,3\}$$$ is the only valid permutation for Yuzu. So $$$f(3)=1$$$, so the number $$$3$$$ is good.  If $$$x = 4$$$, $$$\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$$$ are all valid permutations for Yuzu. So $$$f(4)=4$$$, so the number $$$4$$$ is not good.  If $$$x \ge 5$$$, all $$$6$$$ permutations are valid for Yuzu. So $$$f(x)=6$$$ for all $$$x \ge 5$$$, so all integers $$$x \ge 5$$$ are not good. So, the only good number is $$$3$$$.In the third test, for all positive integers $$$x$$$ the value $$$f(x)$$$ is divisible by $$$p = 3$$$.

const process = require('process');

let inp = "";
process.stdin.on('data', chunk => inp += chunk);
process.stdin.on('end', () => {
    inp = inp.split('\n');
    let [n, p] = inp[0].split(' ').map(x => +x);
    let a = inp[1].split(' ').map(x => +x);

    let cnt = [];
    for (let i = 0; i < 2020; ++i) {
        cnt.push(0);
    }

    for (let i of a) cnt[i] ++;

    for (let i = 1; i < 2020; ++i) cnt[i] += cnt[i - 1];

    let ans = [];
    for (let x = 0; x < 3000; ++x) {
        let ok = true;
        for (let i = 0; i < n; ++i) {
            // console.log(i, cnt[x + i], cnt[x + i] - i);
            let cur_cnt = x + i >= cnt.length ? cnt[2019] : cnt[x + i];
            if (cur_cnt - i < 1 || (cur_cnt - i) % p == 0) {
                ok = false;
                break;
            }
        }
        if (ok) ans.push(x);
    }
    console.log(ans.length);
    console.log(ans.join(' '));
});

const process = require('process');

let inp = "";
process.stdin.on('data', chunk => inp += chunk);
process.stdin.on('end', () => {
    inp = inp.split('\n');
    let [n, p] = inp[0].split(' ').map(x => +x);
    let a = inp[1].split(' ').map(x => +x);

    let cnt = [];
    for (let i = 0; i < 2020; ++i) {
        cnt.push(0);
    }

    for (let i of a) cnt[i] ++;

    for (let i = 1; i < 2020; ++i) cnt[i] += cnt[i - 1];

    let ans = [];
    for (let x = 0; x < 10; ++x) {
        let ok = true;
        for (let i = 0; i < n; ++i) {
            // console.log(i, cnt[x + i], cnt[x + i] - i);
            let cur_cnt = x + i >= cnt.length ? cnt[2019] : cnt[x + i];
            if (cur_cnt - i < 1 || (cur_cnt - i) % p == 0) {
                ok = false;
                break;
            }
        }
        if (ok) ans.push(x);
    }
    console.log(ans.length);
    console.log(ans.join(' '));
});


Все готовятся к VK Fest 2021! Для того, чтобы зрителям была лучше видна главная сцена, планируется построить амфитеатр. В этой задаче мы будем рассматривать его сбоку — схематично он будет иметь форму лестницы из $$$n$$$ одинаковых квадратов. Лестница — это одна или более башен квадратов, выстроенных в ряд, где высоты башен невозрастают слева направо.На следующем рисунке можно видеть три разные фигуры из $$$12$$$ квадратов. Первые две фигуры — лестницы, а третья — нет.  Из эстетических соображений было решено, что амфитеатр должен быть симметричным. Формально, амфитеатр называется симметричным, если при отражении его схемы относительно прямой $$$x = y$$$ получается тот же самый рисунок (где ось $$$x$$$ направлена слева направо, а ось $$$y$$$ — снизу вверх). Например, первая лестница на рисунке выше — симметричная, а вторая — нет.  Кроме того, амфитеатр должен быть максимально компактным — а именно, сторона минимального квадрата, внутрь которого можно его поместить, должна быть как можно меньше.По заданному числу $$$n$$$ нарисуйте схему амфитеатра из ровно $$$n$$$ квадратов, удовлетворяющую всем условиям.

В единственной строке задано одно целое число $$$n$$$ ($$$1 \le n \le 100$$$) — число квадратов, из которых нужно составить схему амфитеатра.

Если не существует схемы амфитеатра из $$$n$$$ квадратов, выведите единственное число $$$-1$$$. Иначе в первой строке выведите целое число $$$m$$$ — минимальное возможное число строк и столбцов в схеме амфитеатра. Далее выведите $$$m$$$ строк, описывающих схему. Каждая строка должна содержать ровно $$$m$$$ символов 'o' (строчная латинская буква) или '.', где 'o' описывает построенный квадрат, а '.' — пустое место. Схема амфитеатра должна состоять ровно из $$$n$$$ символов 'o'. Ячейка в левом нижнем углу должна содержать квадрат. Если возможных ответов с минимальным $$$m$$$ несколько, выведите любой из них.

let _DEBUG;

const fs = require('fs');
const { assert } = require('console');
const print = console.log;
const debug = (x) => {
    if (!_DEBUG) return;
    let vn = Object.keys(x)[0];
    console.error(`${vn}: ${x[vn]}`);
};
const debugf = !_DEBUG ? () => {} : console.error;

const MAXN = 100;

let input = fs.readFileSync(0).toString();
input = input.split(/\r?\n/g);

let n = +input[0];

if (n == 2) {
    print(-1);
} else {
    let m = n % 2;
    while ((m + 2) * (m + 2) <= n) {
        m += 2;
    }

    let rem = n - m * m;
    assert(rem % 2 == 0);
    let hrem = rem / 2;

    let h = Math.ceil(hrem / m);
    let s = m + h;

    debug({ n });
    debug({ m });

    print(s);
    let r = [];
    for (let i = 0; i < s; i++) {
        r.push('.'.repeat(s).split(''));
    }
    for (let i = 0; i < m; i++) {
        for (let j = 0; j <= i; j++) {
            r[i][j] = r[j][i] = 'o';
        }
    }
    for (let i = m; i < m + h; i++) {
        for (let j = 0; j < m; j++) {
            let t = (hrem - 1) % m + 1;
            if (i < m + h - 1 || j < t) {
                r[i][j] = r[j][i] = ['o'];
            }
        }
    }

    print(
        r
            .reverse()
            .map((x) => x.join(''))
            .join('\n')
    );
}

const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift()(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift())
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

function extend(mas) {
  let n = mas.length
  mas.unshift(new Array(n++).fill('.'))
  for (let i = 0; i < n; ++i) {
    mas[i].push('.')
  }
}

async function main() {
  let n = +await nextString()
  if (n === 2) {
    console.log('-1')
    return
  }
  let m = n % 2 === 0 ? 2 : 1
  while (((m + 2) ** 2) <= n && ((n - ((m + 2) ** 2)) % 2) === 0) {
    m += 2
  }
  let mas = new Array(m)
    .fill(42)
    .map(() => new Array(m).fill('o'))
  let f = m
  n -= m * m;
  while (n > 0) {
    extend(mas)
    ++m
    for (let i = 0; i < f && n > 0; ++i, n -= 2) {
      mas[0][i] = mas[m - 1 - i][m - 1] = 'o'
    }
  }
  let str = mas.map(row => row.join('')).join('\n')
  console.log(m + '\n' + str)
}

main()

n = +readline()

if (n%2===0) {
    bd = n/2
} else {
    bd = (n+1)/2
}

function solve(){
    for (var len = 1;len<=bd;len++)
    {
        for (var sq = 1;sq<=len;sq++)
        {
            var now = len*2-1 + (sq-1)*(sq-1)
            var add = (sq-1) * (len-sq) * 2
            if (now <= n && n <= now+add && now%2 == n%2) {
                print(len)
                S = '.'.repeat(len)
                ans = []
                for (var z=0;z<len;z++){
                    ans.push(S)
                }

                for (var i=0;i<len;i++)
                {
                    for (var j=0;j<len;j++)
                    {
                        if (i==0 || j==0 || (i<sq && j<sq)) {
                            ans[i] = ans[i].replace('.','o')
                        }
                    }
                }

                for (var i = sq; i<len && now<n; i++)
                {
                    for (var j = 1;j<sq && now<n; j++)
                    {
                        ans[i] = ans[i].replace('.','o')
                        ans[j] = ans[j].replace('.','o')
                        now += 2
                    }
                }
                for (var i=len-1;i>=0;i--)
                {
                    print(ans[i])
                }
                return
            }
        }
    }
}

if (n==2)
    print(-1)
else
    solve()

let _DEBUG;

const fs = require('fs');
const { assert } = require('console');
const print = console.log;
const debug = (x) => {
    if (!_DEBUG) return;
    let vn = Object.keys(x)[0];
    console.error(`${vn}: ${x[vn]}`);
};
const debugf = !_DEBUG ? () => {} : console.error;

const MAXN = 100;

let input = fs.readFileSync(0).toString();
input = input.split(/\r?\n/g);

let n = +input[0];

if (n == 2) {
    print(-1);
} else {
    let m = n % 2;
    while ((m + 2) * (m + 2) <= n) {
        m += 2;
    }

    let rem = n - m * m;
    assert(rem % 2 == 0);
    let hrem = rem / 2;

    let h = Math.ceil(hrem / m);
    let s = m + h;

    debug({ n });
    debug({ m });

    print(s);
    let r = [];
    for (let i = 0; i < s; i++) {
        r.push('.'.repeat(s).split(''));
    }
    for (let i = 0; i < m; i++) {
        for (let j = 0; j <= i; j++) {
            r[i][j] = r[j][i] = 'o';
        }
    }
    for (let i = m; i < m + h; i++) {
        for (let j = 0; j < m; j++) {
            let t = (hrem - 1) % m + 1;
            if (i < m || j < t) {
                r[i][j] = r[j][i] = ['o'];
            }
        }
    }

    print(
        r
            .reverse()
            .map((x) => x.join(''))
            .join('\n')
    );
}

let _DEBUG = 1;

const fs = require('fs');
const print = console.log;
const debug = (x) => {
  if (!_DEBUG) return;
  let vn = Object.keys(x)[0];
  console.error(`${vn}: ${x[vn]}`);
};
const debugf = !_DEBUG ? () => {} : console.error;

let input = fs.readFileSync(0).toString();
input = input.split(/\r?\n/g);

let n = +input[0];

let s = 1;
while (s * s < n) {
    s++;
}

let r = [];
for (let i = 0; i < s; i++) {
    r.push('.'.repeat(s).split(''));
}

r[s - 1][0] = ['o'];
let t = n - (s - 1) * (s - 1);

for (let i = 0; i < s - 1; i++) {
    for (let j = 0; j < s - 1; j++) {
        r[s - 1 - i][j] = ['o'];
    }
}

for (let i = 0; i < s && t >= 2; i++) {
    r[0][i] = ['o'];
    r[s - 1 - i][s - 1] = ['o'];
    t -= 2;
}

if (n == s * s) {
    r[0][s - 1] = ['o'];
    t = 0;
}

if (t == 0) {
    print(s);
    print(r.map(x => x.join('')).join('\n'));
} else {
    print(-1);
}