Polycarp has come up with a new game to play with you. He calls it "A missing bigram".A bigram of a word is a sequence of two adjacent letters in it.For example, word "abbaaba" contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".The game goes as follows. First, Polycarp comes up with a word, consisting only of lowercase letters 'a' and 'b'. Then, he writes down all its bigrams on a whiteboard in the same order as they appear in the word. After that, he wipes one of them off the whiteboard.Finally, Polycarp invites you to guess what the word that he has come up with was.Your goal is to find any word such that it's possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$3 \le n \le 100$$$) — the length of the word Polycarp has come up with. The second line of each testcase contains $$$n-2$$$ bigrams of that word, separated by a single space. Each bigram consists of two letters, each of them is either 'a' or 'b'. Additional constraint on the input: there exists at least one string such that it is possible to write down all its bigrams, except one, so that the resulting sequence is the same as the sequence in the input. In other words, the answer exists.

For each testcase print a word, consisting of $$$n$$$ letters, each of them should be either 'a' or 'b'. It should be possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with. The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.

4
7
ab bb ba aa ba
7
ab ba aa ab ba
3
aa
5
bb ab bb

NoteThe first two testcases from the example are produced from the word "abbaaba". As listed in the statement, it contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".In the first testcase, the $$$5$$$-th bigram is removed. In the second testcase, the $$$2$$$-nd bigram is removed. However, that sequence could also have been produced from the word "abaabaa". It contains bigrams "ab", "ba", "aa", "ab", "ba" and "aa". The missing bigram is the $$$6$$$-th one.In the third testcase, all of "baa", "aab" and "aaa" are valid answers.

    // your code goes here
    const fs = require('fs');
    const input = fs.readFileSync(0, 'utf8').trim().split('\n');
    let currentline = 0;
    function readline(){
        return input[currentline++];
    }
    var T = readline();
    for(var q =1;q<=T;q++) {
        var n = readline()
        var ar = readline().split(' ')
        var anc = ''
        anc += ar[0][0]
        if(2*ar.length < n) {
        	anc += ar[0][1]
        	for(var i=1;i<ar.length;i++) {
        		anc += ar[i][0]
        		anc += ar[i][1]
        	}
        	if(anc.length < n) {
        		while(anc.length < n) { anc += ar[i-1][1] }
        	}
        	console.log(anc)
        } else {
        	var i = 1, j = 1;
        	while(anc.length < n && i < ar.length) {
        		if(ar[i-1][j] == ar[i][j-1]) {
        			anc += ar[i][0]
        			i++;
        		} else {
        			anc += ar[i-1][j]
        			anc += ar[i][j-1]
        			i++;
        		}
        	}
        	if(anc.length < n) {
        		while(anc.length < n ) { anc += ar[i-1][1] }
        	}
        	console.log(anc)
        }
    }

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

  main(lines);
});

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

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

function solve(N, input) {
  let arr = [input[0]];
  let result = '';

  for (let i = 1; i < input.length; ++i) {
    if (input[i][0] !== input[i - 1][1]) {
      arr.push(input[i - 1][1] + input[i][0]);
    }

    arr.push(input[i]);
  }

  if (arr.length !== N - 1) {
    arr.push(arr[arr.length - 1][1] === 'a' ? 'ab' : 'ba');
  }

  result = arr[0];

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

  console.log(result);
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const bgs = rl().split(' ');

		let ans = '';
		for (const bg of bgs) {
			if (ans.slice(-1) == bg[0])
				ans += bg[1];
			else
				ans += bg;
		}

		if (ans.length < n)
			ans += 'a';

		console.log(ans);
	}
}

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let n = nl.num();
		let a = nl.array();
		let r = [];
		for(let j = 0; j < n - 2; j++){
			if (j == 0){
				r.push(a[j].charAt(0));
				r.push(a[j].charAt(1));
			} else {
				if (a[j-1].charAt(1) != a[j].charAt(0)){
					r.push(a[j].charAt(0));
				}
				r.push(a[j].charAt(1));
			}
		}
		if (r.length < n){
			r.push(r[r.length -1]);
		}
		ans.push(r.join(''));

	}
	console.log(ans.join('\n'));
};

process.stdin.on('end', sol);

// let s = ['ab', 'bb', 'ba', 'aa', 'ba'];
// let k = 7;
// let s = ['aa'];
// let k = 3;
let n = null, m = null, a=[], b=[];
const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

readline.on('line', line => {
    if (n == null) {
        n = parseInt(line)
        m = n * 2
    } else if (m>0) {
        if (m%2==0)
        b.push(parseInt(line))
        else
        a.push(line.split(' '))
        m--;

    }
    if (m == 0) {
        readline.close();
        main();
    }
});

function main(){
    a.forEach((s,j)=> {
        let res = "";
        for (let i = 0 ; i < s.length-1; i++) {
            if (s[i][1] == s[i+1][0]) res+=s[i][0];
            else res += s[i];
        }
        res += s.pop();
        if (res.length < b[j]) res+='a';
        console.log(res)
    });
}
// main();

// 'ab' 'bb' 'ba' 'aa' 'ab' 'ba'
// 'ab' 'bb' 'ba' 'aa' 'ba'
// 'a' 'b' 'b' 'aa' 'ba'
// 'a' 'b' 'b' 'aa' 'ba'
// abbaaba

// bbabb

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' '))
        main()
        process.exit(0)
    }
})

function solve([n], arr) {
    let res = '', flag = false
    res += arr[0][0]
    for (let i = 0; i < n - 3; i++) {
        if (arr[i][1] != arr[i + 1][0]) {
            res += arr[i][1];
            res += arr[i + 1][0];
            flag = true;
        } else {
            res += arr[i + 1][0];
        }
    }
    res += arr[n - 3][1]
    if (!flag) {
        res += arr[n - 3][1];
    }
    console.log(res)
}

function main() {
    for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])
}

//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 if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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();
	while(hasNext()){
		var N = nextInt();
		var list = nextStrArray(N - 2);
		var ok = false;
		var output = list[0][0];
		for(var i = 0; i < N - 3; i++){
			output += list[i][1];
			if(list[i][1] != list[i + 1][0]){
				output += list[i + 1][0];
				ok = true;
			}
		}
		output += list[N - 3][1];
		if(!ok){
			output += "a";
		}
		myout(output);
	}
}

    var len = readline();
    for(var i=0;i<+len;i++)
    {
     var lenth = readline();
     var inputData = readline().split(' ');
     var str ='';
     for(var j=0;j<inputData.length;j++)
     {
         if(str[str.length-1] != inputData[j][0])
         str+=inputData[j];
         else
         str+=inputData[j][1];
     }
     if(str.length < lenth)
           print(str+'a');
           else
           print(str);
    }

