The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules:  The players move in turns; In one move the player can remove an arbitrary letter from string s.  If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.

The input contains a single line, containing string s (1 ≤ |s|  ≤  103). String s consists of lowercase English letters.

In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.

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 main() {
  const str = readLine();
  let [map, count1] = [{}, 0];

  for (let i = 0; i < str.length; i++) {
    const char = str[i];
    map[char] = (map[char] || 0) + 1;
  }

  for (let key in map) {
    if (map[key] % 2 === 1) count1++;
  }

  if (count1 === 0) console.log("First");
  else if (count1 % 2 === 0) console.log("Second");
  else console.log("First");
}

var ans = 0,
	A = 'A'.charCodeAt(),
	z = 'z'.charCodeAt(),
	cnt = new Int32Array(128),
	s = readline();

for (var i = 0; i < s.length; i++)
	cnt[s.charCodeAt(i)]++;

for (var i = A; i <= z; i++)
	ans += cnt[i] % 2;

print(ans == 0 || ans % 2 === 1 ? 'First' : 'Second');

var s=readline().split('')
res=0
var alph="abcdefghijklmnopqrstuvwxyz"
for (var i=0;i<alph.length;i++)
{
    kol=0
    for (var j=0;j<s.length;j++)
    {
        if (alph[i]==s[j])
        {
            kol^=1
        }
    }
    if (kol)
    {
        res++
    }
}
print((!res||res%2)?"First":"Second")

;(function () {

	print((function (s) {

		var m = {};
		for (var i = 0, _i = s.length; i < _i; i++) m[s[i]] = m[s[i]] ? m[s[i]] + 1 : 1;
		m = (function () {
			var ret = [0, 0];
			for (var key in m) ret[m[key]%2]++;
			return ret[1] === 0 ? 1 : ret[1];
		})()

		return m % 2 ? 'First' : 'Second';
	})(readline()));

}).call(this);

;(function () {

	print((function (s) {

		var m = {};
		for (var i = 0, _i = s.length; i < _i; i++) m[s[i]] = m[s[i]] ? m[s[i]] + 1 : 1;
		m = (function () {
			var ret = [0, 0];
			for (var key in m) ret[m[key]%2]++;
			return ret[0] + ret[1];
		})()

		return m % 2 ? 'Second' : 'First';
	})(readline()));

}).call(this);


During their New Year holidays, Alice and Bob play the following game using an array $$$a$$$ of $$$n$$$ integers:   Players take turns, Alice moves first.  Each turn a player chooses any element and removes it from the array.  If Alice chooses even value, then she adds it to her score. If the chosen value is odd, Alice's score does not change.  Similarly, if Bob chooses odd value, then he adds it to his score. If the chosen value is even, then Bob's score does not change. If there are no numbers left in the array, then the game ends. The player with the highest score wins. If the scores of the players are equal, then a draw is declared.For example, if $$$n = 4$$$ and $$$a = [5, 2, 7, 3]$$$, then the game could go as follows (there are other options):   On the first move, Alice chooses $$$2$$$ and get two points. Her score is now $$$2$$$. The array $$$a$$$ is now $$$[5, 7, 3]$$$.  On the second move, Bob chooses $$$5$$$ and get five points. His score is now $$$5$$$. The array $$$a$$$ is now $$$[7, 3]$$$.  On the third move, Alice chooses $$$7$$$ and get no points. Her score is now $$$2$$$. The array $$$a$$$ is now $$$[3]$$$.  On the last move, Bob chooses $$$3$$$ and get three points. His score is now $$$8$$$. The array $$$a$$$ is empty now.  Since Bob has more points at the end of the game, he is the winner. You want to find out who will win if both players play optimally. Note that there may be duplicate numbers in the array.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$a$$$. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array $$$a$$$ used to play the game. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output on a separate line:    "Alice" if Alice wins with the optimal play;  "Bob" if Bob wins with the optimal play;  "Tie", if a tie is declared during the optimal play.

'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();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var n = Number(readline());
        var answer = []
        var xx = 0
        var array = readline().split(' ').map((x, i) => {
            xx = Number(x)
            return xx
        });
        var sorted = array.sort((a, b) => a - b)
        // console.log(sorted)
        // console.log(array)
        var ii = n - 1
        var i = 0
        var sumA = 0
        var sumB = 0
        var smod2 = 0
        var i2 = 0
        while (ii >= 0) {
            smod2 = sorted[ii] % 2
            i2 = i % 2
            if (smod2 === 0 && i2 === 0) sumA += sorted[ii]
            if (smod2 % 2 === 1 && i2 === 1) sumB += sorted[ii]
            ii--
            i++
        }

        if (sumA > sumB) return console.log('Alice')
        if (sumA < sumB) return console.log('Bob')
        console.log('Tie')
    })

}

function swap(items, leftIndex, rightIndex) {
    var temp = items[leftIndex];
    items[leftIndex] = items[rightIndex];
    items[rightIndex] = temp;
}

function partition(items, left, right) {
    var pivot = items[Math.floor((right + left) / 2)], //middle element
        i = left, //left pointer
        j = right; //right pointer
    while (i <= j) {
        while (items[i] < pivot) {
            i++;
        }
        while (items[j] > pivot) {
            j--;
        }
        if (i <= j) {
            swap(items, i, j); //sawpping two elements
            i++;
            j--;
        }
    }
    return i;
}

function quickSort(items, left, right) {
    var index;
    if (items.length > 1) {
        index = partition(items, left, right); //index returned from partition
        if (left < index - 1) { //more elements on the left side of the pivot
            quickSort(items, left, index - 1);
        }
        if (index < right) { //more elements on the right side of the pivot
            quickSort(items, index, right);
        }
    }
    return items;
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    arr.sort((a, b) => b - a);
    let a = 0,
      b = 0,
      k = 1;
    for (let i = 0; i < n; i++, k = !k) {
      if (k) a += arr[i] % 2 === 0 ? arr[i] : 0;
      else b += arr[i] % 2 === 1 ? arr[i] : 0;
    }
    if (a === b) console.log("Tie");
    else if (a > b) console.log("Alice");
    else console.log("Bob");
  }
};
solve();

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

const calculate = (n, a) => {
  a = a.sort((a, b) => b - a)
  let mb = 0
  let ma = 0

  a.forEach((val, index) => {
    if (index % 2 === 0) {
      ma += val % 2 === 0 ? val : 0
    } else {
      mb += val % 2 === 0 ? 0 : val
    }
  })

  if (ma < mb) {
    return 'Bob'
  } else if (ma > mb) {
    return 'Alice'
  } else {
    return 'Tie'
  }
}

let index = -1
let maxRound = 0
let round = 0

let n, a
let answer = []

readline.on('line', line => {
  if (index === -1) {
    maxRound = Number(line)
    index = 0
  } else {
    const mode = index % 2
    if (mode === 0) {
      n = Number(line)
    } else if (mode === 1) {
      a = line.split(' ').map(val => Number(val))
      answer.push(calculate(n, a))
      round++
      if (round === maxRound) {
        readline.close()
        console.log(answer.join('\n'))
        return
      }
    }
    index++
  }
})

// chainNumberList, cList, aList, bList
// console.log(calculate(4, [3, 4, 3, 3], [-1, 1, 2, 2], [-1, 2, 2, 3]))

let i = ''
const { EOL } = require('os')
process.stdin.on('data', c => (i += c))
process.stdin.on('end', () => {
  const lines = i.split(EOL).filter(line => line)
  console.log(processInput(lines))
})

const processInput = lines => {
  return lines
    .slice(1)
    .filter((_, i) => i % 2)
    .map(line => line.split(' ').map(n => +n))
    .map(nums => {
      const sortedNums = nums.sort((a, b) => b - a)
      const alice = sortedNums
        .filter((num, i) => !(i % 2) && num % 2 === 0)
        .reduce((a, b) => a + b, 0)
      const bob = sortedNums
        .filter((num, i) => i % 2 && num % 2 === 1)
        .reduce((a, b) => a + b, 0)
      if (alice > bob) return 'Alice'
      else if (bob > alice) return 'Bob'
      else return 'Tie'
    })
    .join(EOL)
}

