You are given three positive integers $$$n$$$, $$$a$$$ and $$$b$$$. You have to construct a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters such that each substring of length $$$a$$$ has exactly $$$b$$$ distinct letters. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.Recall that the substring $$$s[l \dots r]$$$ is the string $$$s_l, s_{l+1}, \dots, s_{r}$$$ and its length is $$$r - l + 1$$$. In this problem you are only interested in substrings of length $$$a$$$.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of a test case contains three space-separated integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le a \le n \le 2000, 1 \le b \le \min(26, a)$$$), where $$$n$$$ is the length of the required string, $$$a$$$ is the length of a substring and $$$b$$$ is the required number of distinct letters in each substring of length $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$ ($$$\sum n \le 2000$$$).

For each test case, print the answer — such a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters that each substring of length $$$a$$$ has exactly $$$b$$$ distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.

NoteIn the first test case of the example, consider all the substrings of length $$$5$$$:  "tleel": it contains $$$3$$$ distinct (unique) letters,  "leelt": it contains $$$3$$$ distinct (unique) letters,  "eelte": it contains $$$3$$$ distinct (unique) letters.

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  let t = getInt()
  while (t --> 0) {
    const inp = getInts()

    let s = ''
    let init = 'a'.charCodeAt()
    for (let i = 0; i < inp[2]; ++i) {
      s += String.fromCharCode(init ++)
    }

    while (s.length < inp[1]) s += 'a'
    while (s.length < inp[0]) s += s
    print(s.slice(0, inp[0]))
  }
}

var t = parseInt(readline());

function div(val, by){
    return (val - val % by) / by;
}

var ch = 'a';
var acode = ch.charCodeAt(0);

for (var tt = 0; tt < t; tt++) {
    var inp = readline().split(' ').map(Number);
    var n = inp[0];
    var a = inp[1];
    var b = inp[2] - 1;
    var res = '';

    for (var i = 0; i < n; i++) {
        var pos = i % a;
        if (pos > b) {
            res += String.fromCharCode(acode+b);
        } else {
            res += String.fromCharCode(acode+pos);
        }
    }

    write(res+'\n');
}

var n = +readline();
var string = 'abcdefghijklmnopqrstuvwxyz';
for(var i = 0; i < n; i++){
    var s = readline().split(' ').map(Number);
    var x = s[0];
    var a = s[1];
    var b = s[2];

    var _ = parseInt(x/a);
    var str = string.slice(0,b).repeat(parseInt(b/a)+1).slice(0,a);
    str = str.repeat(parseInt(x/b) + 1).slice(0,x);
    write(str + '\n');
}

var n = +readline();

var alp = 'abcdefghijklmnopqrstuvwxyz';
for (var i = 0; i < n; i ++) {
    var s = readline().split(' ').map(Number);

    var x = s[0];
    var a = s[1];
    var b = s[2];

    var rp = parseInt(x / a);
    var str = alp.slice(0, b).repeat(parseInt(b / a) + 1).slice(0, a);
    str = str.repeat(parseInt(x / b) + 1).slice(0, x);
    write(str + '\n');
}

// abc abcab abcabab

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; 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"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var t = readline();

while (t--) {
  var _readline$split = readline().split(' '),
      _readline$split2 = _slicedToArray(_readline$split, 3),
      n = _readline$split2[0],
      a = _readline$split2[1],
      b = _readline$split2[2]; //1, 2, 3

  var charCods = [];

  for (var i = 97; i < 97 + 26; i++) {
    charCods.push(i);
  }

  var str = String.fromCharCode.apply(String, charCods).slice(0, b);
  str = str.repeat(Math.ceil(n / str.length)).slice(0, n);
  print(str);
}

var n = Number(readline());
var inp;
for(var i = 0; i < n; i++){
    inp = readline().split(' ').map(cur => Number(cur));
    stringGenerator(...inp);
}

function stringGenerator (l,a,b){

const arr = [...Array(26)].map((cur,i) => String.fromCharCode(97+i));

var res = [];

for(var i = 0; i< l ;i++){
res.push(arr[i%b]);
}

    print(res.join(''));
}

var t = parseInt(readline());

function mapper(num) {
    return +num;
}

var alph = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];

for (var i = 0; i < t; i++) {
    var data = readline().split(' ').map(mapper);
    var n = data[0];
    var a = data[1];
    var b = data[2];

    var letters = alph.slice(0, b);
    var str = letters.join('');
    var res = '';

    for(var j = 0; j < Math.ceil(n / b); j++) {
        res += str;
    }

    res = res.slice(0, n);
    print(res);
}

var range = readline();

for(var i=0;i<range;i++) {
    var inputs = readline().split(" ").map((x) => parseInt(x));
    var arrange = [];
    var startString = 97;

    for(var j=0;j<inputs[2];j++) {
        arrange.push(String.fromCharCode(startString));
        startString++;
    }

    var construct = [];
    var length = inputs[0];
    var start = 0;

    while(construct.length !== inputs[0]) {
        construct.push(arrange[start]);
        start++;
        if(start === arrange.length) {
            start = 0;
        }
    }

    print(construct.join(""));
}

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var input_lines;
var currentLine = 0;
process.stdin.on('data', function (inputStdin) {
    inputString += inputStdin;
});
process.stdin.on('end', function (_) {
    input_lines = inputString.trim().split('\n').map(function (str) {
        return str.trim();
    });
    main();
});
function input() {
    return input_lines[currentLine++];
}
function EOF() {
    return currentLine >= input_lines.length;
}
var letters = "qwertyuiopasdfghjklzxcvbnm";
function main() {
    var t = parseInt(input());
    for (var casen = 0; casen < t; casen++) {
        var _a = input().split(' ').map(function (x) { return parseInt(x); }), n = _a[0], a = _a[1], b = _a[2];
        var answer = [];
        while (answer.length < n) {
            for (var i = 0; i < b - 1; i++) {
                answer.push(letters.charAt(i));
            }
            for (var i = 0; i < a - (b - 1); i++) {
                answer.push(letters.charAt(b - 1));
            }
        }
        answer = answer.splice(0, n);
        console.log("".concat.apply("", answer));
    }
}

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

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

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

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() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const [n, a, b] = readInts()
    let ans = ''
    let ax = ''
    for(let i = 0, j = 97; i < b; i++) {
      ax += String.fromCharCode(j)
      j++
    }
    ax = ax.padEnd(a, 'a')
    ans = ans.padEnd(n, ax)
    wr(ans)
  }
}