var len = readline();
for(var i=0;i<+len;i++)
{
 var lenth = readline();
 var inputData = readline().split(' ');
 var str ='';
 for(var j=0;j<inputData.length;j++)
 {
    // if(inputData[j].length ==1 && +lenth>2)
     //{
       //  str+=inputData[i]+'a';
     ////}
     //else{
     if(str[str.length-1] != inputData[j][0])
     str+=inputData[j];
     else
     str+=inputData[j][1];

  //   }
 }
 if(str.length < lenth)
       print(str+'a');
       else
       print(str);

}

"use strict";

function answer(wordLength, bigrams) {
    let lastBigram = null;
    let word = '';
    for (let i = 0; i < bigrams.length; i += 1) {
        const bigram = bigrams[i];
        if (lastBigram === null) {
            word += bigram;
            lastBigram = bigram;
            continue;
        }

        if (lastBigram[1] !== bigram[0]) {
            word += bigram;
        } else {
            word += bigram[1];
        }
        lastBigram = bigram;
    }

    if (word.length < wordLength) {
        word += 'a';
    }

    return word;
}

const nQueues = this.readline().split(" ");

for (let i = 0; i < nQueues; i++) {
    const wordLength = this.readline();
    const bigrams = this.readline().split(" ");
    const result = answer(wordLength, bigrams);
    this.print(result)
}

var s = parseInt(readline());
  while (s--) {
    var n = parseInt(readline());
    var str = readline().split(" ");
    var string = str[0];
    for (var i = 1; i < str.length; i++) {
      var st = str[i];
      if (string[string.length - 1] === st[0]) {
        string += st[1];
      } else {
        string += st;
      }
    }
    if (string.length < n) {
      string += "a";
    }
    print(string);
  }

"use strict";

function answer(s) {
  if (s.length > 10) return s[0] + (s.length - 2) + s[s.length - 1];
  return s;
}

const nQueues = this.readline().split(" ");

for (let i = 0; i < nQueues; i++) {
  const length = Number(this.readline());
  const bigrams = this.readline().split(' ');
  let word = ''
  let found = false
  for(let i= 0; i< bigrams.length-1; i++) {
    const a = bigrams[i]
    const b = bigrams[i+1]
    if(a[1] === b[0]){
      word+= a[0]
    } else {
      found = true
      word+= a
    }
  }
  word+= bigrams[bigrams.length-1]
  if(!found) word+='a'
  this.print(word)
}

// your code goes here
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q =1;q<=T;q++) {
    var n = readline()
    var a = readline().split(' ')
    var ans = ''
    var anc = ''
    for(var i=0;i<a.length;i++) {
        anc += a[i]
    }
    for(var i=0;i<(anc.length-4);i++) {
        ans += anc[i]
    }
    console.log(ans)
}

var len = readline();
for(var i=0;i<+len;i++)
{
 var lenth = readline();
 var inputData = readline().split(' ');
 var str ='';
 for(var j=0;j<inputData.length;j++)
 {
     if(inputData[j].length ==1 && +lenth>2)
     {
         str+=inputData[i]+'a';
     }
     else{
     if(str[str.length-1] != inputData[j][0])
     str+=inputData[j];
     else
     str+=inputData[j][1];
     }
 }
       print(str);

}

var len = readline();
for(var i=0;i<+len;i++)
{
 var lenth = readline();
 var inputData = readline().split(' ');
 var str ='';
 for(var j=0;j<inputData.length;j++)
 {
     if(inputData[j].length ==1 && +lenth>2)
     {
         str+=inputData[i]+'a';
     }
     else{
     if(str[str.length-1] != inputData[j][0])
     str+=inputData[j];
     else
     str+inputData[j][1];
     }
 }
       print(str);

}

var len = readline();
for(var i=0;i<+len;i++)
{
 var lenth = readline();
 var inputData = readline().split(' ');
 var str ='';
 for(var j=0;j<inputData.length;j++)
 {
     if(str[str.length-1] != inputData[j][0])
     str+=inputData[j];
     else
     str+inputData[j][1];
 }
}
/*for(var j=1;j*j<=+inputData;j++)
{
   count.add(j*j);
}
for(var k=1;k*k*k<=+inputData;k++)
{
   count.add(k*k*k);
}
print(count.size);*/


There are $$$n$$$ blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed $$$3 \cdot n$$$. If it is impossible to find such a sequence of operations, you need to report it.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 200$$$) — the number of blocks. The second line contains one string $$$s$$$ consisting of $$$n$$$ characters, each character is either "W" or "B". If the $$$i$$$-th character is "W", then the $$$i$$$-th block is white. If the $$$i$$$-th character is "B", then the $$$i$$$-th block is black.

If it is impossible to make all the blocks having the same color, print $$$-1$$$. Otherwise, print an integer $$$k$$$ ($$$0 \le k \le 3 \cdot n$$$) — the number of operations. Then print $$$k$$$ integers $$$p_1, p_2, \dots, p_k$$$ $$$(1 \le p_j \le n - 1)$$$, where $$$p_j$$$ is the position of the left block in the pair of blocks that should be affected by the $$$j$$$-th operation. If there are multiple answers, print any of them.