const game = a => {
  a.sort((i, j) => j - i);
  let res = 0;
  for (let i = 0; i < a.length; i++) {
    if (a[i] % 2 == 0 && i % 2 == 0) res += a[i];
    else if (a[i] % 2 == 1 && i % 2 == 1) res -= a[i];
  }
  return res;
};

const main = () => {
  let test = parseInt(readline());
  while (test--) {
    readline();
    const a = readline()
      .split(" ")
      .map(s => parseInt(s));
    const res = game(a);
    if (res == 0) console.log("Tie");
    else if (res > 0) console.log("Alice");
    else console.log("Bob");
  }
};

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 => string.trim());
  main();
});

const readline = () => {
  return inputString[currentLine++];
};

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

  for (let i = 0; i < x; i++) {
    let n = readline();
    let arr = readline().split(' ').map(x => +x);

    arr = arr.sort((a, b) => {
      return b - a;
    });

    let aliceSum = 0;
    let bobSum = 0;

    for (let i = 0; i <= n; i+=2) {
      if (arr[i] % 2 === 0) {
        aliceSum += arr[i];
      }
      if (arr[i+1] && arr[i+1] % 2 !== 0) {
        bobSum += arr[i+1];
      }
    }

    if (aliceSum === bobSum) {
      console.log('Tie');
    } else if (aliceSum > bobSum) {
      console.log('Alice');
    } else {
      console.log('Bob');
    }
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function getArray(str) {
    return str.split(' ').map(x => Number(x));
}

function getInt(str) {
    return Number(str);
}

function getStrArray(str) {
    return str.split(' ').map(x => x);
}

function create2DArray(rows) {
    var arr = [];

    for (var i = 0; i < rows; i++) {
        arr[i] = [];
    }

    return arr;
}
// ---------------------------------------

function main() {
    let t = getInt(readline());
    while (t--) {
        let len = getInt(readline());
        let arr = getArray(readline());
        arr  = arr.sort((a, b) => b-a);
        let score1 = 0;
        let score2 = 0;
        for(let i=0; i<len; i++) {
            if(i%2 === 0) {
                if (arr[i] % 2 === 0) {
                    score1 += arr[i]
                }
            } else {
                if (arr[i] % 2 !== 0) {
                    score2 += arr[i]
                }
            }
        }
        if(score1 > score2) {
            console.log('Alice');
        } else if (score1 < score2) {
            console.log('Bob');
        } else {
            console.log('Tie');
        }
    }
}

//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 t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return b - a;
		});
		var sum = 0;
		for(var j = 0; j < N; j++){
			if(j % 2 == 0){
				if(list[j] % 2 == 0){
					sum += list[j];
				}
			}else{
				if(list[j] % 2 == 1){
					sum -= list[j];
				}
			}
		}
		if(sum > 0){
			myout("Alice");
		}else if(sum < 0){
			myout("Bob");
		}else{
			myout("Tie");
		}
	}
}

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 [evens, odds] = [[], []];
		const arr = readLine()
			.split(' ')
			.map((n) => {
				n = Number(n);
				if (n % 2 === 0) evens.push(n);
				else odds.push(n);
				return n;
			});
		evens.sort((a, b) => a - b);
		odds.sort((a, b) => a - b);
		let [counta, countb] = [0, 0];

		let i = 1;
		while (evens.length || odds.length) {
			const [evenTop, oddTop] = [evens[evens.length - 1] || 0, odds[odds.length - 1] || 0];
			const max = Math.max(evenTop, oddTop);
			if (i % 2 !== 0) {
				// alice
				if (max === evenTop) {
					counta += evenTop;
					evens.pop();
				} else odds.pop();
			} else {
				// bob
				if (max === oddTop) {
					countb += oddTop;
					odds.pop();
				} else evens.pop();
			}
			i++;
		}
		if (counta > countb) console.log('Alice');
		else if (counta < countb) console.log('Bob');
		else console.log('Tie');
	}
}

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

    const t = parseInt(lines[0]);

    for (let i = 1; i <= t * 2; i += 2) {
        const n = parseInt(lines[i]);
        const arr = lines[i + 1].split(' ').map(num => parseInt(num));

        console.log(solve(n, arr));
    }
});

function solve(n, arr) {
    arr.sort((a, b) => b - a);

    let alice = 0;
    let bob = 0;

    for (let i = 0; i < arr.length; i++) {
        if (arr[i] % 2 === 0 && i % 2 === 0) {
            alice += arr[i];
        } else if (arr[i] % 2 === 1 && i % 2 === 1) {
            bob += arr[i];
        }
    }

    if (alice > bob) {
        return 'Alice';
    } else if (bob > alice) {
        return 'Bob';
    } else {
        return 'Tie';
    }
}

let i = '';
process.stdin.on('data', (c) => (i += c));
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL).filter((line) => line);
    console.log(processInput(lines));
});

const processInput = (lines) => {
    return lines
        .slice(1)
        .filter((_, i) => i % 2)
        .map((line) => line.split(' ').map((n) => +n))
        .map((nums) => {
            const sortedNums = nums.sort((a, b) => b - a);
            let alice = 0,
                bob = 0;
            for (let i = 0; i < sortedNums.length; i++) {
                if (i % 2 === 0) {
                    if (sortedNums[i] % 2 === 0) {
                        alice += sortedNums[i];
                    }
                } else {
                    if (sortedNums[i] % 2 === 1) {
                        bob += sortedNums[i];
                    }
                }
            }
            return alice > bob ? 'Alice' : alice < bob ? 'Bob' : 'Tie';
        })
        .join('\n');
};

"use strict"

let iter = parseInt(readline());

for(let i = 0; i < iter; i++){
    let length = parseInt(readline());
    let arr = readline().split(" ").map(x => parseInt(x));
    let points = 0;
    arr.sort((a, b) => a - b);

    for(let j = 0; j < length; j++) {
        if(j % 2 === 0 && arr[length - j - 1] % 2 === 0){
            points += arr[length - j - 1];
        } else if (j % 2 === 1 && arr[length - j - 1] % 2 === 1) {
            points -= arr[length - j - 1];
        }
    }

    if(points > 0){
        print("Alice");
    } else if(points === 0){
        print("Tie");
    } else {
        print("Bob");
    }
}


Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.Help Inna maximize the total joy the hares radiate. :)

The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≤ ai, bi, ci ≤ 105. Number ai in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in the third line shows the joy that hare number i radiates if both his adjacent hares are full.

In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.

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

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

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