//DISABLE THIS LINE END ENABLE NEXT
//const rl =  require('readline').createInterface({input: require('fs').createReadStream('input.txt')});
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const write = (...args) => {
    process.stdout.write(args.join(' ') );
}
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)

let rli = 0;
function readline() {
    return lines[rli++];
}

function repeat(pattern, count) {
    if (count < 1) return '';
    var result = '';
    while (count > 1) {
        if (count & 1) result += pattern;
        count >>= 1, pattern += pattern;
    }
    return result + pattern;
}

function main() {
	var parr = "abcdefghijklmnopqrstuvwxyz";//.split();
	var y = +readline()
	while(y > 0) {
		var z = readline().split(' ');
		var n = +z[0];
		var a = +z[1];
		var b = +z[2];
		var res = "";
		//[0,...., b-1] from parr
		var res = "";
		var p = parr.substring(0,b);
		var count = Math.floor(n / p.length);
		res = repeat(p, count);
		while(res.length < n) {
			res += p;
		}
		res = res.substring(0, n);
		if (y > 1) {
			write(res + '\n');
		} else {
			write(res);
		}
		y--;
	}
}

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 [n, a, b] = d.split(' ').map(Number);
  let ans = '';

  let i = 0;
  while (ans.length < n) {
    ans += String.fromCharCode((i % 26) % b + 97);
    i++;

    if (i === a) {
      i = 0;
    }
  }

  console.log(ans);

  c++;
});

const processData = (input) => {
    let exp = /\s+/;
    let arr = input.split(exp);
    arr = arr.map(el => +el);
    let l = arr[0];
    arr = arr.slice(1);
    const a = 97;
    for (let i = 0; i < l; i++){
        let temp = arr.slice(i*3,i*3+3);
        let str = "";
        let max = temp[2] + a;
        let current = a;
        for (let i = 0; i < temp[0]; i++) {
            str += String.fromCharCode(current);
            current++;
            if (current === max) current = a;
        }
        console.log(str);
    }
}

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

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

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var currentLine = 0;
process.stdin.on('data', function (input) { inputString += input; });
process.stdin.on('end', function (_) { inputString = inputString.split('\n'); main(); });
var readline = function () { return inputString[currentLine++]; };
function main() {
    var tests = parseInt(readline());
    var abc = ' abcdefghijklmnopqrstuvwxyz';
    while (tests--) {
        var _a = readline().split(' ').map(function (x) { return parseInt(x); }), n = _a[0], a = _a[1], b = _a[2];
        var copies = Math.floor(n / b) + 1;
        var ans = '';
        while (b) {
            ans += abc[b];
            b--;
        }
        ans = ans.repeat(copies);
        ans = ans.substr(0, n);
        console.log(ans);
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var T = parseInt(readline());
    while (T--) {
        var input1 = readline().split(' ').map(x => parseInt(x));
        var a = input1[0]
        var b = input1[1]
        var c = input1[2]
        var str=""
        for(var i=0; i<a; i++){
            str += String.fromCharCode(97 + i % c);
        }
        print(str)
    }

}

const alphabets = []

const start = 'a'.charCodeAt(0)
const end = 'z'.charCodeAt(0)
for (let s = start; s<=end; s++) {
  alphabets.push(String.fromCharCode(s))
}

const processData = (lines) => {
  const num = +lines[0]
  for (let i=0; i<num; i++) {
    const [n, a, b] = lines[i+1].split(' ').map(x => +x)
    let res = ''
    for (let i=0; i<n;i++) {
      res += alphabets[i%b]
    }
    console.log(res)
  }
}

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

const init = () => {
  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();
  });

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

if (typeof readline === 'undefined') {
  init();
}

const print = (...args) => {
  console.log(...args);
};

const main = () => {
  let t = Number(readline());
  while (t--) {
    let [n, a, b] = readline().split(' ').map(x => parseInt(x));
    let s = '';
    let ci = 0;
    const CHAR_CODE_BASE = 97;
    for (let i = 0; i < n; i++) {
      s += String.fromCharCode(ci + CHAR_CODE_BASE);
      ci++;
      ci %= b;
    }
    print(s);
  }
};

'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.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

function solve(n, a, b) {
  let res = '';
  let substr = '';
  let alphabet = 'abcdefghijklmnopqrstuvwxyz';
  for (let i = 0; i < b; i++) {
    substr += alphabet[i];
  }
  for (let i = 0; i < n; i++) {
    res += substr[i % substr.length];
  }
  return res;
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    // let n = parseInt(readLine());
    let [n, a, b] = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n, a, b);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

'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() {
    let n = parseInt(readline(), 10);
    const Acode = 'a'.charCodeAt(0)

    for (var j = 0; j < n; j++) {
        const [n, a ,b] = readline().split(" ").map(e => parseInt(e));
        let res = '';
        var alaphabet = [];
        for (var i = 0; i < b; i++) {
            alaphabet.push(String.fromCharCode((Acode+i)));
        }
        for (var i = 0; i < n; i++) {
            res += alaphabet[i % alaphabet.length];
        }
        console.log(res);
    }

}

var n = +readline();

var alp = 'abcdefghijklmnopqrstuvwxyz';
for (var i = 0; i < n; i ++) {
    var s = readline().split(' ').map(Number);

    var x = s[0];
    var a = s[1];
    var b = s[2];

    var rp = parseInt(x / a);
    var str = ('a'.repeat(a - b) + alp.slice(0, b)).repeat(rp);
    if (rp * a < x) {
        var diff = x - (a * rp);
        str += alp.slice(-diff);
    }

    write(str + '\n');
}

var n = +readline();