NoteIn the first example, it is possible to make all blocks black in $$$3$$$ operations. Start with changing blocks $$$6$$$ and $$$7$$$, so the sequence is "BWWWWBBB". Then change blocks $$$2$$$ and $$$3$$$, so the sequence is "BBBWWBB". And finally, change blocks $$$4$$$ and $$$5$$$, so all blocks are black.It is impossible to make all colors equal in the second example.All blocks are already white in the third example.In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks $$$2$$$ and $$$3$$$ (so the sequence is "BBW"), and then change blocks $$$1$$$ and $$$2$$$ (so all blocks are white).

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, ''))

  const n = parseInt(arr[0])

  const str = arr[1]
  let a = str.split('')

  // white
  let count = 0
  let flag = false
  let ans = []

  for(let i = 0; i < n - 1; i++) {
    if(a[i] == 'W') continue
    else {
      count ++
      ans.push(i + 1)
      a[i] = 'W'
      if(a[i + 1] == 'W') a[i + 1] = 'B'
      else a[i + 1] = 'W'
    }
  }

  for(let i = 0; i < n; i++) {
    if(a[i] == 'B') {
      flag = true
      break
    }
  }

  if(!flag) {
    // console.log(a)
    console.log(count)
    if(count != 0) console.log(ans.join(' '))
  }
  else {
    // black
    count = 0
    flag = false
    ans = []
    a = str.split('')

    for(let i = 0; i < n - 1; i++) {
      // console.log(a)
      if(a[i] == 'B') continue
      else {
        count ++
        ans.push(i + 1)
        a[i] = 'B'
        if(a[i + 1] == 'W') a[i + 1] = 'B'
        else a[i + 1] = 'W'
      }
    }

    for(let i = 0; i < n; i++) {
      if(a[i] == 'W') {
        flag = true
        break
      }
    }

    if(!flag) {
      // console.log('black', a)
      console.log(count)
      if(count != 0) console.log(ans.join(' '))
    }
    else {
      console.log(-1)
    }
  }

})

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, ''))

  const n = parseInt(arr[0])

  const str = arr[1]
  const a = str.split('')

  // white
  let count = 0
  let flag = false
  let ans = []

  for(let i = 0; i < n - 1; i++) {
    if(a[i] == 'W') continue
    else {
      count ++
      ans.push(i + 1)
      a[i] = 'W'
      if(a[i + 1] == 'W') a[i + 1] = 'B'
      else a[i + 1] = 'W'
    }
  }

  for(let i = 0; i < n; i++) {
    if(a[i] == 'B') {
      flag = true
      break
    }
  }

  if(!flag) {
    console.log(count)
    if(count != 0) console.log(ans.join(' '))
  }
  else {
    // black
    count = 0
    flag = false
    ans = []

    for(let i = 0; i < n - 1; i++) {
      if(a[i] == 'B') continue
      else {
        count ++
        ans.push(i + 1)
        a[i] = 'B'
        if(a[i + 1] == 'W') a[i + 1] = 'B'
        else a[i + 1] = 'W'
      }
    }

    for(let i = 0; i < n; i++) {
      if(a[i] == 'W') {
        flag = true
        break
      }
    }

    if(!flag) {
      console.log(count)
      if(count != 0) console.log(ans.join(' '))
    }
    else {
      console.log(-1)
    }
  }

})


Carol is currently curling.She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100.She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She will then push it so the disk’s y coordinate continuously decreases, and x coordinate stays constant. The disk stops once it touches the line y = 0 or it touches any previous disk. Note that once a disk stops moving, it will not move again, even if hit by another disk. Compute the y-coordinates of centers of all the disks after all disks have been pushed.

The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively. The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.

Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6. Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker program will consider your answer correct if  for all coordinates.

NoteThe final positions of the disks will look as follows:  In particular, note the position of the last disk.

'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

{
    var kr = readline,
        chr = String.fromCodePoint,
        ord = function ord(v, i) {
        return v.charCodeAt(i);
    };
    var krr = function krr() {
        var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';
        return kr().split(sp);
    };
    var S = String,
        N = Number,
        A = function A() {
        for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {
            a[_key] = arguments[_key];
        }

        return new (Function.prototype.bind.apply(Array, [null].concat(a)))();
    };
    var M = function M(l, f) {
        var r = A(l);for (var i = 0; i < l; i++) {
            r[i] = f(i);
        }return r;
    };
    var kt = function kt(m, d) {
        return d.map(function (v, i) {
            return m[i](v);
        });
    };
    //////////////////////////////////////////////////////////////////////////////
    var dist = function dist(x1, y1, x2, y2) {
        return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
    };
    var gp = function gp(x, y, r, x2) {
        var v = Math.pow(r, 2) - Math.pow(x - x2, 2);
        if (v < 0) return 0;
        return Math.sqrt(v) + y;
    };

    var _kt = kt([N, N], krr()),
        _kt2 = _slicedToArray(_kt, 2),
        n = _kt2[0],
        r = _kt2[1];

    var l = krr().map(N),
        SZ = 1100;
    var d = A(SZ),
        xx = M(SZ, function () {
        return A();
    });

    l.forEach(function (x, i) {
        var y = r;

        var _loop = function _loop(xi) {
            xx[xi].forEach(function (yi) {
                y = Math.max(y, gp(xi, yi, 2 * r, x));
            });
        };

        for (var xi = Math.max(1, x - r * 2); xi < Math.min(SZ, x + r * 2 + 1); xi++) {
            _loop(xi);
        }
        xx[x].push(y);
        d[i] = y;
    });
    print(d.slice(0, n).join(' '));
}

'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

{
    var kr = readline,
        chr = String.fromCodePoint,
        ord = function ord(v, i) {
        return v.charCodeAt(i);
    };
    var krr = function krr() {
        var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';
        return kr().split(sp);
    };
    var S = String,
        N = Number,
        A = function A() {
        for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {
            a[_key] = arguments[_key];
        }

        return new (Function.prototype.bind.apply(Array, [null].concat(a)))();
    };
    var kt = function kt(m, d) {
        return d.map(function (v, i) {
            return m[i](v);
        });
    };
    //////////////////////////////////////////////////////////////////////////////
    var dist = function dist(x1, y1, x2, y2) {
        return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
    };
    var gp = function gp(x, y, r, x2) {
        var v = Math.pow(r, 2) - Math.pow(x - x2, 2);
        if (v < 0) return 0;
        return Math.sqrt(v) + y;
    };

    var _kt = kt([N, N], krr()),
        _kt2 = _slicedToArray(_kt, 2),
        n = _kt2[0],
        r = _kt2[1];

    var l = krr().map(N),
        SZ = 1000;
    var d = A(SZ),
        xx = A();
    for (var i = 0; i < 2000; i++) {
        xx[i] = A();
    }l.forEach(function (x, i) {
        var y = r;

        var _loop = function _loop(xi) {
            xx[xi].forEach(function (yi) {
                y = Math.max(y, gp(xi, yi, 2 * r, x));
            });
        };

        for (var xi = Math.max(1, x - r * 3); xi <= Math.min(1000, x + r * 3); xi++) {
            _loop(xi);
        }
        xx[x].push(y);
        d[i] = y;
    });
    print(d.slice(0, n).join(' '));
}

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
vec[0]=Number(r);
for(i=1;i<n;i++){
	hit = false;
	vec[i]=Number(-1);
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		vec[i]=Math.max(vec[i],(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));
	}
	if(hit===false){
		vec[i]=Number(r);
	}
	ans+=" "+vec[i];
}
print(ans);

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var vec=[];
vec[0]=Number(r);
print(r);
for(i=1;i<n;i++){
	vec[i]=Number(r);
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		vec[i]=Math.max(vec[i],(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));
	}
	print(vec[i]);
}