function main() {
	var hareNum = parseInt(readline());
	var orderValues = [];
	for (var i = 0; i < 3; ++i) {
		orderValues.push(tokenizeIntegers(readline()));
	}

	if (hareNum == 1) {
		print(orderValues[0][0]);
		return;
	}

	var permutations = [
		[1, 2, 3],
		[1, 3, 2],
		[2, 1, 3],
		[2, 3, 1],
		[3, 1, 2],
		[3, 2, 1]
	];

	var compatible = [];
	for (var i = 0; i < 6; ++i) {
		var a = permutations[i][0], b = permutations[i][1];
		var dir = (a-b)/Math.abs(a-b);
		compatible.push([]);
		for (var j = 0; j < 6; ++j) {
			var c = permutations[j][1], d = permutations[j][2];
			if ((c-d)/Math.abs(c-d) == dir) {
				compatible[i].push(j);
			}
		}
	}

	var memo = [];

	function getCurrentValue(position, permutationIx) {
		return orderValues[permutations[permutationIx][1]-1][position];
	}

	function storeTotalValue(position, permutationIx) {
		if (position == 0) {
			if (permutationIx >= 4) {
				memo[position][permutationIx] = { previousIndex: -1,
						value: getCurrentValue(position, permutationIx) };
			}
			else {
				memo[position][permutationIx] = { previousIndex: -1,
						value: -3000*1000*1000 };
			}
			return;
		}
		if (position == hareNum-1) {
			if (permutationIx != 0 && permutationIx != 2) {
				memo[position][permutationIx] = { previousIndex: -1,
						value: -3000*1000*1000 };
				return;
			}
		}
		var memoRow = memo[position-1], indices = compatible[permutationIx];
		var bestIndex = indices[indices.length-1];
		for (var i = indices.length-2; i >= 0; --i) {
			if (memoRow[indices[i]].value > memoRow[bestIndex].value) {
				bestIndex = indices[i];
			}
		}
		memo[position][permutationIx] = { previousIndex: bestIndex,
				value: memoRow[bestIndex].value +
						getCurrentValue(position, permutationIx) };
	}

	for (var position = 0; position < hareNum; ++position) {
		memo.push(new Array(6));
		for (var permutationIx = 0; permutationIx < 6; ++permutationIx) {
			storeTotalValue(position, permutationIx);
		}
	}

	var bestValue = 0;
	for (var permutationIx = 0; permutationIx < 6; ++permutationIx) {
		bestValue = Math.max(bestValue, memo[hareNum-1][permutationIx].value);
	}
	print(bestValue);
	return;

	print();
	var choices = [];
	for (var i = 0; i < 6; ++i) {
		if (memo[hareNum-1][i].value == bestValue) {
			choices.push(i);
			break;
		}
	}
	for (var position = hareNum-2; position >= 0; --position) {
		var choice = choices[0];
		var indices = compatible[choice];
		var previous = indices[indices.length-1];
		var memoRow = memo[position];
		for (var i = indices.length-2; i >= 0; --i) {
			if (memoRow[indices[i]].value > memoRow[previous].value) {
				previous = indices[i];
			}
		}
		choices.unshift(previous);
	}
	print(choices.join(" "));
	for (var i = 0; i < choices.length; ++i) {
		print("choice = "+choices[i]+" ("+permutations[choices[i]].join(" ")+")");
	}
}

main();

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

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

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

function main() {
	var hareNum = parseInt(readline());
	var orderValues = [];
	for (var i = 0; i < 3; ++i) {
		orderValues.push(tokenizeIntegers(readline()));
		orderValues[i].unshift(0);
	}

	var permutations = [
		[1, 2, 3],
		[1, 3, 2],
		[2, 1, 3],
		[2, 3, 1],
		[3, 1, 2],
		[3, 2, 1]
	];

	var compatible = [];
	for (var i = 0; i < 6; ++i) {
		var a = permutations[i][0], b = permutations[i][1];
		var dir = (a-b)/Math.abs(a-b);
		compatible.push([]);
		for (var j = 0; j < 6; ++j) {
			var c = permutations[j][1], d = permutations[j][2];
			if ((c-d)/Math.abs(c-d) == dir) {
				compatible[i].push(j);
			}
		}
	}

	var memo = [[0, 0, 0, 0, 0, 0]];
	++hareNum;

	function storeTotalValue(position, permutationIx) {
		var best = 0, indices = compatible[permutationIx];
		for (var i = indices.length-1; i >= 0; --i) {
			best = Math.max(best, memo[position-1][indices[i]]);
		}
		memo[position][permutationIx] = best +
				orderValues[permutations[permutationIx][1]-1][position];
	}

	for (var position = 1; position < hareNum; ++position) {
		for (var permutationIx = 0; permutationIx < 6; ++permutationIx) {
			memo.push(new Array(6));
			storeTotalValue(position, permutationIx);
		}
	}

	var best = 0;
	for (var permutationIx = 0; permutationIx < 6; ++permutationIx) {
		best = Math.max(best, memo[hareNum-1][permutationIx]);
	}
	print(best);
}

main();

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

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

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

function main() {
	var hareNum = parseInt(readline());
	var orderValues = [];
	for (var i = 0; i < 3; ++i) {
		orderValues.push(tokenizeIntegers(readline()));
	}

	var permutations = [
		[1, 2, 3],
		[1, 3, 2],
		[2, 1, 3],
		[2, 3, 1],
		[3, 1, 2],
		[3, 2, 1]
	];

	var compatible = [];
	for (var i = 0; i < 6; ++i) {
		var a = permutations[i][0], b = permutations[i][1];
		var dir = (a-b)/Math.abs(a-b);
		compatible.push([]);
		for (var j = 0; j < 6; ++j) {
			var c = permutations[j][1], d = permutations[j][2];
			if ((c-d)/Math.abs(c-d) == dir) {
				compatible[i].push(j);
			}
		}
	}

	var memo = [];

	function getCurrentValue(position, permutationIx) {
		return orderValues[permutations[permutationIx][1]-1][position];
	}

	function storeTotalValue(position, permutationIx) {
		if (position == 0) {
			if (permutationIx >= 4) {
				memo[position][permutationIx] = { previousIndex: -1,
						value: getCurrentValue(position, permutationIx) };
			}
			else {
				memo[position][permutationIx] = { previousIndex: -1,
						value: -3000*1000*1000 };
			}
			return;
		}
		if (position == hareNum-1) {
			if (permutationIx != 0 && permutationIx != 2) {
				memo[position][permutationIx] = { previousIndex: -1,
						value: -3000*1000*1000 };
			}
		}
		var memoRow = memo[position-1], indices = compatible[permutationIx];
		var bestIndex = indices[indices.length-1];
		for (var i = indices.length-2; i >= 0; --i) {
			if (memoRow[indices[i]].value > memoRow[bestIndex].value) {
				bestIndex = indices[i];
			}
		}
		memo[position][permutationIx] = { previousIndex: bestIndex,
				value: memoRow[bestIndex].value +
						getCurrentValue(position, permutationIx) };
	}

	for (var position = 0; position < hareNum; ++position) {
		memo.push(new Array(6));
		for (var permutationIx = 0; permutationIx < 6; ++permutationIx) {
			storeTotalValue(position, permutationIx);
		}
	}

	var bestValue = 0;
	for (var permutationIx = 0; permutationIx < 6; ++permutationIx) {
		bestValue = Math.max(bestValue, memo[hareNum-1][permutationIx].value);
	}
	print(bestValue);
	return;

	print();
	var choices = [];
	for (var i = 0; i < 6; ++i) {
		if (memo[hareNum-1][i].value == bestValue) {
			choices.push(i);
			break;
		}
	}
	for (var position = hareNum-2; position >= 1; --position) {
		var choice = choices[0];
		var indices = compatible[choice];
		var previous = indices[indices.length-1];
		var memoRow = memo[position];
		for (var i = indices.length-2; i >= 0; --i) {
			if (memoRow[indices[i]].value > memoRow[previous].value) {
				previous = indices[i];
			}
		}
		choices.unshift(previous);
	}
	print(choices.join(" "));
	for (var i = 0; i < choices.length; ++i) {
		print("choice = "+choices[i]+" ("+permutations[choices[i]].join(" ")+")");
	}
}

main();

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

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

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