var alp = 'abcdefghijklmnopqrstuvwxyz';
for (var i = 0; i < n; i ++) {
    var s = readline().split(' ').map(Number);

    var x = s[0];
    var a = s[1];
    var b = s[2];

    var rp = parseInt(x / a);
    var str = ('a'.repeat(a - b) + alp.slice(0, b)).repeat(rp);
    if (rp * a < x) {
        var diff = x - (a * rp);
        str += str.slice(-diff);
    }

    write(str + '\n');
}

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

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

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

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() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const [n, a, b] = readInts()
    let ans = ''
    let ax = ''
    for(let i = 0, j = 97; i < a; i++) {
      ax += String.fromCharCode(j)
      j++
      if(j - 96 > b) j = 97
      if(j > 121) j = 97
    }
    // wr(ax)
    ans = ans.padEnd(n, ax)
    wr(ans)
  }
}

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 [n, a, b] = d.split(' ').map(Number);
  let ans = '';

  for (let i = 0; i < n; i++) {
    ans += String.fromCharCode( (i % 26) % b + 97 );
  }

  console.log(ans);

  c++;
});

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var T = parseInt(readline());
    while (T--) {
        var input1 = readline().split(' ').map(x => parseInt(x));
        var a = input1[0]
        var b = input1[1]
        var c = input1[2]
        var str=""
        for(var i=0; i<a; i++){
            str += String.fromCharCode(97 + b % c);
        }
        print(str)
    }

}


Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors. Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

First line of input consists of one integer n (1 ≤ n ≤ 3000). Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.

Output single integer — minimum amount of coins the colonel has to pay.

NoteIn first sample test we can increase factor of first badge by 1.In second sample test we can increase factors of the second and the third badge by 1.

function countUniqueElements(input,output){
	for(var i = 0; i < input.length; i++){
		output[+input[i]]++;
	}
}

var n = +readline(), a = readline().split(" ").map(Number);
var signs = {}, cnt = 0, x = 0;

for(i = 1; i <= n*2; i++){
	signs[i] = 0;
}

countUniqueElements(a,signs);

for(i = 1; i <= n; i++){
	if(signs[i] > 1){
		for(j = i; j <= n*2; j++){
			if(signs[j] == 0){
				signs[i]--;
				signs[j]++;
				cnt += j - i;
			}
			if(signs[i] == 1){
				break;
			}
		}
	}
}

write(cnt);

function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[""],this.c=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,i){return i?gcd(i,t%i):t},Math.lcm=function(t,i){return t/gcd(t,i)*i},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,i){return(+t>+i)-(+i>+t)},Math.icmp=function(t,i){return(+i>+t)-(+t>+i)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.a[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(" ")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){this.l[this.c]+=t,this.l.push(""),++this.c},Writer.prototype.flush=function(){print(this.l.join("\n")),this.l=[]};

var cnt = new Array(10000);

function main(cin, cout)
{
    var n = +cin.next();
    var t;
    for(var i = 0; i < 10000; ++i)
        cnt[i] = 0;
    for(var i = 0; i < n; ++i)
    {
        t = +cin.next();
        cnt[t]++;
    }
    var ans = 0;
    for(var i = 1; i <= n; ++i)
    {
        while(cnt[i] > 1)
        {
            var j;
            for(j = i + 1; cnt[j]; ++j);
            --cnt[i];
            ++cnt[j];
            ans += j - i;
        }
    }
    cout.print(ans);
}

var cin = new Reader();
var cout = new Writer();

main(cin, cout);

cout.flush();

/**
 * Created by Det on 25.05.2015.
 */
(function main() {
    var line1 = readline().split(' ');
    var line2 = readline().split(' ');
    var money = 0;
    var sold = [];
    var lish = [];

    for (var i=0; i < line2.length; i++){
        if (sold[line2[i]]) {
            lish.push(sold[line2[i]]);
        } else {
            sold[line2[i]] = line2[i];
        }
    }
    for (var i=0; i < lish.length; i++) {
        for (var j=+lish[i]; j < (sold.length + lish.length); j++) {
            if(!sold[j]){
                sold[j] = 1;
                money += j - lish[i];
                break;
            }
        }
    }

    print(money);
})();

function ProblemSolver() {
    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;
    this.CLEAR_ARRAY_PER_CASE = false;

    this.solveCase = function() {
        var res , i , j , fl , cn , temp ;
        res = 0 ;
        this.arr = this.arr.sort( function( left , right ) { return left - right ; } ) ;
        prev = -1 ;
        for( i = 0 ; i < this.n ; i++ ) {
        	if( this.arr[ i ] <= prev ) {
        		res += prev + 1 - this.arr[ i ] ;
        		prev = prev + 1 ;
        	}
        	else {
        		prev = this.arr[ i ] ;
        	}
        }
        print( res );
    };

    this.init = function() {
        this.lim1 = 100010;
        this.lim2 = 110;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            this.arr = [] ;
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr.push( irObj.nextInt() ) ;
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i;
        this.arr = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 );
            this.adj_list.push( new Array() );
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    };

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init();
}

function InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    };

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    };

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    };

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            res = "";
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );
                }
            }
            this.currrentCharacterIndex = endIdx;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        return this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCases = function() {
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {
                    environmentType = 'local-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    };

    this.configureStreamsAndReadInput = function() {
        var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino();
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
    };

    this.configureStreamsAndReadInput();
}

new CodeExecutioner();

function main() {
    var numBadges = parseInt(readline());

    var badges = readline().split(" ");

    badges.sort(function(a, b) {
        return a - b;
    });
    for(var i = 0; i < badges.length; ++i) {
        badges[i] = parseInt(badges[i]);
    }
    //print(badges);
    var numChanges = 0;
    for(var i = 0; i < badges.length-1; i++) {
        while(badges[i] >= badges[i+1]) {
            ++numChanges;
            ++badges[i+1];
        }
    }
    return numChanges;

}

print(main());

function countUniqueElements(input,output){
	for(var i = 0; i < input.length; i++){
		output[+input[i]]++;
	}
}

var n = +readline(), a = readline().split(" ").map(Number);
var signs = {}, cnt = 0;

for(i = 1; i <= n; i++){
	signs[i] = 0;
}

countUniqueElements(a,signs);

for(sign in signs){
	if(signs[sign] == 0){
		cnt++;
	}
}

write(cnt);

function countUniqueElements(input,output){
	for(var i = 0; i < input.length; i++){
		output[+input[i]]++;
	}
}

var n = +readline(), a = readline().split(" ").map(Number);
var signs = {}, cnt = 0;

for(i = 1; i <= n; i++){
	signs[i] = 0;
}

countUniqueElements(a,signs);

for(i = 1; i <= n; i++){
	if(signs[i] > 1){
		for(j = signs[i]; j <= n; j++){
			if(signs[j] == 0){
				signs[i]--;
				signs[j]++;
				cnt += j - i;
			}
		}
	}
}

write(cnt);

function main() {
    var numBadges = parseInt(readline());

    var badges = readline().split(" ");
    badges.map(parseInt);

    badges.sort();
    var numChanges = 0;
    for(var i = 0; i < badges.length-1; i++) {
        if(badges[i] == badges[i+1]) {
            ++numChanges;
            ++badges[i+1];
        }
    }
    return numChanges;

}

print(main());

function main() {
    var numBadges = parseInt(readline());

    var badges = readline().split(" ");
    badges.map(parseInt);

    badges.sort(function(a, b) {
        return a - b;
    });
    var numChanges = 0;
    for(var i = 0; i < badges.length-1; i++) {
        if(badges[i] == badges[i+1]) {
            ++numChanges;
            ++badges[i+1];
        }
    }
    return numChanges;

}

print(main());

function main() {
    var numBadges = parseInt(readline());

    var badges = readline().split(" ");
    badges.map(parseInt);

    badges.sort(function(a, b) {
        return a - b;
    });
    //print(badges);
    var numChanges = 0;
    for(var i = 0; i < badges.length-1; i++) {
        while(badges[i] >= badges[i+1]) {
            ++numChanges;
            ++badges[i+1];
        }
    }
    return numChanges;

}

print(main());


SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is  for SmallR while  for Zanoes. The one who shoots in the target first should be the winner.Output the probability that SmallR will win the match.

Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

// problem name: Archer
// problem link: https://codeforces.com/problemset/problem/312/B
// contest link: https://codeforces.com/contest/312
// author: reyad
// time: (?)

'use strict';

function main() {
	let a = nextInt();
	let b = nextInt();
	let c = nextInt();
	let d = nextInt();

	let p = a / b; // probability that SmallR wins in the first round
	let q = c / d; // probability that Zanoes wins in the first round

	// let's say SmallR hit the target in the first round, then
	// probabilty of win is (a/b) i.e. simply p(as p = (a/b))

	// now let's say SmallR was not successful in the first round, then two cases arise
	// (i)  Zanoes will hit the target and win
	// (ii) Zanoes will miss the target and SmallR would again have some chance to shoot
	// In the second case, SmallR's probalility of win will be
	// (probability that SmallR loses in the first round *
	// probability that Zanoes loses in the first round *
	// probability that SmallR wins in the second round)
	// and it is (
	//           	(1 - (a/b)) *
	//			 	(1 - (c/d)) *
	//			 	(a/b)
	//			 )
	// or simply (
	//				(1 - p) *
	//				(1 - q) *
	//				p
	//			 )

	// this process will go on for third round
	// and the probability of win in the third round is ((1-p) * (1-q) * (1-p) * (1-q) * p)
	// i.e. simply ((1-p)^2 * (1-q)^2 * p)

	// for fourth round, it'll be ((1-p)^3 * (1-q)^3 * p)
	// and this will go on for infinity

	// and by adding those probabilities of each round
	// we'll be able to found the answer i.e.
	// the probability that SmallR will win

	// now, ans = p + ((1-p) * (1-q) * p) + ((1-p)^2 * (1-q)^2 * p) + ...
	// let us consider, (1-p) * (1-q) = r
	// then, ans = p + (r * p) + (r^2 * p) + (r^3 + p) + ...
	// as 0 < p < 1 and 0 < q < 1, then 0 < r < 1
	// then, ans = p / (1 - r) (by applying formula of geometric progression)

	let r = (1 - p) * (1 - q);
	let ans = p / (1 - r);
	console.log(ans);
}

// reader and main caller

let readline = require('readline');

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

let inputBuf = [];
let inputBufCnt = 0;
let tk = []
let tkCnt = 0;

function nextLine() {
	return inputBuf[inputBufCnt++];
}
function next() {
	if(tkCnt == tk.length) {
		tk = inputBuf[inputBufCnt++].split(' ');
		tkCnt = 0;
	}
	return tk[tkCnt++];
}
function nextInt() {
	return parseInt(next());
}
function nextDouble() {
	return parseFloat(next());
}

rl.on('line', (line) => {
	inputBuf.push(line);
}).on('close', () => {
	main();
});


This is an interactive problem.We hid from you a permutation $$$p$$$ of length $$$n$$$, consisting of the elements from $$$1$$$ to $$$n$$$. You want to guess it. To do that, you can give us 2 different indices $$$i$$$ and $$$j$$$, and we will reply with $$$p_{i} \bmod p_{j}$$$ (remainder of division $$$p_{i}$$$ by $$$p_{j}$$$).We have enough patience to answer at most $$$2 \cdot n$$$ queries, so you should fit in this constraint. Can you do it?As a reminder, a permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

The only line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — length of the permutation.

// let input = '';
// let inputResolve;
// let inputPromise = new Promise(resolve => inputResolve = resolve);
// process.stdin.on('data', c => input += c);
// process.stdin.on('end', () => inputResolve());

function For(a, b, step, fn) {
  let res;
  for (let i = a; i <= b; i += step) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

(async () => {
  // await inputPromise;
  // let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
  //   out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;

  let inputResolve;
  let inputNext = i => new Promise(resolve => inputResolve = resolve);
  process.stdin.on('data', c => inputResolve(+c));
  let n = await inputNext();
  if (n == 1) {
    console.log('! 1');
    process.exit();
  }
  let a = Array(n + 1);
  let i = 1;
  let j = 2;
  // setTimeout(() => {
  //   process.stdout.write(`! ${a.filter(v => v).length} ${Arr(n - 1, 1, 0, i => i).join(' ')}\n`);
  //   process.exit();
  // }, 800);
  while (1) {
    while (i <= n && a[i] || i == j) i++;
    while (j <= n && a[j] || i == j) j++;
    if (i > n || j > n) break;
    console.log('?', i, j);
    let mij = await inputNext()
    console.log('?', j, i);
    let mji = await inputNext()
    if (mij > mji) a[i++] = mij;
    else a[j++] = mji;
  }
  For(1, n, 1, i => a[i] ? null : a[i] = n);
  console.log('!', a.slice(1).join(' '));
  process.exit();
})();

// let input = '';
// let inputResolve;
// let inputPromise = new Promise(resolve => inputResolve = resolve);
// process.stdin.on('data', c => input += c);
// process.stdin.on('end', () => inputResolve());

function For(a, b, step, fn) {
  let res;
  for (let i = a; i <= b; i += step) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

(async () => {
  // await inputPromise;
  // let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
  //   out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;

  let inputResolve;
  let inputNext = i => new Promise(resolve => inputResolve = resolve);
  process.stdin.on('data', c => inputResolve(+c));
  let n = await inputNext();
  if (n == 1) {
    process.stdout.write(`! 1\n`);
    process.exit();
  }
  let a = Array(n + 1);
  let i = 1;
  let j = 2;
  // setTimeout(() => {
  //   process.stdout.write(`! ${a.filter(v => v).length} ${Arr(n - 1, 1, 0, i => i).join(' ')}\n`);
  //   process.exit();
  // }, 800);
  while (1) {
    while (i <= n && a[i] || i == j) i++;
    while (j <= n && a[j] || i == j) j++;
    if (i > n || j > n) break;
    process.stdout.write(`? ${i} ${j}\n`);
    let mij = await inputNext()
    process.stdout.write(`? ${j} ${i}\n`);
    let mji = await inputNext()
    if (mij > mji) a[i++] = mij;
    else a[j++] = mji;
  }
  For(1, n, 1, i => a[i] ? null : a[i] = n);
  process.stdout.write(`! ${a.slice(1).join(' ')}\n`);
  process.exit();
})();

// let input = '';
// let inputResolve;
// let inputPromise = new Promise(resolve => inputResolve = resolve);
// process.stdin.on('data', c => input += c);
// process.stdin.on('end', () => inputResolve());

function For(a, b, step, fn) {
  let res;
  for (let i = a; i <= b; i += step) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

(async () => {
  // await inputPromise;
  // let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
  //   out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;

  function* genMain() {
    let n = yield;
    if (n == 1) {
      console.log('! 1');
      process.exit();
    }
    let a = Array(n + 1);
    let i = 1;
    let j = 2;
    while (1) {
      while (i <= n && a[i] || i == j) i++;
      while (j <= n && a[j] || i == j) j++;
      if (i > n || j > n) break;
      console.log('?', i, j);
      let mij = yield;
      console.log('?', j, i);
      let mji = yield;
      if (mij > mji) a[i++] = mij;
      else a[j++] = mji;
    }
    For(1, n, 1, i => a[i] ? null : a[i] = n);
    console.log('!', a.slice(1).join(' '));
    process.exit();
  }
  let main = genMain();
  main.next();
  process.stdin.on('data', c => main.next(+c));

})();

// let input = '';
// let inputResolve;
// let inputPromise = new Promise(resolve => inputResolve = resolve);
// process.stdin.on('data', c => input += c);
// process.stdin.on('end', () => inputResolve());

function For(a, b, step, fn) {
  let res;
  for (let i = a; i <= b; i += step) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

(async () => {
  // await inputPromise;
  // let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
  //   out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;
  let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));
  let n = await next();
  if (n == 1) {
    process.stdout.write(`! 1\n`);
    process.exit();
  }
  let a = Array(n + 1);
  let i = 1;
  let j = 2;
  setTimeout(() => {
    process.stdout.write(`! ${a.filter(v => v).length}\n`);
    process.exit();
  }, 800);
  while (1) {
    while (i <= n && a[i] || i == j) i++;
    while (j <= n && a[j] || i == j) j++;
    if (i > n || j > n) break;
    process.stdout.write(`? ${i} ${j}\n`);
    let mij = await next();
    process.stdout.write(`? ${j} ${i}\n`);
    let mji = await next();
    if (mij > mji) a[i++] = mij;
    else a[j++] = mji;
  }
  For(1, n, 1, i => a[i] ? null : a[i] = n);
  process.stdout.write(`! ${a.slice(1).join(' ')}\n`);
  process.exit();
})();

// let input = '';
// let inputResolve;
// let inputPromise = new Promise(resolve => inputResolve = resolve);
// process.stdin.on('data', c => input += c);
// process.stdin.on('end', () => inputResolve());

function For(a, b, step, fn) {
  let res;
  for (let i = a; i <= b; i += step) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

(async () => {
  // await inputPromise;
  // let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
  //   out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;
  let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));
  let n = await next();
  if (n == 1) {
    process.stdout.write(`! 1\n`);
    process.exit();
  }
  let a = Array(n + 1);
  let i = 1;
  let j = 2;
  setTimeout(() => {
    process.stdout.write(`! ${Arr(n, 1, 0, i => i).join(' ')}\n`);
    process.exit();
  }, 800);
  while (1) {
    while (i <= n && a[i] || i == j) i++;
    while (j <= n && a[j] || i == j) j++;
    if (i > n || j > n) break;
    process.stdout.write(`? ${i} ${j}\n`);
    let mij = await next();
    process.stdout.write(`? ${j} ${i}\n`);
    let mji = await next();
    if (mij > mji) a[i++] = mij;
    else a[j++] = mji;
  }
  For(1, n, 1, i => a[i] ? null : a[i] = n);
  process.stdout.write(`! ${a.slice(1).join(' ')}\n`);
  process.exit();
})();

// let input = '';
// let inputResolve;
// let inputPromise = new Promise(resolve => inputResolve = resolve);
// process.stdin.on('data', c => input += c);
// process.stdin.on('end', () => inputResolve());

function For(a, b, step, fn) {
  let res;
  for (let i = a; i <= b; i += step) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

(async () => {
  // await inputPromise;
  // let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
  //   out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;
  let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));
  let n = await next();
  if (n == 1) {
    process.stdout.write(`! 1\n`);
    process.exit();
  }
  let a = Array(n + 1);
  let i = 1;
  let j = 2;
  setTimeout(() => {
    process.stdout.write(`! ${a.filter(v => v).length} ${Arr(n - 1, 1, 0, i => i).join(' ')}\n`);
    process.exit();
  }, 800);
  while (1) {
    while (i <= n && a[i] || i == j) i++;
    while (j <= n && a[j] || i == j) j++;
    if (i > n || j > n) break;
    process.stdout.write(`? ${i} ${j}\n`);
    let mij = await next();
    process.stdout.write(`? ${j} ${i}\n`);
    let mji = await next();
    if (mij > mji) a[i++] = mij;
    else a[j++] = mji;
  }
  For(1, n, 1, i => a[i] ? null : a[i] = n);
  process.stdout.write(`! ${a.slice(1).join(' ')}\n`);
  process.exit();
})();

// let input = '';
// let inputResolve;
// let inputPromise = new Promise(resolve => inputResolve = resolve);
// process.stdin.on('data', c => input += c);
// process.stdin.on('end', () => inputResolve());

function For(a, b, step, fn) {
  let res;
  for (let i = a; i <= b; i += step) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

(async () => {
  // await inputPromise;
  // let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
  //   out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;
  let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));
  let n = await next();
  if (n == 1) {
    process.stdout.write(`! 1\n`);
    process.exit();
  }
  let a = Array(n + 1);
  let i = 1;
  let j = 2;
  setTimeout(() => {
    process.stdout.write(`! ${a.filter(v => v).length} ${a.slice(1).join(' ')}\n`);
    process.exit();
  }, 800);
  while (1) {
    while (i <= n && a[i] || i == j) i++;
    while (j <= n && a[j] || i == j) j++;
    if (i > n || j > n) break;
    process.stdout.write(`? ${i} ${j}\n`);
    let mij = await next();
    process.stdout.write(`? ${j} ${i}\n`);
    let mji = await next();
    if (mij > mji) a[i++] = mij;
    else a[j++] = mji;
  }
  For(1, n, 1, i => a[i] ? null : a[i] = n);
  process.stdout.write(`! ${a.slice(1).join(' ')}\n`);
  process.exit();
})();