'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

{
    var kr = readline,
        chr = String.fromCodePoint,
        ord = function ord(v, i) {
        return v.charCodeAt(i);
    };
    var krr = function krr() {
        var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';
        return kr().split(sp);
    };
    var S = String,
        N = Number,
        A = function A() {
        for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {
            a[_key] = arguments[_key];
        }

        return new (Function.prototype.bind.apply(Array, [null].concat(a)))();
    };
    var M = function M(l, f) {
        var r = A(l);for (var i = 0; i < l; i++) {
            r[i] = f(i);
        }return r;
    };
    var kt = function kt(m, d) {
        return d.map(function (v, i) {
            return m[i](v);
        });
    };
    //////////////////////////////////////////////////////////////////////////////
    var dist = function dist(x1, y1, x2, y2) {
        return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
    };
    var gp = function gp(x, y, r, x2) {
        var v = Math.pow(r, 2) - Math.pow(x - x2, 2);
        if (v < 0) return 0;
        return Math.sqrt(v) + y;
    };

    var _kt = kt([N, N], krr()),
        _kt2 = _slicedToArray(_kt, 2),
        n = _kt2[0],
        r = _kt2[1];

    var l = krr().map(N),
        SZ = 1100;
    var d = A(SZ),
        xx = M(SZ, function () {
        return A();
    });

    l.forEach(function (x, i) {
        var y = r;

        var _loop = function _loop(xi) {
            xx[xi].forEach(function (yi) {
                y = Math.max(y, gp(xi, yi, 2 * r, x));
            });
        };

        for (var xi = Math.max(1, x - r * 2); xi < Math.min(SZ, x + r * 2); xi++) {
            _loop(xi);
        }
        xx[x].push(y);
        d[i] = y;
    });
    print(d.slice(0, n).join(' '));
}

'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

{
    var kr = readline,
        chr = String.fromCodePoint,
        ord = function ord(v, i) {
        return v.charCodeAt(i);
    };
    var krr = function krr() {
        var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';
        return kr().split(sp);
    };
    var S = String,
        N = Number,
        A = function A() {
        for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {
            a[_key] = arguments[_key];
        }

        return new (Function.prototype.bind.apply(Array, [null].concat(a)))();
    };
    var kt = function kt(m, d) {
        return d.map(function (v, i) {
            return m[i](v);
        });
    };
    //////////////////////////////////////////////////////////////////////////////
    var dist = function dist(x1, y1, x2, y2) {
        return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
    };
    var gp = function gp(x, y, r, x2) {
        return Math.sqrt(Math.pow(r, 2) - Math.pow(x - x2, 2)) + y;
    };

    var _kt = kt([N, N], krr()),
        _kt2 = _slicedToArray(_kt, 2),
        n = _kt2[0],
        r = _kt2[1];

    var l = krr().map(N),
        SZ = 2000;
    var d = A(SZ),
        xx = A();
    for (var i = 0; i < SZ; i++) {
        xx[i] = A();
    }l.forEach(function (x, i) {
        var y = r;

        var _loop = function _loop(xi) {
            xx[xi].forEach(function (yi) {
                y = Math.max(y, gp(xi, yi, 2 * r, x));
            });
        };

        for (var xi = Math.max(0, x - r * 2); xi < Math.min(SZ, x + r * 2); xi++) {
            _loop(xi);
        }
        xx[x].push(y);
        d[i] = y;
    });
    print(d.slice(0, n).join(' '));
}

'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

{
    var kr = readline,
        chr = String.fromCodePoint,
        ord = function ord(v, i) {
        return v.charCodeAt(i);
    };
    var krr = function krr() {
        var sp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';
        return kr().split(sp);
    };
    var S = String,
        N = Number,
        A = function A() {
        for (var _len = arguments.length, a = Array(_len), _key = 0; _key < _len; _key++) {
            a[_key] = arguments[_key];
        }

        return new (Function.prototype.bind.apply(Array, [null].concat(a)))();
    };
    var kt = function kt(m, d) {
        return d.map(function (v, i) {
            return m[i](v);
        });
    };
    //////////////////////////////////////////////////////////////////////////////
    var dist = function dist(x1, y1, x2, y2) {
        return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
    };
    var gp = function gp(x, y, r, x2) {
        return Math.sqrt(Math.pow(r, 2) - Math.pow(x - x2, 2)) + y;
    };

    var _kt = kt([N, N], krr()),
        _kt2 = _slicedToArray(_kt, 2),
        n = _kt2[0],
        r = _kt2[1];

    var l = krr().map(N),
        SZ = 2000;
    var d = A(SZ),
        xx = A();
    for (var i = 0; i < SZ; i++) {
        xx[i] = A();
    }l.forEach(function (x, i) {
        var y = r;

        var _loop = function _loop(xi) {
            xx[xi].forEach(function (yi) {
                y = Math.max(y, gp(xi, yi, 2 * r, x));
            });
        };

        for (var xi = Math.max(0, x - r * 3); xi < Math.min(SZ, x + r * 3); xi++) {
            _loop(xi);
        }
        xx[x].push(y);
        d[i] = y;
    });
    print(d.slice(0, n).join(' '));
}

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
print(r);
vec.push(r);
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		print((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));
		ans+=" "+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));
		vec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));
	}
	if(hit===false){
		ans+=" "+Number(r);
		print(r);
		vec.push(r);
	}
}

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
vec.push(r);
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		ans+=" "+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);
		vec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);
	}
	if(hit==false){
		ans+=" "+r;
		vec.push(r);
	}
}
print(ans);

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
print(s);
var ans=r+"";
var vec=[];
vec.push(r);
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		ans+=" "+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);
		vec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);
	}
	if(hit==false){
		ans+=" "+r;
		vec.push(r);
	}
}
print(ans);