function main() {
	var hareNum = parseInt(readline());
	var orderValues = [];
	for (var i = 0; i < 3; ++i) {
		orderValues.push(tokenizeIntegers(readline()));
	}

	var permutations = [
		[1, 2, 3],
		[1, 3, 2],
		[2, 1, 3],
		[2, 3, 1],
		[3, 1, 2],
		[3, 2, 1]
	];

	var compatible = [];
	for (var i = 0; i < 6; ++i) {
		var a = permutations[i][0], b = permutations[i][1];
		var dir = (a-b)/Math.abs(a-b);
		compatible.push([]);
		for (var j = 0; j < 6; ++j) {
			var c = permutations[j][1], d = permutations[j][2];
			if ((c-d)/Math.abs(c-d) == dir) {
				compatible[i].push(j);
			}
		}
	}

	var memo = [];

	function getCurrentValue(position, permutationIx) {
		return orderValues[permutations[permutationIx][1]-1][position];
	}

	function storeTotalValue(position, permutationIx) {
		if (position == 0) {
			if (permutationIx >= 4) {
				memo[position][permutationIx] = { previousIndex: -1,
						value: getCurrentValue(position, permutationIx) };
			}
			else {
				memo[position][permutationIx] = { previousIndex: -1,
						value: -3000*1000*1000 };
			}
			return;
		}
		if (position == hareNum-1) {
			if (permutationIx != 0 && permutationIx != 2) {
				memo[position][permutationIx] = { previousIndex: -1,
						value: -3000*1000*1000 };
				return;
			}
		}
		var memoRow = memo[position-1], indices = compatible[permutationIx];
		var bestIndex = indices[indices.length-1];
		for (var i = indices.length-2; i >= 0; --i) {
			if (memoRow[indices[i]].value > memoRow[bestIndex].value) {
				bestIndex = indices[i];
			}
		}
		memo[position][permutationIx] = { previousIndex: bestIndex,
				value: memoRow[bestIndex].value +
						getCurrentValue(position, permutationIx) };
	}

	for (var position = 0; position < hareNum; ++position) {
		memo.push(new Array(6));
		for (var permutationIx = 0; permutationIx < 6; ++permutationIx) {
			storeTotalValue(position, permutationIx);
		}
	}

	var bestValue = 0;
	for (var permutationIx = 0; permutationIx < 6; ++permutationIx) {
		bestValue = Math.max(bestValue, memo[hareNum-1][permutationIx].value);
	}
	print(bestValue);
	return;

	print();
	var choices = [];
	for (var i = 0; i < 6; ++i) {
		if (memo[hareNum-1][i].value == bestValue) {
			choices.push(i);
			break;
		}
	}
	for (var position = hareNum-2; position >= 0; --position) {
		var choice = choices[0];
		var indices = compatible[choice];
		var previous = indices[indices.length-1];
		var memoRow = memo[position];
		for (var i = indices.length-2; i >= 0; --i) {
			if (memoRow[indices[i]].value > memoRow[previous].value) {
				previous = indices[i];
			}
		}
		choices.unshift(previous);
	}
	print(choices.join(" "));
	for (var i = 0; i < choices.length; ++i) {
		print("choice = "+choices[i]+" ("+permutations[choices[i]].join(" ")+")");
	}
}

main();


There is an infinite 2-dimensional grid. The robot stands in cell $$$(0, 0)$$$ and wants to reach cell $$$(x, y)$$$. Here is a list of possible commands the robot can execute:  move north from cell $$$(i, j)$$$ to $$$(i, j + 1)$$$;  move east from cell $$$(i, j)$$$ to $$$(i + 1, j)$$$;  move south from cell $$$(i, j)$$$ to $$$(i, j - 1)$$$;  move west from cell $$$(i, j)$$$ to $$$(i - 1, j)$$$;  stay in cell $$$(i, j)$$$. The robot wants to reach cell $$$(x, y)$$$ in as few commands as possible. However, he can't execute the same command two or more times in a row.What is the minimum number of commands required to reach $$$(x, y)$$$ from $$$(0, 0)$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. Each of the next $$$t$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 10^4$$$) — the destination coordinates of the robot.

For each testcase print a single integer — the minimum number of commands required for the robot to reach $$$(x, y)$$$ from $$$(0, 0)$$$ if no command is allowed to be executed two or more times in a row.

NoteThe explanations for the example test:We use characters N, E, S, W and 0 to denote going north, going east, going south, going west and staying in the current cell, respectively.In the first test case, the robot can use the following sequence: NENENENENE.In the second test case, the robot can use the following sequence: NENENEN.In the third test case, the robot can use the following sequence: ESENENE0ENESE.In the fourth test case, the robot doesn't need to go anywhere at all.In the fifth test case, the robot can use the following sequence: E0E.

function task(input){
	let ia = input.trim().split('\n');
	let t = +ia.shift();
	for (let i = 0; i < t; i++) {
		let x = [], [X, Y] = ia.shift().split(' ').map((el) => +el), d = Math.abs(X - Y)
		x = X + Y + (d>1 ? (d-1) : 0)
		console.log(x)
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', _ => {
    task(inputString);
});

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 [x, y] = readLine().split(" ").map(Number);
    let diff = Math.abs(x - y);
    if (diff > 0) diff = diff - 1;
    console.log(x + y + diff);
  }
}

//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 one = nextIntArray();
		var x = one[0];
		var y = one[1];
		var count = 0;
		if(x > 0 && y > 0){
			count = Math.min(x, y) * 2;
			x -= count / 2;
			y -= count / 2;
		}

		if(x > 0){
			count += x * 2 - 1;
		}else if(y > 0){
			count += y * 2 - 1;
		}
		output[i] = count;
	}
	myout(myconv(output, 9));
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const p="local"===process.argv[2],a=t=>{if(p){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(" ").map((t=>parseFloat(t)))}function c(){return h().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e]=i.default.nextNumbers(),r=2*[t,e].min(),n=[t,e].max()-[t,e].min();n>0&&(r+=2*n-1),i.default.puts(r)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [x, y] = io.nextNumbers()
//
//   let cnt = [x, y].min() * 2
//
//   let d = [x, y].max() - [x, y].min()
//
//   if (d > 0) {
//     cnt += d * 2 - 1
//   }
//
//   io.puts(cnt)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

/*
 * File Created: Sunday, 29th November 2020 9:28:45 pm
 * Author: Lukas Rimkus (lukasrimkuslg@gmail.com)
 */

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    data = data.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

        let testCases = parseInt(data.shift());

        while(testCases--) {

            const [n, m ] = get_ints();

            const res = robot(n,m);

            console.log(res);
        }
    });

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
    return data[currentLine++];
}
function robot(x ,y)
{
    //i - 2 j - 2
    return 2*(x > y ? x : y) - (x != y);
}

module.exports = robot

///https://codeforces.com/problemset/problem/1452/A

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

let inputString = '';

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

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

    main(inputString);
});