// let input = '';
// let inputResolve;
// let inputPromise = new Promise(resolve => inputResolve = resolve);
// process.stdin.on('data', c => input += c);
// process.stdin.on('end', () => inputResolve());

function For(a, b, step, fn) {
  let res;
  for (let i = a; i <= b; i += step) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, step, fn, init) {
  if (!step) {
    return a < b
      ? Array(b - a + 1).fill(0).map((v, i) => fn(a + i))
      : Array(a - b + 1).fill(0).map((v, i) => fn(a - i))
  }
  let arr = Array(Math.max(a, b) + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i += step) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

(async () => {
  // await inputPromise;
  // let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
  //   out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a;
  let next = i => new Promise(resolve => process.stdin.on('data', c => resolve(+c)));
  let n = await next();
  if (n == 1) {
    process.stdout.write(`! 1\n`);
    process.exit();
  }
  let a = Array(n + 1);
  let i = 1;
  let j = 2;
  setTimeout(() => {
    process.stdout.write(`! ${Arr(n, 1, -1, i => i).join(' ')}\n`);
    process.exit();
  }, 800);
  while (1) {
    while (i <= n && a[i] || i == j) i++;
    while (j <= n && a[j] || i == j) j++;
    if (i > n || j > n) break;
    process.stdout.write(`? ${i} ${j}\n`);
    let mij = await next();
    process.stdout.write(`? ${j} ${i}\n`);
    let mji = await next();
    if (mij > mji) a[i++] = mij;
    else a[j++] = mji;
  }
  For(1, n, 1, i => a[i] ? null : a[i] = n);
  process.stdout.write(`! ${a.slice(1).join(' ')}\n`);
  process.exit();
})();


Just to remind, girls in Arpa's land are really nice.Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 ≤ i < k, and a1 = x and ak = y.  Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it. Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.

The first line contains integers n, m and w (1  ≤  n  ≤  1000, , 1 ≤ w ≤ 1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited. The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 1000) — the weights of the Hoses. The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 106) — the beauties of the Hoses. The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 ≤ xi, yi ≤ n, xi ≠ yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.

Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.