var s = readline().split(' ');
n=s[0];
r=s[1];
print(n+" "+r);

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
print(r);
vec.push(r);
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		print((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+ +vec[j]));
		ans+=" "+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+ +vec[j]);
		vec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+ +vec[j]);
	}
	if(hit===false){
		ans+=" "+ +r;
		print(r);
		vec.push(r);
	}
}

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
print(r);
vec[0]=r;
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		vec[i]=Math.max(vec[i],(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));
	}
	if(hit===false){
		vec[i]=r;
	}
	ans+=" "+vec[i];
}
print(ans);

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
print(r);
vec.push(r);
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>=r*2)continue;
		hit=true;
		print((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));
		ans+=" "+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));
		vec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));
		break;
	}
	if(hit===false){
		ans+=" "+Number(r);
		print(r);
		vec.push(r);
	}
}

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
vec[0]=Number(r);
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		vec[i]=Math.max(vec[i],(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));
	}
	if(hit===false){
		vec[i]=Number(r);
	}
	ans+=" "+vec[i];
}
print(ans);

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
print(r);
vec.push(r);
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		print((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]));
		ans+=" "+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);
		vec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);
	}
	if(hit===false){
		ans+=" "+r;
		print(r);
		vec.push(r);
	}
}

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
vec.push(r);
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		s+=" "+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);
		vec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+vec[j]);
	}
	if(hit==false){
		s+=" "+r;
		vec.push(r);
	}
}
print(s);

var s = readline().split(' ');
n=s[0];
r=s[1];
var s = readline().split(' ');
var ans=r+"";
var vec=[];
print(r);
vec.push(r);
for(i=1;i<n;i++){
	hit = false;
	for(j=i-1;j>=0;j--){
		if(Math.abs(s[i]-s[j])>r*2)continue;
		hit=true;
		print((Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j])));
		ans+=" "+(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));
		vec.push(Math.sqrt(Math.pow(r*2,2)-Math.pow(Math.abs(s[i]-s[j]),2))+Number(vec[j]));
		break;
	}
	if(hit===false){
		ans+=" "+Number(r);
		print(r);
		vec.push(r);
	}
}


You are given a tree consisting of $$$n$$$ vertices. A tree is an undirected connected acyclic graph.    Example of a tree. You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color.You have to paint the vertices so that any path consisting of exactly three distinct vertices does not contain any vertices with equal colors. In other words, let's consider all triples $$$(x, y, z)$$$ such that $$$x \neq y, y \neq z, x \neq z$$$, $$$x$$$ is connected by an edge with $$$y$$$, and $$$y$$$ is connected by an edge with $$$z$$$. The colours of $$$x$$$, $$$y$$$ and $$$z$$$ should be pairwise distinct. Let's call a painting which meets this condition good.You have to calculate the minimum cost of a good painting and find one of the optimal paintings. If there is no good painting, report about it.

The first line contains one integer $$$n$$$ $$$(3 \le n \le 100\,000)$$$ — the number of vertices. The second line contains a sequence of integers $$$c_{1, 1}, c_{1, 2}, \dots, c_{1, n}$$$ $$$(1 \le c_{1, i} \le 10^{9})$$$, where $$$c_{1, i}$$$ is the cost of painting the $$$i$$$-th vertex into the first color. The third line contains a sequence of integers $$$c_{2, 1}, c_{2, 2}, \dots, c_{2, n}$$$ $$$(1 \le c_{2, i} \le 10^{9})$$$, where $$$c_{2, i}$$$ is the cost of painting the $$$i$$$-th vertex into the second color. The fourth line contains a sequence of integers $$$c_{3, 1}, c_{3, 2}, \dots, c_{3, n}$$$ $$$(1 \le c_{3, i} \le 10^{9})$$$, where $$$c_{3, i}$$$ is the cost of painting the $$$i$$$-th vertex into the third color. Then $$$(n - 1)$$$ lines follow, each containing two integers $$$u_j$$$ and $$$v_j$$$ $$$(1 \le u_j, v_j \le n, u_j \neq v_j)$$$ — the numbers of vertices connected by the $$$j$$$-th undirected edge. It is guaranteed that these edges denote a tree.

If there is no good painting, print $$$-1$$$. Otherwise, print the minimum cost of a good painting in the first line. In the second line print $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ $$$(1 \le b_i \le 3)$$$, where the $$$i$$$-th integer should denote the color of the $$$i$$$-th vertex. If there are multiple good paintings with minimum cost, print any of them.

NoteAll vertices should be painted in different colors in the first example. The optimal way to do it is to paint the first vertex into color $$$1$$$, the second vertex — into color $$$3$$$, and the third vertex — into color $$$2$$$. The cost of this painting is $$$3 + 2 + 1 = 6$$$.

'use strict'

const problem = () => {
    const n = parseInt(readline());
    const cost = Array.from({ length: 3 }, () => readline().split(' ').map(Number));
    const info = Array.from({ length: n-1 }, () => readline().split(' ').map(Number));
    const graph = Array.from({ length: n }, () => []);

    for (let i = 0; i < n-1; i++) {
        const a = info[i][0] - 1, b = info[i][1] - 1;
        graph[a].push(b);
        graph[b].push(a)
    }

    if (graph.some(i => i.length > 2)) return -1;
    const start = graph.findIndex(i => i.length === 1);
    const visited = Array(n).fill(-1); visited[start] = 0;
    const q = [ start ];

    while (q.length) {
        const j = q.shift();
        for (let i = 0; i < graph[j].length; i++) {
            const next = graph[j][i];
            if (visited[next] === -1) {
                visited[next] = (visited[j] + 1) % 3;
                q.push(next);
            }
        }
    }

    let res = Infinity;
    let set;

    [ [0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0] ].forEach(a => {
        const t = Array.from({ length: n }, (_, i) => cost[a[visited[i]]][i]).reduce((r, i) => r + i, 0);
        if (t < res) { res = t; set = a; }
    });

    return [ res, Array.from({ length: n }, (_, i) => set[visited[i]] + 1).join(' ') ].join('\n');
}

write(problem());

'use strict'

const problem = () => {
    const n = parseInt(readline());
    const cost = Array.from({ length: 3 }, () => readline().split(' ').map(Number));
    const info = Array.from({ length: n-1 }, () => readline().split(' ').map(Number));
    const graph = Array.from({ length: n }, () => []);

    for (let i = 0; i < n-1; i++) {
        const a = info[i][0] - 1, b = info[i][1] - 1;
        graph[a].push(b);
        graph[b].push(a)
    }

    if (graph.indexOf(i => i.length > 2) !== -1) return -1;
    const start = graph.findIndex(i => i.length === 1);
    const visited = Array(n).fill(-1); visited[start] = 0;
    const q = [ start ];

    while (q.length) {
        const j = q.shift();
        for (let i = 0; i < graph[j].length; i++) {
            const next = graph[j][i];
            if (visited[next] === -1) {
                visited[next] = (visited[j] + 1) % 3;
                q.push(next);
            }
        }
    }

    let res = Infinity;
    let set;

    [ [0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0] ].forEach(a => {
        const t = Array.from({ length: n }, (_, i) => cost[a[visited[i]]][i]).reduce((r, i) => r + i, 0);
        if (t < res) { res = t; set = a; }
    });

    return [ res, Array.from({ length: n }, (_, i) => set[visited[i]] + 1).join(' ') ].join('\n');
}