function main(fileContents) {//input lines as an array
    const amoutOfInputsForTheProgram = fileContents.splice(0,1);
    const listOfEndpointsForRobot = [...fileContents];

    listOfEndpointsForRobot
        .map((endpoints)=>endpoints.split(" "))
        .map((endpoints)=>{
           const diffBetweetVertAndHorizontal = Math.abs(parseInt(endpoints[0])-parseInt(endpoints[1]));
           return parseInt(endpoints[0])+parseInt(endpoints[1])
               +(diffBetweetVertAndHorizontal > 0 ? (diffBetweetVertAndHorizontal-1) : 0)
        })
        .forEach(x=>console.log(x));

}

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [x,y] = ti(readline().split(' '));

        let min = Math.min(x,y);
        let max = Math.max(x,y);
        if(max === min){
            console.log(max+min);
        }else{
            console.log(2*min+(1+(max-min-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() {
  const x = readline();
  var answer = []
  Array(Number(x)).fill(1).map((t, i)=>{
    var line2 = readline().split( ' ').map(x=>Number(x));
    // console.log(typeof line2)
    // line2 = line2.map(x=>Number(x))
    if(Math.max(line2[0],line2[1]) === 0) return console.log(0)
    if(line2[0] === line2[1]) return console.log(line2[1]*2)
    console.log(Math.max(line2[0],line2[1])*2-1)
    // answer[i] = Math.max(line2[0],line2[1])*2-1
  })
}
function foo(x) {
  // process.stdout.write("hello: ");   // without auto '\n' (newline)

  console.log(x);  // with auto '\n' (newline)
}

var tc = parseInt(readline());
for (; tc--;){
  var ar = readline().split(' ').map(x => +x);
  var a = ar[0], b = ar[1];
  var mn = Math.min(a, b);
  var mx = Math.max(a, b);

  print(mn * 2 + (mx - mn) * 2 - (mx - mn > 0 ? 1 : 0));
}

function task(input){
	let ia = input.trim().split('\n');
	let t = +ia.shift();
	for (let i = 0; i < t; i++) {
		let x = [], [X, Y] = ia.shift().split(' ').map((el) => +el), d = Math.abs(X - Y)
		x = X + Y + (d>1 ? (d-1) : 0)
		console.log(`Case #${i+1}: `+x)
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', _ => {
    task(inputString);
});

'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();
  var answer = []
  Array(Number(x)).fill(1).map((t, i)=>{
    var line2 = readline();
    if(Math.max(line2[0],line2[1]) == 0) return console.log(0)
    console.log(Math.max(line2[0],line2[1])*2-1)
    // answer[i] = Math.max(line2[0],line2[1])*2-1
  })
}
function foo(x) {
  // process.stdout.write("hello: ");   // without auto '\n' (newline)

  console.log(x);  // with auto '\n' (newline)
}


You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.You have to find minimum k such that there exists at least one k-dominant character.

The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).

Print one number — the minimum value of k such that there exists at least one k-dominant character.

s=readline()
res=s.length
if (res%2==0)
{
    res/=2
    ++res
}
else
{
    ++res
    res/=2
}

function max(a,b)
{
    return a+b-min(a,b)
}

function min(a,b)
{
    if (a<b)return a;
    return b
}

function go(c)
{
    last=-1
    re=0
    for (i=0;i<s.length;i++)
    {
        if (s[i]==c)
        {
            re=max(re,i-last);
            last=i
        }
    }
    re=max(s.length-last,re)
    //print(re)
    res=min(res,re)
}
go('q');go('w');go('e');
go('r');go('s');go('z');
go('t');go('d');go('x');
go('y');go('f');go('c');
go('u');go('g');go('v');
go('i');go('h');go('b');
go('o');go('j');go('n');
go('p');go('k');go('m');
go('a');go('l');
print(res)


You are given an integer $$$n$$$. You have to apply $$$m$$$ operations to it.In a single operation, you must replace every digit $$$d$$$ of the number with the decimal representation of integer $$$d + 1$$$. For example, $$$1912$$$ becomes $$$21023$$$ after applying the operation once.You have to find the length of $$$n$$$ after applying $$$m$$$ operations. Since the answer can be very large, print it modulo $$$10^9+7$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^5$$$) — the number of test cases. The only line of each test case contains two integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the initial number and the number of operations.

For each test case output the length of the resulting number modulo $$$10^9+7$$$.

NoteFor the first test, $$$1912$$$ becomes $$$21023$$$ after $$$1$$$ operation which is of length $$$5$$$.For the second test, $$$5$$$ becomes $$$21$$$ after $$$6$$$ operations which is of length $$$2$$$.For the third test, $$$999$$$ becomes $$$101010$$$ after $$$1$$$ operation which is of length $$$6$$$.For the fourth test, $$$88$$$ becomes $$$1010$$$ after $$$2$$$ operations which is of length $$$4$$$.

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

var maxN = 2*1e5+10
var mod = 1e9+7

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  var res = ''
  var digit = new Array(10).fill(0)
  var digit2 = new Array(10).fill(0)
  var a = '10'
  a = a.split('').map(x => {
    digit[parseInt(x)]++
    parseInt(x)
  })
  var ans = new Array(maxN + 1).fill(0)
  for (let j = 1; j < maxN + 1; j++) {
    for (let i = 0; i < 10; i++) {
      if (i === 9) {
        digit2[0] = (digit2[0] + digit[9]) % mod
        digit2[1] = (digit2[1] + digit[9]) % mod
        continue
      }
      digit2[i + 1] = digit[i]
    }
    for (let i = 0; i < 10; i++) {
      digit[i] = digit2[i]
      digit2[i] = 0
    }
    for (let k = 0; k < 10; k++) {
      ans[j] = (ans[j] + digit[k]) % mod
    }
  }
  ans[0] = 2
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    // var n = BigInt(readline());
    var [n, m] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    // var [x, y] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    // var a = readline().split(' ').map((x, iii) => {
    //   return BigInt(x)
    // })

    a = n.toString().split('').map(x => {
      digit[parseInt(x)]++
      return parseInt(x)
    })

    var value = 0;

    for (let j = 0; j < a.length; j++) {
      if(m - (10 - a[j]) >= 0){
        value = (value + ans[m - (10 - a[j])]) % mod
      } else {
        value = (value + 1) % mod
      }
      // console.log(a[j], m - (10 - a[j]), value)
    }
    // console.log(value)
    res = res + value + '\n'
  })
  console.log(res)
}

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

var maxN = 2*1e5+10
var mod = 100000007

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  var res = ''
  var digit = new Array(10).fill(0)
  var digit2 = new Array(10).fill(0)
  var a = '10'
  a = a.split('').map(x => {
    digit[parseInt(x)]++
    parseInt(x)
  })
  var ans = new Array(maxN + 1).fill(0)
  for (let j = 1; j < maxN + 1; j++) {
    for (let i = 0; i < 10; i++) {
      if (i === 9) {
        digit2[0] = (digit2[0] + digit[9]) % mod
        digit2[1] = (digit2[1] + digit[9]) % mod
        continue
      }
      digit2[i + 1] = digit[i]
    }
    for (let i = 0; i < 10; i++) {
      digit[i] = digit2[i]
      digit2[i] = 0
    }
    for (let k = 0; k < 10; k++) {
      ans[j] = (ans[j] + digit[k]) % mod
    }
  }
  ans[0] = 2
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    // var n = BigInt(readline());
    var [n, m] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    // var [x, y] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    // var a = readline().split(' ').map((x, iii) => {
    //   return BigInt(x)
    // })

    a = n.toString().split('').map(x => {
      digit[parseInt(x)]++
      return parseInt(x)
    })

    var value = 0;

    for (let j = 0; j < a.length; j++) {
      if(m - (10 - a[j]) >= 0){
        value = (value + ans[m - (10 - a[j])]) % mod
      } else {
        value = (value + 1) % mod
      }
      // console.log(a[j], m - (10 - a[j]), value)
    }
    // console.log(value)
    res = res + value + '\n'
  })
  console.log(res)
}

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

var maxN = 2*1e5+1
var mod = 100000007

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  var res = ''
  var digit = new Array(10).fill(0)
  var digit2 = new Array(10).fill(0)
  var a = '10'
  a = a.split('').map(x => {
    digit[parseInt(x)]++
    parseInt(x)
  })
  var ans = new Array(maxN).fill(0)
  for (let j = 1; j < maxN + 1; j++) {
    for (let i = 0; i < 10; i++) {
      if (i === 9) {
        digit2[0] = (digit2[0] + digit[9]) % mod
        digit2[1] = (digit2[1] + digit[9]) % mod
        continue
      }
      digit2[i + 1] = digit[i]
    }
    for (let i = 0; i < 10; i++) {
      digit[i] = digit2[i]
      digit2[i] = 0
    }
    for (let k = 0; k < 10; k++) {
      ans[j] = (ans[j] + digit[k]) % mod
    }
  }
  ans[0] = 2
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    // var n = BigInt(readline());
    var [n, m] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    // var [x, y] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    // var a = readline().split(' ').map((x, iii) => {
    //   return BigInt(x)
    // })

    a = n.toString().split('').map(x => {
      digit[parseInt(x)]++
      return parseInt(x)
    })

    var value = 0;

    for (let j = 0; j < a.length; j++) {
      if(m - (10 - a[j]) >= 0){
        value = (value + ans[m - (10 - a[j])]) % mod
      } else {
        value = (value + 1) % mod
      }
      // console.log(a[j], m - (10 - a[j]), value)
    }
    // console.log(value)
    res = res + value + '\n'
  })
  console.log(res)
}


Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.There are $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ on Bob's homework paper, where $$$n$$$ is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least $$$2$$$ numbers. Suppose the numbers are divided into $$$m$$$ groups, and the sum of the numbers in the $$$j$$$-th group is $$$s_j$$$. Bob's aim is to minimize the sum of the square of $$$s_j$$$, that is $$$$$$\sum_{j = 1}^{m} s_j^2.$$$$$$Bob is puzzled by this hard problem. Could you please help him solve it?