NoteIn the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.

function sa(n, w, weights, nicest, friends){

        var friendsTo = [];

        for(var i=0;i<n;i++){
            friendsTo[i] = [];
            for(var j=0;j<friends.length;j++){
                if(friends[j][0] == i){
                    friendsTo[i].push(friends[j][1])
                } else if(friends[j][1] == i){
                    friendsTo[i].push(friends[j][0])
                }
            }

        }

        var sets = [];
        var visited = [];
        for(var i=0;i<n;i++){
            visited[i] = false;
        }

        for(var i=0;i<n;i++){
            if(visited[i]){
                continue;
            }

            var queue = [];
            queue.push(i);
            var newSet = [];
            while(queue.length > 0){
                var current = queue.pop();
                if(visited[current]){
                    continue;
                }
                visited[current] = true;
                newSet.push(current);
                for(var j=0;j<friendsTo[current].length;j++){
                    queue.push(friendsTo[current][j]);
                }
            }
            sets.push(newSet);
        }

        var dp = [];
        for(var i=0;i<=w;i++){
            dp[i]=0;
        }
        for(var i =0; i < sets.length; i++) {
            for(var j = w; j >= 0; j--) {
                var sumWeight = 0;
                var sumPrice = 0;
                for(var k=0;k<sets[i].length;k++){
                    var weight = weights[sets[i][k]];
                    sumWeight += weight;
                    var nice = nicest[sets[i][k]];
                    sumPrice += nice;
                    dp[j] = (weight > j) ? dp[j]: Math.max(dp[j], dp[j-weight] + nice);
                }
                dp[j] = (sumWeight > j) ? dp[j]: Math.max(dp[j], dp[j-sumWeight] + sumPrice);
            }
        }
    return dp[w];

    }
    var f = readline().split(" ").map(Number);
    var n = f[0];
    var m = f[1];
    var w = f[2];
    var weights = readline().split(" ").map(Number);
    var nicest = readline().split(" ").map(Number);
    var friends = [];
    for(var i=0;i<m;i++){
        friends.push(readline().split(" ").map(Number).map(a => a-1));
    }
    print(sa(n, w, weights, nicest, friends));