write(problem());


This is yet another problem on regular bracket sequences.A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequence that consists of characters "(", ")" and "?". You have to replace each character "?" with a bracket so, that you get a regular bracket sequence.For each character "?" the cost of its replacement with "(" and ")" is given. Among all the possible variants your should choose the cheapest.

The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai,  bi ≤ 106), where ai is the cost of replacing the i-th character "?" with an opening bracket, and bi — with a closing one.

Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them.

var Q = [];
Q.push = function( v ){
	var l = 0;
	var h = Q.length;
	do{
		var i = Math.floor( (h-l)/2 );

		if( this[l+i] && (this[l+i].n < v.n) ){
			h = l+i;
		}else{
			l = l+i;
		}
	}while(i!=0);
	//console.log(h)
	this.splice(h, 0, v);
}

var s = readline().split('');
var l = 0;

var all = 0;
for(var i=0; i<s.length; i++){
	if( s[i] == '('){
		l++;
	}else if(s[i] == ')'){
		l--;
	}else{
		s[i] = ')';
		l--;
		var line = readline().split(' ');
		all += parseInt(line[1]);
		Q.push({
			n: parseInt(line[0]) - parseInt(line[1]),
			i: i
		});
	}

	if(l<0){
		var c = Q.pop();
		if(!c){
			all=-1;
			break;
		}
		all += c.n;
		s[ c.i ] = '(';
		l+=2;
	}
}

if( l!==0 || all == -1){
	print( -1 );
}else{
	print(all);
	print(s.join(''));
}

var line = readline();

var l = 0;
var la=[];
var max = 0;
var c = 0;
for(var i=0;i<line.length;i++){
	if(line[i] == '('){
		if( la[l] === undefined){
			la[l]=i;
		}
		l++;
	}else{
		l--;
		if(l>=0){
			var j = i-la[l]+1;
			if( j > max){
				max = j;
				c=1;
			}else if( j==max){
				c++;
			}
		}
	}
	if(l<0){
		l=0;
		la=[];
	}
}

if(max==0){
	c=1;
}
print(max+' '+c);


Gaurang has grown up in a mystical universe. He is faced by $$$n$$$ consecutive 2D planes. He shoots a particle of decay age $$$k$$$ at the planes.A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $$$k-1$$$. If a particle has decay age equal to $$$1$$$, it will NOT produce a copy.For example, if there are two planes and a particle is shot with decay age $$$3$$$ (towards the right), the process is as follows: (here, $$$D(x)$$$ refers to a single particle with decay age $$$x$$$)  the first plane produces a $$$D(2)$$$ to the left and lets $$$D(3)$$$ continue on to the right;  the second plane produces a $$$D(2)$$$ to the left and lets $$$D(3)$$$ continue on to the right;  the first plane lets $$$D(2)$$$ continue on to the left and produces a $$$D(1)$$$ to the right;  the second plane lets $$$D(1)$$$ continue on to the right ($$$D(1)$$$ cannot produce any copies). In total, the final multiset $$$S$$$ of particles is $$$\{D(3), D(2), D(2), D(1)\}$$$. (See notes for visual explanation of this test case.)Gaurang is unable to cope up with the complexity of this situation when the number of planes is too large. Help Gaurang find the size of the multiset $$$S$$$, given $$$n$$$ and $$$k$$$.Since the size of the multiset can be very large, you have to output it modulo $$$10^9+7$$$.Note: Particles can go back and forth between the planes without colliding with each other.

The first line of the input contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Then, $$$t$$$ lines follow, each containing two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1000$$$).  Additionally, the sum of $$$n$$$ over all test cases will not exceed $$$1000$$$, and the sum of $$$k$$$ over all test cases will not exceed $$$1000$$$. All test cases in one test are different.

Output $$$t$$$ integers. The $$$i$$$-th of them should be equal to the answer to the $$$i$$$-th test case.

NoteLet us explain the first example with four test cases. Test case 1: ($$$n = 2$$$, $$$k = 3$$$) is already explained in the problem statement.See the below figure of this simulation. Each straight line with a different color represents the path of a different particle. As you can see, there are four distinct particles in the multiset. Note that the vertical spacing between reflected particles is for visual clarity only (as mentioned before, no two distinct particles collide with each other)  Test case 2: ($$$n = 2$$$, $$$k = 2$$$) is explained as follows: the first plane produces a $$$D(1)$$$ to the left and lets $$$D(2)$$$ continue on to the right;  the second plane produces a $$$D(1)$$$ to the left and lets $$$D(2)$$$ continue on to the right;  the first plane lets $$$D(1)$$$ continue on to the left ($$$D(1)$$$ cannot produce any copies).Total size of multiset obtained $$$\{D(1), D(1), D(2)\}$$$ is equal to three.Test case 3: ($$$n = 3$$$, $$$k = 1$$$), there are three planes, but decay age is only one. So no new copies are produced while the one particle passes through the planes. Hence, the answer is one.Test case 4: ($$$n = 1$$$, $$$k = 3$$$) there is only one plane. The particle produces a new copy to the left. The multiset $$$\{D(2), D(3)\}$$$ is of size two.

'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 = 1001
var mod = 1000000007

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

function main() {
  const x = readline();
  var toPrint = ''
  Array(Number(x)).fill(1).map((t, i) => {
    // const a = parseInt(readline());
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    if (k === 1) return toPrint += 1 + '\n'

    var dp = new Array(k)
    for (let j = 0; j < k; j++) {
      dp[j] = new Array(n).fill(0)
    }
    for (let j = 0; j < n; j++) {
      dp[0][j] = 1
    }
    for (let j = 0; j < k - 2; j++) {
      if (j % 2 === 0) {
        var sum = 0
        for (let i = 0; i < n; i++) {
          dp[j + 1][i] = sum
          sum += dp[j][i]
          sum = sum % mod
        }
      } else {
        sum = 0
        for (let i = n - 1; i >= 0; i--) {
          dp[j + 1][i] = sum
          sum += dp[j][i]
          sum = sum % mod
        }
      }
    }

    var ans = 1
    for (let j = 0; j < k - 1; j++) {
      for (let i = 0; i < n; i++) {
        // console.log(ans, dp[j][i])
        ans = (ans + dp[j][i]) % mod
      }
    }
    toPrint += ans.toString() + '\n'
    // console.log(dp)
  })
  console.log(toPrint)

}

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 MOD = 1e9 + 7;