The first line contains an even integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$), denoting that there are $$$n$$$ integers on Bob's homework paper. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^4$$$), describing the numbers you need to deal with.

A single line containing one integer, denoting the minimum of the sum of the square of $$$s_j$$$, which is $$$$$$\sum_{i = j}^{m} s_j^2,$$$$$$ where $$$m$$$ is the number of groups.

NoteIn the first sample, one of the optimal solutions is to divide those $$$4$$$ numbers into $$$2$$$ groups $$$\{2, 8\}, \{5, 3\}$$$. Thus the answer is $$$(2 + 8)^2 + (5 + 3)^2 = 164$$$.In the second sample, one of the optimal solutions is to divide those $$$6$$$ numbers into $$$3$$$ groups $$$\{1, 2\}, \{1, 2\}, \{1, 2\}$$$. Thus the answer is $$$(1 + 2)^2 + (1 + 2)^2 + (1 + 2)^2 = 27$$$.

"use strict";
function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");

  const N = Number(inputs[0]);
  const A = inputs[1].split(" ").map(Number);

  const sortedA = A.sort((a,b) => a-b);
  const B = [];
  if (sortedA.length % 2 === 1) {
    for (let i=1;i<= (sortedA.length-1)/2; i++) {
      B[i-1] = sortedA[i] + sortedA[N-i];
    }
  } else {
    for (let i=0; i <= (sortedA.length-1)/2; i++) {
      B[i] = sortedA[i] + sortedA[N-i-1];
    }
  }

  const sortedB = B.sort((a,b) => a-b);

  if (sortedA.length % 2 === 1) {
    B[0] += sortedA[0];
  }

  let result = B.reduce((acc, cur) => acc + cur * cur, 0);
  console.log(result);

}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  main(i)
})

"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};

function main(input) {
  var o = new I(input);

  const N = o.a();
  const A = o.l();

  const sortedA = A.sort((a,b) => a-b);
  const B = [];
  if (sortedA.length % 2 === 1) {
    for (let i=1;i<= (sortedA.length-1)/2; i++) {
      B[i-1] = sortedA[i] + sortedA[N-i];
    }
  } else {
    for (let i=0; i <= (sortedA.length-1)/2; i++) {
      B[i] = sortedA[i] + sortedA[N-i-1];
    }
  }

  const sortedB = B.sort((a,b) => a-b);

  if (sortedA.length % 2 === 1) {
    B[0] += sortedA[0];
  }

  let result = B.reduce((acc, cur) => acc + cur * cur, 0);
  console.log(result);

}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  main(i)
})

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

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

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  let ans = 0;
  let L = 0;
  let R = arr.length - 1;

  while (L < R) {
    ans += (arr[L] + arr[R]) ** 2;
    L++;
    R--;
  }

  console.log(ans);

  c++;
});

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

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

  const arr = d.split(' ').map(Number);
  arr.sort();

  let ans = 0;
  let L = 0;
  let R = arr.length - 1;

  while (L < R) {
    ans += (arr[L] + arr[R]) ** 2;
    L++;
    R--;
  }

  console.log(ans);

  c++;
});


It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days!When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day.The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is .You should write a program which will calculate average sleep times of Polycarp over all weeks.

The first line contains two integer numbers n and k (1 ≤ k ≤ n ≤ 2·105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).

Output average sleeping time over all weeks.  The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point.

NoteIn the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.

 var input = readline().split(' ');
var n = +input[0];
var k = +input[1];
var a = readline().split(' ');

var ans = 0;
for (var i = 0; i < n; i++) {
  a[i] = +a[i];
}
for (var i = 0; i < k; i++) {
  ans += a[i];
}

var val = ans;
for (var i = k; i < n; i++) {
  val += a[i];
  val -= a[i - k];
  ans += val;
}

print(ans / (n - k + 1));


The student council is preparing for the relay race at the sports festival.The council consists of $$$n$$$ members. They will run one after the other in the race, the speed of member $$$i$$$ is $$$s_i$$$. The discrepancy $$$d_i$$$ of the $$$i$$$-th stage is the difference between the maximum and the minimum running speed among the first $$$i$$$ members who ran. Formally, if $$$a_i$$$ denotes the speed of the $$$i$$$-th member who participated in the race, then $$$d_i = \max(a_1, a_2, \dots, a_i) - \min(a_1, a_2, \dots, a_i)$$$.You want to minimize the sum of the discrepancies $$$d_1 + d_2 + \dots + d_n$$$. To do this, you are allowed to change the order in which the members run. What is the minimum possible sum that can be achieved?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$)  — the number of members of the student council. The second line contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$1 \le s_i \le 10^9$$$)  – the running speeds of the members.

Print a single integer  — the minimum possible value of $$$d_1 + d_2 + \dots + d_n$$$ after choosing the order of the members.

NoteIn the first test case, we may choose to make the third member run first, followed by the first member, and finally the second. Thus $$$a_1 = 2$$$, $$$a_2 = 3$$$, and $$$a_3 = 1$$$. We have:  $$$d_1 = \max(2) - \min(2) = 2 - 2 = 0$$$.  $$$d_2 = \max(2, 3) - \min(2, 3) = 3 - 2 = 1$$$.  $$$d_3 = \max(2, 3, 1) - \min(2, 3, 1) = 3 - 1 = 2$$$. The resulting sum is $$$d_1 + d_2 + d_3 = 0 + 1 + 2 = 3$$$. It can be shown that it is impossible to achieve a smaller value.In the second test case, the only possible rearrangement gives $$$d_1 = 0$$$, so the minimum possible result is $$$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++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();
var a
var dp
function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  a.sort((a, b) => a - b)

  dp = new Array(n + 1)
  for (let i = 0; i < n + 1; i++) {
    dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)
  }
  console.log(solve(0, n - 1, a))
  // })
}

function solve(l, r) {
  if (l === r) return 0

  if(dp[l][r] !== Number.MAX_SAFE_INTEGER) return dp[l][r]
  var ans = Math.min(solve(l + 1, r), solve(l, r - 1))
  if(dp[l][r] === Number.MAX_SAFE_INTEGER) dp[l][r] = ans + a[r] - a[l]
  return ans + a[r] - a[l]
}

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

const mxN = 2010;

function main () {
	const n = rn();
	const s = rna();

	s.sort((x, y) => x - y);

	const dp = Array.from(Array(mxN), x => Array(mxN).fill(0));

	for (let k = 2; k <= n; k++) {
		for (let i = n-k; i >= 0; i--) {
			dp[i][k] = Math.min(dp[i][k-1], dp[i+1][k-1]) + s[i+k-1] - s[i];
		}
	}

	const ans = dp[0][n];

	console.log(ans);
}

let stdin = ''

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

process.stdin.on('end', () => {
  stdin = stdin.trim().split('\n').map(string => string.trim())
  main()
})

let currentLine = 0
function input() {
  return stdin[currentLine++]
}