function sa(n, w, weights, nicest, friends){

        var friendsTo = [];

        for(var i=0;i<n;i++){
            friendsTo[i] = [];
            for(var j=0;j<friends.length;j++){
                if(friends[j][0] == i){
                    friendsTo[i].push(friends[j][1])
                } else if(friends[j][1] == i){
                    friendsTo[i].push(friends[j][0])
                }
            }

        }

        var sets = [];
        var visited = [];
        for(var i=0;i<n;i++){
            visited[i] = false;
        }

        for(var i=0;i<n;i++){
            if(visited[i]){
                continue;
            }

            var queue = [];
            queue.push(i);
            var newSet = [];
            while(queue.length > 0){
                var current = queue.pop();
                if(visited[current]){
                    continue;
                }
                visited[current] = true;
                newSet.push(current);
                for(var j=0;j<friendsTo[current].length;j++){
                    queue.push(friendsTo[current][j]);
                }
            }
            sets.push(newSet);
        }

        var dp = [];
        for(var j=0;j<sets.length;j++){
            dp[j] = [];
            dp[j][0] = 0;
            for(var i=1;i<=w;i++){
                var max = 0;
                for(var k=0;k<sets[j].length;k++){
                    var weight = weights[sets[j][k]];
                    var nice = nicest[sets[j][k]];
                    var a = dp[j-1] ? (dp[j-1][i] ||0) : 0;
                    var b = dp[j-1] ? (dp[j-1][i-weight] || 0) : 0;
                    if(i<weight){
                        dp[j][i] = Math.max(a,dp[j][i] || 0);
                    } else {
                        dp[j][i] = Math.max(Math.max(a, b + nice),dp[j][i] || 0);
                    }
                }

            }
        }
        var newDp = [];
        for(var j=0;j<sets.length;j++){
            var totalWeight = 0;
            var totalNice = 0;
            for(var k=0;k<sets[j].length;k++)    {
                totalNice += nicest[sets[j][k]];
                totalWeight += weights[sets[j][k]];
            }

            newDp[j] = [];
            newDp[j][0] = 0;
            for(var i=1;i<=w;i++){
                if(i<totalWeight){
                    var a = newDp[j-1] ? (newDp[j-1][i] ||0) : 0;
                    newDp[j][i] = Math.max(a, dp[j][i]);
                } else {

                     var a = newDp[j-1] ? (newDp[j-1][i] ||0) : 0;
                     var b = newDp[j-1] ? (newDp[j-1][i-weight] || 0) : 0;
                    newDp[j][i] = Math.max(b + totalNice, a);
                }

            }
        }

        return newDp[sets.length-1][w];

    }
    var f = readline().split(" ").map(Number);
    var n = f[0];
    var m = f[1];
    var w = f[2];
    var weights = readline().split(" ").map(Number);
    var nicest = readline().split(" ").map(Number);
    var friends = [];
    for(var i=0;i<m;i++){
        friends.push(readline().split(" ").map(Number).map(a => a-1));
    }
    print(sa(n, w, weights, nicest, friends));

function sa(n, w, weights, nicest, friends){

        var friendsTo = [];

        for(var i=0;i<n;i++){
            friendsTo[i] = [];
            for(var j=0;j<friends.length;j++){
                if(friends[j][0] == i){
                    friendsTo[i].push(friends[j][1])
                } else if(friends[j][1] == i){
                    friendsTo[i].push(friends[j][0])
                }
            }

        }

        var sets = [];
        var visited = [];
        for(var i=0;i<n;i++){
            visited[i] = false;
        }

        for(var i=0;i<n;i++){
            if(visited[i]){
                continue;
            }

            var queue = [];
            queue.push(i);
            var newSet = [];
            while(queue.length > 0){
                var current = queue.pop();
                if(visited[current]){
                    continue;
                }
                visited[current] = true;
                newSet.push(current);
                for(var j=0;j<friendsTo[current].length;j++){
                    queue.push(friendsTo[current][j]);
                }
            }
            sets.push(newSet);
        }

        var dp = [];
        for(var j=0;j<sets.length;j++){
            dp[j] = [];
            dp[j][0] = 0;
            for(var i=1;i<=w;i++){
                var max = 0;
                for(var k=0;k<sets[j].length;k++){
                    var weight = weights[sets[j][k]];
                    var nice = nicest[sets[j][k]];
                    var a = dp[j-1] ? (dp[j-1][i] ||0) : 0;
                    var b = dp[j-1] ? (dp[j-1][i-weight] || 0) : 0;
                    if(i<weight){
                        dp[j][i] = Math.max(a,dp[j][i] || 0);
                    } else {
                        dp[j][i] = Math.max(Math.max(a, b + nice),dp[j][i] || 0);
                    }
                }

            }
        }
        var newDp = [];
        for(var j=0;j<sets.length;j++){
            var totalWeight = 0;
            var totalNice = 0;
            for(var k=0;k<sets[j].length;k++)    {
                totalNice += nicest[sets[j][k]];
                totalWeight += weights[sets[j][k]];
            }

            newDp[j] = [];
            newDp[j][0] = 0;
            for(var i=1;i<=w;i++){
                if(i<totalWeight){
                    var a = newDp[j-1] ? (newDp[j-1][i] ||0) : 0;
                    newDp[j][i] = Math.max(a, dp[j][i]);
                } else {

                     var a = newDp[j-1] ? (newDp[j-1][i] ||0) : 0;
                     var b = newDp[j-1] ? (newDp[j-1][i-totalWeight] || 0) : 0;
                    newDp[j][i] = Math.max(b + totalNice, a);
                }

            }
        }
        return newDp[sets.length-1][w];

    }
    var f = readline().split(" ").map(Number);
    var n = f[0];
    var m = f[1];
    var w = f[2];
    var weights = readline().split(" ").map(Number);
    var nicest = readline().split(" ").map(Number);
    var friends = [];
    for(var i=0;i<m;i++){
        friends.push(readline().split(" ").map(Number).map(a => a-1));
    }
    print(sa(n, w, weights, nicest, friends));


Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view):  Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples.