function main () {
	let T = rn();
	while (T--) {
		const [N, K] = rna();

		const dp = Array.from(Array(N+1), x => Array(K+1));
		for (let n = 0; n <= N; n++) {
			dp[n][0] = 0;
		}
		for (let k = 1; k <= K; k++) {
			dp[0][k] = 1;
		}
		for (let k = 1; k <= K; k++) {
			for (let n = 1; n <= N ; n++) {
				dp[n][k] = (dp[n-1][k] + dp[N-n][k-1]) % MOD;
			}
		}
		const ans = dp[N][K];

		console.log(ans);
	}
}

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 MOD = 1e9 + 7;

function main () {
	let T = rn();
	while (T--) {
		const [N, K] = rna();

		/*
		   const dp = Array.from(Array(n+1), x => []);
		   function f (i, k) {
		   if (dp[i][k]) return dp[i][k];
		   console.log({i, k})
		   if (i == 0) return 1;
		   if (k > 1) return dp[i][k] = (f(i-1, k) + f(n-i, k-1)) % MOD;
		   else return dp[i][k] = f(i-1, k) % MOD;
		   }
		   */

		const dp = Array.from(Array(N+1), x => Array(K+1).fill(0));
		for (let k = 1; k <= K; k++) {
			dp[0][k] = 1;
		}
		for (let k = 1; k <= K; k++) {
			for (let n = 1; n <= N ; n++) {
				dp[n][k] = (dp[n-1][k] + dp[N-n][k-1]) % MOD;
			}
		}
		const ans = dp[N][K];

		console.log(ans);
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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();
	var mod = 1000000007;
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var K = nextInt();
		var output = 1;
		if(K == 1){
			myout(output);
			continue;
		}
		if(N == 1){
			myout(2);
			continue;
		}
		output++;
		N--;
		var list = new Array(N).fill(0);
		list[0] = 1;
		var isL = true;
		while(K > 1){
			if(!isL){
				for(var k = N - 2; k >= 0; k--){
					list[k] += list[k + 1];
					list[k] %= mod;
				}
			}else{
				for(var k = 1; k < N; k++){
					list[k] += list[k - 1];
					list[k] %= mod;
				}
			}
			for(var k = 0; k < N; k++){
				output += list[k];
				output %= mod;
			}
			K--;
			isL = !isL;
		}
		myout(output);
	}
}

'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 = 1001
var mod = 1000000007n

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

function main() {
  const x = readline();
var toPrint = ''
  Array(Number(x)).fill(1).map((t, i) => {
    // const a = parseInt(readline());
    var [n, k] = readline().split(' ').map((x, iii) => {
      return BigInt(x)
    });
    if (k === 1n) return console.log(1)
    var dp = new Array(k)
    for (let j = 0n; j < k; j++) {
      dp[j] = new Array(n).fill(0n)
    }
    for (let j = 0n; j < n; j++) {
      dp[0][j] = 1n
    }
    for (let j = 0n; j < k - 2n; j++) {
      if (j % 2n === 0n) {
        var sum = 0n
        for (let i = 0n; i < n; i++) {
          dp[j + 1n][i] = sum
          sum += dp[j][i]
          sum = sum % mod
        }
      } else {
        sum = 0n
        for (let i = n - 1n; i >= 0n; i--) {
          dp[j + 1n][i] = sum
          sum += dp[j][i]
          sum = sum % mod
        }
      }
    }

    var ans = 1n
    for (let j = 0n; j < k - 1n; j++) {
      for (let i = 0n; i < n; i++) {
        // console.log(ans, dp[j][i])
        ans = (ans + dp[j][i]) % mod
      }
    }
    toPrint += ans.toString() + '\n'
    // console.log(dp)
  })
  console.log(toPrint)

}


The process of mammoth's genome decoding in Berland comes to its end!One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.

The first line contains the integer n (4 ≤ n ≤ 255) — the length of the genome. The second line contains the string s of length n — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.

If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).

NoteIn the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.In the third and the fourth examples it is impossible to decode the genom.

function main()
{

String.prototype.replaceAt = function(index, character) {
    return this.substr(0, index) + character + this.substr(index+character.length);
}

var n = parseInt( readline() );
var s = readline();

if ( n%4 > 0 )
{
	print( "===" );
	return;
}

var q = 0;
var a = [];
a['A'] = a['C'] = a['G'] = a['T'] = 0;

for ( var i = 0 ; i < n ; i++ )
{
	if ( s[i] == '?' )
		q++;
	else
		a[ s[i] ]++;
}

var e = n / 4;
if ( a['A'] > e || a['C'] > e || a['G'] > e || a['T'] > e )
{
	print( "===" );
	return;
}

var ans = "";
for ( var i=0 ; i<n ; i++ )
{
	if ( s[i] == '?' )
	{
		if ( a['A'] < e )
		{
			a['A']++;
			ans += 'A';
			continue;
		}

		if ( a['C'] < e )
		{
			a['C']++;
			ans += 'C';
			continue;
		}

		if ( a['G'] < e )
		{
			a['G']++;
			ans += 'G';
			continue;
		}

		if ( a['T'] < e )
		{
			a['T']++;
			ans += 'T';
			continue;
		}

	}
	else
	{
		ans += s[i];
	}
}

print( ans );

} main();

var memo = {
  A: 0,
  G: 0,
  C: 0,
  T: 0,
  '?': 0
};

var memo2 = {
  A: 0,
  G: 0,
  C: 0,
  T: 0
};

function max() {}

function resolve(s) {
  for (var i = 0; i < s.length; i++) {
    memo[s[i]]++;
  }
  var max = 0;
  for (var key in memo) {
    if (key !== '?' && memo[key] > max) {
      max = memo[key];
    }
  }
  var sum = 0;
  for (var key in memo) {
    if (key !== '?') {
      sum += max - memo[key];
      memo2[key] = max - memo[key];
    }
  }
  if (memo['?'] < sum) {
    return '===';
  }
  if ((memo['?'] - sum) % 4 !== 0) {
    return '===';
  } else {
    memo2.A += (memo['?'] - sum) / 4;
    memo2.G += (memo['?'] - sum) / 4;
    memo2.C += (memo['?'] - sum) / 4;
    memo2.T += (memo['?'] - sum) / 4;
  }
  var res = '';
  for (var i = 0; i < s.length; i++) {
    if (s[i] === '?') {
      if (memo2.A > 0) {
        res += 'A';
        memo2.A--;
      } else if (memo2.G > 0) {
        res += 'G';
        memo2.G--;
      } else if (memo2.C > 0) {
        res += 'C';
        memo2.C--;
      } else if (memo2.T > 0) {
        res += 'T';
        memo2.T--;
      }
    } else {
      res += s[i];
    }
  }
  return res;
}