function main() {
  const n = parseInt(input())

  const a = input()
    .split(' ')
    .map(s => parseInt(s))
    .sort((a, b) => a - b)

  const dp = new Array(n).fill(-1).map(_ => new Array(n).fill(-1))

  for (let i = 0; i < n; i++) {
    dp[i][i] = 0
  }

  for (let d = 1; d < n; d++) {
    for (let l = 0; l < n - d; l++) {
      const r = l + d
      dp[l][r] = a[r] - a[l] + Math.min(dp[l+1][r], dp[l][r-1])
    }
  }

  console.log(dp[0][n-1])
}

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

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  a.sort((a, b) => a - b)

  var dp = new Array(n + 1)
  for (let i = 0; i < n + 1; i++) {
    dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)
    dp[i][i] = 0
  }

  for (let k = 0; k < 2; k++) {
    for (let i = 0; i < n-1; i++) {
      for (let j = 1; j < n; j++) {
        // console.log(a[j], a[i], Math.min(dp[i + 1][j], dp[i][j - 1]))
          dp[i][j] = Math.min(dp[i][j], a[j] - a[i] + Math.min(dp[i + 1][j], dp[i][j - 1]))
      }
    }
  }
  console.log(dp[0][n-1])
  // })
}

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

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  a.sort((a, b) => a - b)

  var dp = new Array(n + 1)
  for (let i = 0; i < n + 1; i++) {
    dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)
    dp[i][i] = 0
  }

  // for (let k = 0; k < n; k++) {
    for (let i = 0; i < n; i++) {
      for (let j = i; j < n; j++) {
        // console.log(a[j], a[i], Math.min(dp[i + 1][j], dp[i][j - 1]))
        if (i < n - 1 && j > 0)
          dp[i][j] = Math.min(dp[i][j], a[j] - a[i] + Math.min(dp[i + 1][j], dp[i][j - 1]))
      }
    }
  // }
  console.log(dp[0][n-1])
  // })
}

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

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  a.sort((a, b) => a - b)
  var l = 0
  var r = n - 1
  var sum = a[r] - a[l]

  while (l !== r) {
    if (a[r] - a[l + 1] > a[r - 1] - a[l]) {
      r--
    } else l++
    sum += a[r] - a[l]
    // console.log(sum, l, r)
  }
  console.log(sum)
  // })
}

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

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  var sum = 0
  for (let i = 0; i < n; i++) {
    sum += a[i]
  }
  var medd = sum / n
  var med
  var res = Number.MAX_SAFE_INTEGER
  for (let i = 0; i <= n; i++) {
    med = aa[i]
    if (i === n) med = medd

    a = a.sort((a, b) => {
      var a1 = a - med > 0 ? a - med : med - a
      var b1 = b - med > 0 ? b - med : med - b
      return a1 > b1 ? 1 : -1
    })

    var min = a[0]
    var max = a[0]
    sum = 0

    for (let j = 0; j < n; j++) {
      min = Math.min(min, a[j])
      max = Math.max(max, a[j])
      sum += max - min
    }
    // console.log(sum)
    // console.log(a)
    res = Math.min(res, sum)
  }

  for (let i = 1; i < n; i++) {
    med = (aa[i] - aa[i-1]) / 2
    a = a.sort((a, b) => {
      var a1 = a - med > 0 ? a - med : med - a
      var b1 = b - med > 0 ? b - med : med - b
      return a1 > b1 ? 1 : -1
    })

    var min = a[0]
    var max = a[0]
    sum = 0

    for (let j = 0; j < n; j++) {
      min = Math.min(min, a[j])
      max = Math.max(max, a[j])
      sum += max - min
    }
    // console.log(sum)
    // console.log(a)
    res = Math.min(res, sum)
  }

  console.log(res)
  // })
}

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

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  var sum = 0
  for (let i = 0; i < n; i++) {
    sum += a[i]
  }
  var medd = sum / n
  var med
  var res = Number.MAX_SAFE_INTEGER
  for (let i = 0; i <= n; i++) {
    med = aa[i]
    if (i === n) med = medd

    a = a.sort((a, b) => {
      var a1 = a - med > 0 ? a - med : med - a
      var b1 = b - med > 0 ? b - med : med - b
      return a1 > b1 ? 1 : -1
    })

    var min = a[0]
    var max = a[0]
    sum = 0

    for (let j = 0; j < n; j++) {
      min = Math.min(min, a[j])
      max = Math.max(max, a[j])
      sum += max - min
    }
    // console.log(sum)
    // console.log(a)
    res = Math.min(res, sum)
  }

  console.log(res)
  // })
}


Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it.In the beginning, uncle Bogdan wrote on a board a positive integer $$$x$$$ consisting of $$$n$$$ digits. After that, he wiped out $$$x$$$ and wrote integer $$$k$$$ instead, which was the concatenation of binary representations of digits $$$x$$$ consists of (without leading zeroes). For example, let $$$x = 729$$$, then $$$k = 111101001$$$ (since $$$7 = 111$$$, $$$2 = 10$$$, $$$9 = 1001$$$).After some time, uncle Bogdan understood that he doesn't know what to do with $$$k$$$ and asked Denis to help. Denis decided to wipe last $$$n$$$ digits of $$$k$$$ and named the new number as $$$r$$$.As a result, Denis proposed to find such integer $$$x$$$ of length $$$n$$$ that $$$r$$$ (as number) is maximum possible. If there are multiple valid $$$x$$$ then Denis is interested in the minimum one.All crew members, including captain Flint himself, easily solved the task. All, except cabin boy Kostya, who was too drunk to think straight. But what about you?Note: in this task, we compare integers ($$$x$$$ or $$$k$$$) as numbers (despite what representations they are written in), so $$$729 < 1999$$$ or $$$111 < 1000$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain test cases — one per test case. The one and only line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the integer $$$x$$$ you need to find. It's guaranteed that the sum of $$$n$$$ from all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print the minimum integer $$$x$$$ of length $$$n$$$ such that obtained by Denis number $$$r$$$ is maximum possible.

NoteIn the second test case (with $$$n = 3$$$), if uncle Bogdan had $$$x = 998$$$ then $$$k = 100110011000$$$. Denis (by wiping last $$$n = 3$$$ digits) will obtain $$$r = 100110011$$$.It can be proved that the $$$100110011$$$ is the maximum possible $$$r$$$ Denis can obtain and $$$998$$$ is the minimum $$$x$$$ to obtain it.

var T = +readline();
while (T) {
    T -= 1;
    var n = +readline();
    var ans = "";
    var cnt = Math.floor((n + 3) / 4);
    for (var index = 0; index < n - cnt; index++) {
        //const element = array[index];
        ans += "9";
    }
    for (var index = 0; index < cnt; index++) {
        //const element = array[index];
        ans += "8";
    }
    print(ans);
}

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] * 1;
	let i = 1;
	while (i <= testCases) {
	  let n = data[i] * 1;
	  if (n == 1) {
	    console.log(8);
	    i += 1;
	    continue;
	  }
	  let r = Math.ceil(n / 4);
	  let num = '9'.repeat(n - r);
	  num += '8'.repeat(r);
	  console.log(num);
    i += 1;
	}
}