The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.

Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.

NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled:   In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher:   In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:

var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
        arr = arr.split('\n') ;
        let str = arr[0],stack = [];
        let len = str.length;
        for(i=0;i<len-1;i++){
            if(i === 0) stack.push(str[i]);
            else{
                if(stack[stack.length-1] == str[i]) stack.pop();
                else stack.push(str[i]);
            }
        }
        if(stack.length === 0) console.log("Yes");
        else console.log("No");
    });

            var arr = '';
                process.stdin.on('data',function(chunk){
                   arr += chunk;
                });
                process.stdin.on('end',function(){
                    //arr = arr.split('\n') ;
                    console.log("for arr");
                    console.log(arr);
                    let str = arr[0],stack = [];
                    console.log("for str:"+str);
                    let len = str.length;
                    for(i=0;i<len;i++){
                        console.log("str[i]:"+str[i]);
                        if(i === 0) stack.push(str[i]);
                        else{
                            if(stack[stack.length-1] == str[i]) stack.pop();
                            else stack.push(str[i]);
                        }
                        console.log("for stack");
                        console.log(stack);
                    }
                    console.log("for stack outside");
                    console.log(stack);
                    if(stack.length === 0) console.log("Yes");
                    else console.log("No");
                });

var arr = '';
process.stdin.on('data',function(chunk){
   arr += chunk;
});
process.stdin.on('end',function(){
    arr = arr.split('\n') ;
    let str = arr[0],stack = [];
    let len = str.length;
    for(i=0;i<len;i++){
        if(i === 0) stack.push(str[i]);
        else
            if(stack[stack.length-1] == str[i]) stack.pop();
            else stack.push(str[i]);
    }
    if(stack.length === 0) console.log("Yes");
    else console.log("No");
});

    var arr = '';
        process.stdin.on('data',function(chunk){
           arr += chunk;
        });
        process.stdin.on('end',function(){
            arr = arr.split('\n') ;
            let str = arr[0],stack = [];
            console.log("for str:"+str);
            let len = str.length;
            for(i=0;i<len;i++){
                console.log("str[i]:"+str[i]);
                if(i === 0) stack.push(str[i]);
                else{
                    if(stack[stack.length-1] == str[i]) stack.pop();
                    else stack.push(str[i]);
                }
                console.log("for stack");
                console.log(stack);
            }
            console.log("for stack outside");
            console.log(stack);
            if(stack.length === 0) console.log("Yes");
            else console.log("No");
        });

var arr = '';
process.stdin.on('data',function(chunk){
   arr += chunk;
});
process.stdin.on('end',function(){
    arr = arr.split('\n') ;
    let str = arr[0],stack = [];
    let len = str.length;
    for(i=0;i<len;i++){
        if(i === 0) stack.push(str[i]);
        else
            if(stack[len-1] == str[i]) stack.pop();
            else stack.push(str[i]);
    }
    if(stack.length === 0) console.log("Yes");
    else console.log("No");
});

        var arr = '';
            process.stdin.on('data',function(chunk){
               arr += chunk;
            });
            process.stdin.on('end',function(){
                arr = arr.split('\n') ;
                console.log("for arr");
                console.log(arr);
                let str = arr[0],stack = [];
                console.log("for str:"+str);
                let len = str.length;
                for(i=0;i<len;i++){
                    console.log("str[i]:"+str[i]);
                    if(i === 0) stack.push(str[i]);
                    else{
                        if(stack[stack.length-1] == str[i]) stack.pop();
                        else stack.push(str[i]);
                    }
                    console.log("for stack");
                    console.log(stack);
                }
                console.log("for stack outside");
                console.log(stack);
                if(stack.length === 0) console.log("Yes");
                else console.log("No");
            });

    var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
        arr = arr.split('\n') ;
        let str = arr[0],stack = [];
        let len = str.length;
        for(i=0;i<len;i++){
            if(i === 0) stack.push(str[i]);
            else
                if(stack[stack.length-1] == str[i]) stack.pop();
                else stack.push(str[i]);
        }
        console.log("for stack");
        console.log(stack);
        if(stack.length === 0) console.log("Yes");
        else console.log("No");
    });

var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
        arr = arr.split('\n') ;
        let str = arr[0],stack = [];
        let len = str.length;
        for(i=0;i<len;i++){
            if(i === 0) stack.push(str[i]);
            else{
                if(stack[stack.length-1] == str[i]) stack.pop();
                else stack.push(str[i]);
            }
            console.log("for stack");
            console.log(stack);
        }
        console.log("for stack outside");
        console.log(stack);
        if(stack.length === 0) console.log("Yes");
        else console.log("No");
    });

                var arr = '';
                    process.stdin.on('data',function(chunk){
                       arr += chunk;
                    });
                    process.stdin.on('end',function(){
                        arr = arr.split('\n') ;
                        console.log("for arr");
                        console.log(arr);
                        let str = arr[0],stack = [];
                        console.log("for str:"+str);
                        let len = str.length;
                        console.log("for len:"+len);
                        for(i=0;i<len-1;i++){
                            console.log("str[i]:"+str[i]);
                            if(i === 0) stack.push(str[i]);
                            else{
                                if(stack[stack.length-1] == str[i]) stack.pop();
                                else stack.push(str[i]);
                            }
                            console.log("for stack");
                            console.log(stack);
                        }
                        console.log("for stack outside");
                        console.log(stack);
                        if(stack.length === 0) console.log("Yes");
                        else console.log("No");
                    });