//console.log(resolve('AA??'));

readline();
const s = readline();
print(resolve(s));

"use strict";

var NOT_FOUND = "===";
var letters = ["A", "C", "T", "G"];

function countLetters (genom) {
    var count = {};
    for (var i = 0; i < letters.length; i++) {
        count[letters[i]] = 0;
    }
    for (i = 0; i < genom.length; i++) {
        if (letters.indexOf(genom[i]) !== -1) {
            count[genom[i]]++;
        }
    }
    return count;
}

function reconstruct (genom) {
    if (genom.length % 4 !== 0) {
        return NOT_FOUND;
    }
    var count = countLetters(genom);
    var desiredCount = Math.round(genom.length / 4);
    for (var i = 0; i < letters.length; i++) {
        if (count[letters[i]] > desiredCount) {
            return NOT_FOUND;
        }
    }
    var result = "";
    for (i = 0; i < genom.length; i++) {
        if (letters.indexOf(genom[i]) === -1) {
            var curLetter = letters.filter(function (s) {
                return count[s] < desiredCount;
            })[0];
            result += curLetter;
            count[curLetter]++;
        } else {
            result += genom[i];
        }
    }
    return result;
}

var n = parseInt(readline());
var s = readline();
print(reconstruct(s));

"use strict";

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

let n = null;
let genome = [];
let map = {
    'A': 0,
    'C': 0,
    'G': 0,
    'T': 0,
    '?': 0
};

readline.on('line', line => {

    if (!n)
        n = line;
    else {
        genome = line.split('');
        readline.close();
    }
})

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

    genome.map(char => {
        map[char] = ++map[char];
    })

    let max = n / 4;

    let word = genome.join('');

    Object.keys(map).forEach(key => {
        if (key === '?') return;
        while (map['?'] > 0 && map[key] < max) {
            map[key] = ++map[key];
            map['?']--;
            word = word.replace('?', key);
        }
    })

    let cumple = true;
    Object.keys(map).forEach(key => {
        if (key !== '?' && map[key] < max) {
            cumple = false;
        }
    })
    if (word.includes('?') || !cumple)
        return console.log('===');
    console.log(word);
})

"use strict";

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

let n = null;
let genome = [];
let map = {
    'A': 0,
    'C': 0,
    'G': 0,
    'T': 0,
    '?': 0
};

readline.on('line', line => {

    if (!n)
        n = line;
    else {
        genome = line.split('');
        readline.close();
    }
})

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

    genome.map(char => {
        map[char] = ++map[char];
    })

    let max = 0;
    let maxKey = null;

    Object.keys(map).forEach(key => {
        if (key !== '?') {
            if (map[key] > max) {
                max = map[key]
                maxKey = key;
            }
        }
    })

    if (max === 0)
        max = map['?'] / 4;

    let word = genome.join('');

    Object.keys(map).forEach(key => {
        if (map['?'] >= 0) {
            if (key !== maxKey && map[key] < max) {
                map[key] = ++map[key];
                map['?']--;
                word = word.replace('?', key);
            }
        }
    })

    let cumple = true;
    Object.keys(map).forEach(key => {
        if (key != '?' && map[key] < max) {
            cumple = false;
        }
    })
    if (word.includes('?') || !cumple)
        return console.log('===');
    console.log(word);
})

"use strict";

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

let n = null;
let genome = [];
let map = {
    'A': 0,
    'C': 0,
    'G': 0,
    'T': 0,
    '?': 0
};

readline.on('line', line => {

    if (!n)
        n = line;
    else {
        genome = line.split('');
        readline.close();
    }
})

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

    genome.map(char => {
        map[char] = ++map[char];
    })

    let max = 0;
    let maxKey = null;

    Object.keys(map).forEach(key => {
        if (key !== '?') {
            if (map[key] > max) {
                max = map[key]
                maxKey = key;
            }
        }
    })

    if (max === 0)
        max = map['?'] / 4;

    let word = genome.join('');

    Object.keys(map).forEach(key => {
        if (map['?'] >= 0) {
            if (key !== maxKey && map[key] < max) {
                map[key] = ++map[key];
                map['?']--;
                word = word.replace('?', key);
            }
        }
    })
    if (word.includes('?'))
        return console.log('===');
    console.log(word);
})

"use strict";

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

let n = null;
let genome = [];
let map = {};

readline.on('line', line => {

    if (!n)
        n = line;
    else {
        genome = line.split('');
        readline.close();
    }
})

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

    genome.map(char => {
        map[char] = map[char] ? ++map[char] : 1;
    })

    if (Object.keys(map).length <= n / 2)
        return console.log('===');

    let max = 0;
    let maxKey = null;

    Object.keys(map).forEach(key => {
        if (key !== '?') {
            if (map[key] > max) {
                max = map[key]
                maxKey = key;
            }
        }
    })

    let word = genome.join('');

    Object.keys(map).forEach(key => {
        if (map['?'] >= 0) {
            if (key !== maxKey && map[key] < max) {
                map[key] = ++map[key];
                map['?']--;
                word = word.replace('?', key);
            }
        }
    })
    if (word.includes('?'))
        return console.log('===');
    console.log(word);
})

"use strict";

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

let n = null;
let genome = [];
let map = {
    'A': 0,
    'C': 0,
    'G': 0,
    'T': 0,
    '?': 0
};

readline.on('line', line => {

    if (!n)
        n = line;
    else {
        genome = line.split('');
        readline.close();
    }
})

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

    genome.map(char => {
        map[char] = ++map[char];
    })

    let max = 0;
    let maxKey = null;

    Object.keys(map).forEach(key => {
        if (key !== '?') {
            if (map[key] > max) {
                max = map[key]
                maxKey = key;
            }
        }
    })

    if (max === 0)
        max = map['?'] / 4;

    let word = genome.join('');

    Object.keys(map).forEach(key => {
        if (map['?'] >= 0) {
            if (key !== maxKey && map[key] < max) {
                map[key] = ++map[key];
                map['?']--;
                word = word.replace('?', key);
            }
        }
    })

    let cumple = true;
    Object.keys(map).forEach(key =>{
        if(map[key] < max){
            cumple = false;
        }
    })

    if (word.includes('?') || !cumple)
        return console.log('===');
    console.log(word);
})