var read = require('readline').createInterface({
   input: process.stdin
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
   obj = init(inLine);
   var start = Date.now();
   Main();
   console.error("\n");
   var end = Date.now() - start;
   myerr("time : " + (end) + "ms");
   myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function input(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
    var returnObj = {
      list : input, index : 0, max : input.length,
      hasNext : function(){return (this.index < this.max);},
      next : function(){
        if(!this.hasNext()){

            throw "ArrayIndexOutOfBoundsException これ以上ないよ";
        }
        else{
            var returnInput = this.list[this.index];
            this.index++;
            return returnInput;
        }
    }};
    return returnObj;
}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
function puts(s){console.log(s);}
function print(s) {process.stdout.write(s+"");}

function Main(){
    tc = parseInt(input())
    while(tc--) {
        n = parseInt(input())
        k = Math.ceil(n/4)
        g = n - k
        arr = []
        for(let i=0;i<g;i++) {
            arr.push('9')
        }
        for(let i=0;i<k;i++) {
            arr.push('8')
        }
        puts(arr.join(""))
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    let t = parseInt(readline());

    for(let o = 0; o < t; o++){
        let n = parseInt(readline());

        if(n % 4 === 0){
            let en = '';
            let y = Math.floor(n/4);
            while(y > 0){
                en += '8';
                y -= 1;
            }

            let st = '';
            let x = n - en.length;
            while(x > 0){
                st += '9';
                x--;
            }

            console.log(st+en);
            continue;
        }else{
            let en = '';
            let y = Math.floor(n/4) + 1;
            while(y > 0){
                en += '8';
                y -= 1;
            }

            let st = '';
            let x = n - en.length;
            while(x > 0){
                st += '9';
                x--;
            }

            console.log(st+en);
            continue;
        }
    }
}

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] * 1;
	let i = 1;
	while (i <= testCases) {
	  let n = data[i] * 1;
	  if (n == 1) {
	    console.log(8);
	    i += 1;
	    continue;
	  }
	  let r = Math.ceil(n / 4);
	  let num = '9'.repeat(n - r);
	  num += '8'.repeat(r);
	  console.log(num * 1);
    i += 1;
	}
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    let t = parseInt(readline());

    for(let o = 0; o < t; o++){
        let n = parseInt(readline());

        if(n % 4 === 0){
            let res = '';
            let x = (4*n) - Math.floor(n/4);
            while(x > 4){
                res += '9';
                x -= 4;
            }

            let y = n/4;
            while(y > 0){
                res += '8';
                y -= 1;
            }

            console.log(parseInt(res));
            continue;
        }else{
            let res = '';
            let x = (4*n) - Math.floor(n/4);
            while(x > 4){
                res += '9';
                x -= 4;
            }

            let y = Math.floor(n/4) + 1;
            while(y > 0){
                res += '8';
                y -= 1;
            }

            console.log(parseInt(res));
            continue;
        }
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    let t = parseInt(readline());

    for(let o = 0; o < t; o++){
        let n = parseInt(readline());

        if(n % 4 === 0){
            let en = '';
            let y = Math.floor(n/4);
            while(y > 0){
                en += '8';
                y -= 1;
            }

            let st = '';
            let x = n - en.length;
            while(x > 0){
                st += '9';
                x--;
            }

            console.log(parseInt(st + en));
            continue;
        }else{
            let en = '';
            let y = Math.floor(n/4) + 1;
            while(y > 0){
                en += '8';
                y -= 1;
            }

            let st = '';
            let x = n - en.length;
            while(x > 0){
                st += '9';
                x--;
            }

            console.log(parseInt(st + en));
            continue;
        }
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    let t = parseInt(readline());

    for(let o = 0; o < t; o++){
        let n = parseInt(readline());

        if(n % 4 === 0){
            let res = '';
            let x = (4*n) - Math.floor(n/4);
            while(x > 4){
                res += '9';
                x -= 4;
            }

            let y = n/4;
            while(y > 0){
                res += '8';
                y -= 1;
            }

            console.log(parseInt(res));
            continue;
        }else{
            let res = '';
            let x = 4 * (n-1);
            while(x > 4){
                res += '9';
                x -= 4;
            }

            let y = Math.floor(n/4) + 1;
            while(y > 0){
                res += '8';
                y -= 1;
            }

            console.log(parseInt(res));
            continue;
        }
    }
}


You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that:  the length of both arrays is equal to $$$m$$$;  each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive);  $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$;  array $$$a$$$ is sorted in non-descending order;  array $$$b$$$ is sorted in non-ascending order. As the result can be very large, you should print it modulo $$$10^9+7$$$.

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$1 \le m \le 10$$$).

Print one integer – the number of arrays $$$a$$$ and $$$b$$$ satisfying the conditions described above modulo $$$10^9+7$$$.

! function (e) {
  var n = {};

  function t(r) {
    if (n[r]) return n[r].exports;
    var o = n[r] = {
      i: r,
      l: !1,
      exports: {}
    };
    return e[r].call(o.exports, o, o.exports, t), o.l = !0, o.exports
  }
  t.m = e, t.c = n, t.d = function (e, n, r) {
    t.o(e, n) || Object.defineProperty(e, n, {
      enumerable: !0,
      get: r
    })
  }, t.r = function (e) {
    "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {
      value: "Module"
    }), Object.defineProperty(e, "__esModule", {
      value: !0
    })
  }, t.t = function (e, n) {
    if (1 & n && (e = t(e)), 8 & n) return e;
    if (4 & n && "object" == typeof e && e && e.__esModule) return e;
    var r = Object.create(null);
    if (t.r(r), Object.defineProperty(r, "default", {
        enumerable: !0,
        value: e
      }), 2 & n && "string" != typeof e)
      for (var o in e) t.d(r, o, function (n) {
        return e[n]
      }.bind(null, o));
    return r
  }, t.n = function (e) {
    var n = e && e.__esModule ? function () {
      return e.default
    } : function () {
      return e
    };
    return t.d(n, "a", n), n
  }, t.o = function (e, n) {
    return Object.prototype.hasOwnProperty.call(e, n)
  }, t.p = "", t(t.s = 0)
}([function (e, n) {
  process.stdin.resume(), process.stdin.setEncoding("utf-8");
  var t = "";
  process.stdin.on("data", e => {
    t += e
  }), process.stdin.on("end", () => {
    t = t.split("\n").map(e => e.replace(/(\r\n|\n|\r)/gm, "")),
      function (e) {
        const [n, r] = void 0 === o ? t.shift().split(" ").map(e => parseInt(e)) : t[o].split(" ").map(e => parseInt(e));
        var o;
        ! function (...e) {
          console.log(...e)
        }(function (e, n, t) {
          if (0 == n) return 1;
          const r = new Array(n + 1).fill(0);
          r[0] = 1;
          for (let o = 1; o <= e; o++)
            for (let e = Math.min(o, n); e > 0; e--) r[e] = (r[e] + r[e - 1]) % t;
          return r[n]
        }(n + 2 * r - 1, 2 * r, 1e9 + 7))
      }()
  })
}]);

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

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

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

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

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

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

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

function powM(base, exponent, mod) {
  if(exponent == 0) return 1
  else if(exponent % 2 == 0) return Math.pow(powM(base, exponent / 2, mod), 2) % mod
  else return (base * powM(base, exponent - 1, mod)) % mod
}

function inverseMod(num, prime) {
  return powM(num, prime - 2, prime)
}

function nCrMod(n, r, p) {
  if(r == 0) return 1

  const pascalTriangle = new Array(r + 1).fill(0)

  pascalTriangle[0] = 1

  for(let i = 1; i <= n; i++) {
    for(let j = Math.min(i, r); j > 0; j--) {
      pascalTriangle[j] = (pascalTriangle[j] + pascalTriangle[j - 1]) % p
    }
  }
  return pascalTriangle[r]
}

function main(input) {
  const [n, m] = readInts(input)

  const mod = 10 ** 9 + 7
  wr(nCrMod(n + 2 * m - 1, 2 * m, mod))
}

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

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

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

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

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

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

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

function main(input) {
  const [n, m] = readInts(input)
  const m2 = 2 * m

  const dp = new Array(m2 + 1)
  const mod = 10 ** 9 + 7

  for(let i = 0; i <= m2; i++) {
    dp[i] = new Array(n + 1)
  }

  for(let i = 1; i <= m2; i++) {
    dp[i][0] = 0
  }

  for(let i = 1; i <= n; i++) {
    dp[1][i] = i
  }

  for(let i = 2; i <= m2; i++) {
    for(let j = 1; j <= n; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod
    }
  }

  // wr(dp)
  wr(dp[m2][n])

}