Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:  the final tournament features n teams (n is always even)  the first n / 2 teams (according to the standings) come through to the knockout stage  the standings are made on the following principle: for a victory a team gets 3 points, for a draw — 1 point, for a defeat — 0 points. In the first place, teams are ordered in the standings in decreasing order of their points; in the second place — in decreasing order of the difference between scored and missed goals; in the third place — in the decreasing order of scored goals  it's written in Berland's Constitution that the previous regulation helps to order the teams without ambiguity. You are asked to write a program that, by the given list of the competing teams and the results of all the matches, will find the list of teams that managed to get through to the knockout stage.

The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) / 2 lines describe the held matches in the format name1-name2 num1:num2, where name1, name2 — names of the teams; num1, num2 (0 ≤ num1, num2 ≤ 100) — amount of the goals, scored by the corresponding teams. Accuracy of the descriptions is guaranteed: there are no two team names coinciding accurate to the letters' case; there is no match, where a team plays with itself; each match is met in the descriptions only once.

Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.

'use strict'

let lll

const N = +readline()

let ts = {}

for (let i = 0; i < N; i++) {
  const n = readline()
  ts[n] = [0, 0, 0, n]
}

while (lll = readline()) {
  const fn = lll.slice(0, lll.indexOf('-'))
  const sn = lll.slice(lll.indexOf('-') + 1, lll.indexOf(' '))
  const scr = lll.slice(lll.indexOf(' ') + 1).split(':').map(v => parseInt(v))
  const fs = scr[0]
  const ss = scr[1]
  if (fs > ss) {
    ts[fn][0] += 3
  } else if (ss > fs) {
    ts[sn][0] += 3
  } else {
    ts[fn][0] += 1
    ts[sn][0] += 1
  }
  ts[fn][1] += fs
  ts[fn][1] -= ss
  ts[sn][1] += ss
  ts[sn][1] -= fs
  ts[fn][2] += fs
  ts[sn][2] += ss
}

const ns = Object.keys(ts)
const tsa = []

for (let i = 0; i < ns.length; i++) {
  tsa.push(ts[ns[i]])
}

tsa.sort((ft, st) => ft[0] - st[0] || ft[1] - st[1] || ft[2] - st[2])

const pots = tsa.slice(tsa.length / 2).map(v => v[3]).sort()

pots.forEach(v => print(v))

const readline = require('readline');

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

class Info {
    constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {
        this.teamName = newTeamName;
        this.points = newPoints;
        this.goalDiff = newGoalDiff;
        this.scoredGoals = newScoredGoals;
    }
}

var findIndexByName = function (cont, searchName) {
    for (let i = 0; i < cont.length; i++) {
        if (cont[i].teamName == searchName)
            return i;
    }
    return -1;
}
var cont = [];
var indicator = 0, N;

rl.on('line', (input) => {
    if (indicator == 0) {
        N = parseInt(input);
        indicator++;
    }
    else if (indicator <= N) {
        cont.push(new Info(input, 0, 0, 0));
        indicator++;
    }
    else {
        let dashIndex = input.indexOf("-");
        let spaceIndex = input.indexOf(" ");
        let colonIndex = input.indexOf(":");
        let team1Name = input.substring(0, dashIndex);
        let team2Name = input.substring(dashIndex + 1, spaceIndex);
        let goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));
        let goal2 = parseInt(input.substring(colonIndex + 1));
        let team1Index = findIndexByName(cont, team1Name);
        let team2Index = findIndexByName(cont, team2Name);
        // update points
        if (goal1 > goal2)
            cont[team1Index].points += 3;
        else if (goal1 < goal2)
            cont[team2Index].points += 3;
        else {
            cont[team1Index].points++;
            cont[team2Index].points++;
        }
        // update goalDiff
        cont[team1Index].goalDiff += (goal1 - goal2);
        cont[team2Index].goalDiff += (goal2 - goal1);
        // update scoredGoals
        cont[team1Index].scoredGoals += goal1;
        cont[team2Index].scoredGoals += goal2;
    }
}).on('close', function () {
    // sort by points, then by goalDiff, then by scoredGoals in descending order:
    cont.sort((obj1, obj2) => {
        if (obj1.points != obj2.points)
            return obj2.points - obj1.points;

        if (obj1.goalDiff != obj2.goalDiff)
            return obj2.goalDiff - obj1.goalDiff;

        return obj2.scoredGoals - obj1.scoredGoals;
    });
    // delete second half of cont
    cont.splice(N / 2);
    // sort by teamName in lexicographical order
    cont.sort((obj1, obj2) => {
        let s1 = obj1.teamName;
        let s2 = obj2.teamName;
        let s1Len = s1.length;
        let s2Len = s2.length;
        let minLen = Math.min(s1Len, s2Len);
        for (let i = 0; i < minLen; i++) {
            if (s1[i] != s2[i])
                return s1.charCodeAt(i) - s2.charCodeAt(i);
        }
        return s1Len - s2Len;
    });

    cont.forEach(item => {
        console.log(item.teamName);
    });
});

/*
    0123456789.........
s= 'barcelona-real 15:10'

4
A
B
C
D
A-B 1:1
A-C 2:2
A-D 1:0
B-C 1:0
B-D 0:3
C-D 0:3

Points                 goalDiff                           scoredGoals
A => 1+1+3=5           A=> (1+2+1) - (1+2+0)= 4-3=1       A=> 4
B => 1+3+0=4           B=> (1+1+0) - (1+0+3)= 2-4=-2      B=> 2
C => 1+0+0=1           C=> (2+0+0) - (2+1+3)= 2-6=-4      C=> 2
D => 0+3+3=6           D=> (0+3+3) - (1+0+0)= 6-1=5       D=> 6

A, B, C, D => D, A, B, C => D, A =>A, D

cont:
    0               1
|teamName: 'A' |teamname: 'B'|
|point: 5      |point: 5     |
|goalDiff: 1   |
|scoredGoals: 4|
*/

const readline = require('readline');

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

class Info {
    constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {
        this.TeamName = newTeamName;
        this.Points = newPoints;
        this.GoalDiff = newGoalDiff;
        this.ScoredGoals = newScoredGoals;
    }
}

var indicator = 0, N, cont = [];

rl.on('line', (input) => {
    if (indicator == 0) {
        N = parseInt(input);
        indicator++;
    }
    else if (indicator <= N) {
        //var obj=new Info(input,0,0,0);
        cont.push(new Info(input, 0, 0, 0));
        indicator++;
    }
    else {
        var dashIndex = input.indexOf('-');
        var spaceIndex = input.indexOf(' ');
        var colonIndex = input.indexOf(':');

        var Team1Name = input.substring(0, dashIndex);
        var Team2Name = input.substring(dashIndex + 1, spaceIndex);

        var Goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));
        var Goal2 = parseInt(input.substring(colonIndex + 1));

        var Team1Index = cont.findIndex(item => item.TeamName == Team1Name);
        var Team2Index = cont.findIndex(item => item.TeamName == Team2Name);

        //Update Points

        if (Goal1 > Goal2)
            cont[Team1Index].Points += 3;
        else if (Goal1 < Goal2)
            cont[Team2Index].Points += 3;
        else {
            cont[Team1Index].Points++;
            cont[Team2Index].Points++;
        }
        //Update Goal Difference
        cont[Team1Index].GoalDiff += (Goal1 - Goal2);
        cont[Team2Index].GoalDiff += (Goal2 - Goal1);

        //Update Scored Goals
        cont[Team1Index].ScoredGoals += Goal1;
        cont[Team2Index].ScoredGoals += Goal2;

    }

}).on('close', () => {
    //sort by points, then by GoalDiff and then by ScoredGoals in descending order
    cont.sort((obj1, obj2) => {
        if (obj1.Points != obj2.Points)
            return obj2.Points - obj1.Points;

        if (obj1.GoalDiff != obj2.GoalDiff)
            return obj2.GoalDiff - obj1.GoalDiff;

        return obj2.ScoredGoals - obj1.ScoredGoals;
    });

    //delete second half of our array
    cont.splice(N/2);
    //sort by Team name in ascending order
    cont.sort( (obj1,obj2) => {
       // return obj1.TeamName.localeCompare(obj2.TeamName);
       return obj1.TeamName > obj2.TeamName ? 1 : -1;
    });
    //output
    cont.forEach(item => {
        console.log(item.TeamName);
    });
});

const readline = require('readline');

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

class Info{
    constructor(newTeamName, newPoint, newGoalDiff, newScoredGoals){
        this.teamName=newTeamName;
        this.point=newPoint;
        this.goalDiff=newGoalDiff;
        this.scoredGoals=newScoredGoals;
    }
}
/*
  var findIndexByName = function(cont, searchName){
         for(let i=0; i<cont.length;i++){
             if(cont[i] == searchName)
                  return i;
         }
       return -1;
  }
  */

  var cont=[],indicator=0, N=0;
  rl.on('line', (input) => {
    if(indicator == 0){
        N = parseInt(input);
        indicator++;
    }
    else if(indicator <= N){
      cont.push(new Info(input,0,0,0));
      indicator++;
    }
    else{
        let dashInd = input.indexOf('-');
        let spaceInd = input.indexOf(' ');
        let colonInd = input.indexOf(':');

        let team1Name = input.substring(0,dashInd);
        let team2Name = input.substring(dashInd+1, spaceInd);
        let goal1=parseInt(input.substring(spaceInd+1, colonInd));
        let goal2=parseInt(input.substring(colonInd+1));

        let team1Index = cont.findIndex(obj => obj.teamName == team1Name);
        let team2Index = cont.findIndex(obj => obj.teamName == team2Name);

        //update points
        if(goal1>goal2)
          cont[team1Index].point +=3;
        else if(goal1<goal2)
          cont[team2Index].point+=3;
        else{
           cont[team1Index].point++;
           cont[team2Index].point++;
        }

        // update goal difference
        cont[team1Index].goalDiff += (goal1-goal2);
        cont[team2Index].goalDiff += (goal2-goal1);

        // update scored goals
        cont[team1Index].scoredGoals += goal1;
        cont[team2Index].scoredGoals += goal2;

    }
  }).on('close',function(){
     // sort by descending order first of all by points, thenby goalDiff and then by scoredGoals
     cont.sort((obj1, obj2)=>{

        if(obj1.point != obj2.point)
             return obj2.point - obj1.point;

        if(obj1.goalDiff != obj2.goalDiff)
           return obj2.goalDiff - obj1.goalDiff;

        return obj2.scoredGoals - obj1.scoredGoals;
     });

     // remove second half of array
    cont.splice(N/2);

    //sort by lexicographical order
    cont.sort((obj1, obj2)=>{

        if(obj1.teamName > obj2.teamName)
           return 1;
        else if(obj1.teamName < obj2.teamName)
           return -1;
        else
           return 0;
    });

    cont.forEach(element => {
        console.log(element.teamName);
    });

  });

/*

           0               1             2  ........
cont=|teamName: "A" |teamName: "B"|.......
     |point: 5      |
     |goalDiff: 1   |
     |scoredGoals: 4|
*/
  /*

4
A
B
C
D
A-B 1:1
A-C 2:2
A-D 1:0
B-C 1:0
B-D 0:3
C-D 0:3

Points             GoalDifference                 ScoredGoals

A=>1+1+3=5         A=>(1+2+1)-(1+2)=4-3=1         A=>4
B=>1+3+0=4         B=>(1+1)-(1+3)=2-4=-2          B=>2
C=>1+0+0=1         C=>(2)-(2+1+3)=2-6=-4          C=>2
D=>0+3+3=6         D=>(3+3)-(1)=6-1=5             D=>6

A B C D => D A B C => D A => A D
  */

const readline = require('readline');

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

class Info {
    constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {
        this.teamName = newTeamName;
        this.points = newPoints;
        this.goalDiff = newGoalDiff;
        this.scoredGoals = newScoredGoals;
    }
}
var indexOfByName = function (cont,N, searchName) {
    for (let i = 0; i < N; i++)
        if (cont[i].teamName == searchName)
            return i;
    return -1;
}
var indicator = 0, N, cont = [];

rl.on('line', (input) => {
    if (indicator == 0) {
        N = parseInt(input);
        indicator++;
    }
    else if (indicator <= N) {
        cont.push(new Info(input, 0, 0, 0));
        indicator++;
    }
    else {
        let dashIndx = input.indexOf('-');
        let spaceIndx = input.indexOf(' ');
        let colonIndx = input.indexOf(':');

        let team1Name = input.substring(0, dashIndx);
        let team2Name = input.substring(dashIndx + 1, spaceIndx);
        let Goal1 = parseInt(input.substring(spaceIndx + 1, colonIndx));
        let Goal2 = parseInt(input.substring(colonIndx + 1));

        let team1Indx = indexOfByName(cont,N, team1Name);
        let team2Indx = indexOfByName(cont,N, team2Name);

        //update points

        if (Goal1 > Goal2)
            cont[team1Indx].points += 3;
        else if (Goal1 < Goal2)
            cont[team2Indx].points += 3;
        else {
            cont[team1Indx].points++;
            cont[team2Indx].points++;
        }

        //update goal diff

        cont[team1Indx].goalDiff += (Goal1 - Goal2);
        cont[team2Indx].goalDiff += (Goal2 - Goal1);

        //update scored goals

        cont[team1Indx].scoredGoals += Goal1;
        cont[team2Indx].scoredGoals += Goal2;

    }
}).on('close', () => {
    //sort by points then by GoalDiff then by scored goals in descending order
    cont.sort((obj1, obj2) => {
        if (obj1.points != obj2.points)
            return obj2.points - obj1.points;

        if (obj1.goalDiff != obj2.goalDiff)
            return obj2.goalDiff - obj1.goalDiff;

       return obj2.scoredGoals - obj1.scoredGoals;
    });

    // delete the second half of array
    cont.splice(N / 2);
    //order by teamName in lexicographical order ascending order
    cont.sort((obj1, obj2) => {
        let s1 = obj1.teamName;
        let s2 = obj2.teamName;
        let s1Len = s1.length;
        let s2Len = s2.length;
        let minLen = Math.min(s1Len, s2Len);
        for (let i = 0; i < minLen; i++) {
            if (s1[i] != s2[i])
                return s1.charCodeAt(i) - s2.charCodeAt(i);
        }
        return s1Len - s2Len;
    });

    //output ans
    cont.forEach(element => {
        console.log(element.teamName);
    });
});

/*
       0123456789...
input="Barcelona-Real 15:10"
4
A
B
C
D
A-B 1:1
A-C 2:2
A-D 1:0
B-C 1:0
B-D 0:3
C-D 0:3

Points            GoalDiff                     ScoredGoals
A=>1+1+3=5        A=>(1+2+1)-(1+2)=4-3=1       A=>4
B=>1+3=4          B=>(1+1)-(1+3)=2-4=-2        B=>2
C=>1              C=>(2)-(2+1+3)=2-6=-4        C=>2
D=>3+3=6          D=>(3+3)-(1)=6-1=5           D=>6

{D,A,B,C} => {D,A} => {A,D}

  0
|teamName: "A" |teamName
|Points: 5     |
|GoalDiff: -2  |
|scoredGoals: 4|

*/

const readline = require("readline");

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

class Info {
  constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {
    this.teamName = newTeamName;
    this.points = newPoints;
    this.goalDiff = newGoalDiff;
    this.scoredGoals = newScoredGoals;
  }
}

var indexOfByName = function (cont, searchName) {
  for (let i = 0; i < cont.length; i++) {
    if (cont[i].teamName == searchName) return i;
  }
  return -1;
};
/*

4
A
B
C
D
A-B 1:1
A-C 2:2
A-D 1:0
B-C 1:0
B-D 0:3
C-D 0:3

*/

var cont = [],
  indicator = 0,
  N = 0;
rl.on("line", (input) => {
  if (indicator == 0) {
    N = parseInt(input);
    indicator++;
  } else if (indicator <= N) {
    cont.push(new Info(input, 0, 0, 0));
    indicator++;
  } else {
    // 0123456789....
    //"Barcelona-Real 15:10"
    let dashIndex = input.indexOf("-");
    let spaceIndex = input.indexOf(" ");
    let colonIndex = input.indexOf(":");
    let team1Name = input.substring(0, dashIndex);
    let team2Name = input.substring(dashIndex + 1, spaceIndex);
    let goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));
    let goal2 = parseInt(input.substring(colonIndex + 1));
    let team1Index = indexOfByName(cont, team1Name);
    let team2Index = indexOfByName(cont, team2Name);
    // Update Points
    if (goal1 > goal2) cont[team1Index].points += 3;
    else if (goal1 < goal2) cont[team2Index].points += 3;
    else {
      cont[team1Index].points++;
      cont[team2Index].points++;
    }
    //update goal diff
    cont[team1Index].goalDiff += goal1 - goal2;
    cont[team2Index].goalDiff += goal2 - goal1;
    //update Score goals
    cont[team1Index].scoredGoals += goal1;
    cont[team2Index].scoredGoals += goal2;
  }
}).on("close", function () {
  // sort by point then by goalDiff and then by scored goals in descending order
  cont.sort((obj1, obj2) => {
    if (obj1.points != obj2.points) return obj2.points - obj1.points;

    if (obj1.goalDiff != obj2.goalDiff) return obj2.goalDiff - obj1.goalDiff;

    return obj2.scoredGoals - obj1.scoredGoals;
  });

  //erse second half of an array
  cont.splice(N / 2);

  //sort by teamname in ascending order
  cont.sort((obj1, obj2) => {
    let s1 = obj1.teamName;
    let s2 = obj2.teamName;
    let s1Len = s1.length;
    let s2Len = s2.length;
    let minLen = Math.min(s1Len, s2Len);
    for (let i = 0; i < minLen; i++) {
      if (s1[i] != s2[i]) return s1.charCodeAt(i) - s2.charCodeAt(i);
    }
    return s1Len - s2Len;
  });

  //output answer
  cont.forEach((element) => {
    console.log(element.teamName);
  });
});

const readline = require('readline');

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

class Info {
    constructor(teamName, points, goalDiff, scoredGoals) {
        this.teamName = teamName;
        this.points = points;
        this.goalDiff = goalDiff;
        this.scoredGoals = scoredGoals;
    }

}

var outputInfoObj = function (obj) {
    console.log("************************");
    console.log("teamName=%s ", obj.teamName);
    console.log("points  = %d", obj.points);
    console.log("goaldiff  = %d", obj.goalDiff);
    console.log("scoredgoals  = %d", obj.scoredGoals);
    console.log("************************");
}

var customCompare = function (obj1, obj2) {
    if (obj1.points != obj2.points)
        return obj2.points - obj1.points;

    if (obj1.goalDiff != obj2.goalDiff)
        return obj2.goalDiff - obj1.goalDiff;

    return obj2.scoredGoals - obj1.scoredGoals;
}

var compareByName = function (obj1, obj2) {
    var s1 = obj1.teamName;
    var s2 = obj2.teamName;
    var s1Len = s1.length;//<=problem was here. error caused: Length instead of length
    var s2Len = s2.length;// note that js
    var minLen = (s1Len > s2Len) ? s2Len : s1Len;
    for (let i = 0; i < minLen; i++) {
        let cd1 = s1.charCodeAt(i);
        let cd2 = s2.charCodeAt(i);
        //console.log("inside compare func s1=%s s2=%s  cd1=%d  cd2=%d",s1,s2,cd1,cd2);
        if (cd1 != cd2)
            return  cd1-cd2;
        /*
                if(s1[i]!=s2[i])
                    //return s1[i]-s2[i];
                    return s1.charCodeAt(i) - s2.charCodeAt(i);
        */
    }
    return s1Len - s2Len;
}

var n, indicator = 0,
    cont = [];

rl.on('line', (input) => {
    if (indicator == 0) {
        n = parseInt(input);
        indicator++;
    } else if (indicator <= n) {
        cont.push(new Info(input, 0, 0, 0));
        indicator++;
    } else {
        var dashIndex = input.indexOf('-');
        var spaceIndex = input.indexOf(' ');
        var colonIndex = input.indexOf(':');
        var team1Name = input.substring(0, dashIndex);
        var team2Name = input.substring(dashIndex + 1, spaceIndex);
        var goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));
        var goal2 = parseInt(input.substring(colonIndex + 1));
        var team1Index = cont.findIndex(item => item.teamName == team1Name);
        var team2Index = cont.findIndex(item => item.teamName == team2Name);

        //Update points
        if (goal1 > goal2)
            cont[team1Index].points += 3;
        else if (goal2 > goal1)
            cont[team2Index].points += 3;
        else {
            cont[team1Index].points++;
            cont[team2Index].points++;
        }
        //Update Goal Difference
        cont[team1Index].goalDiff += (goal1 - goal2);
        cont[team2Index].goalDiff += (goal2 - goal1);
        //Update Scored Goals
        cont[team1Index].scoredGoals += goal1;
        cont[team2Index].scoredGoals += goal2;

    }
}).on('close', () => {
    /* cont.forEach(item => {
         outputInfoObj(item);
     });*/
    cont.sort(customCompare);
    cont.splice(n / 2);
    //cont.sort((obj1, obj2) => obj1.teamName.localeCompare(obj2.teamName));
    cont.sort(compareByName);
    cont.forEach(item => {
        console.log(item.teamName);
    });

});

'use strict'

let lll

const N = +readline()

let ts = {}

for (let i = 0; i < N; i++) {
  const n = readline()
  ts[n] = [0, 0, 0, n]
}

while (lll = readline()) {
  const fn = lll.slice(0, lll.indexOf('-'))
  const sn = lll.slice(lll.indexOf('-') + 1, lll.indexOf(' '))
  const scr = lll.slice(lll.indexOf(' ') + 1).split(':').map(v => parseInt(v))
  const fs = scr[0]
  const ss = scr[1]
  if (fs > ss) {
    ts[fn][0] += 3
  } else if (ss > fs) {
    ts[sn][0] += 3
  } else {
    ts[fn][0] += 1
    ts[sn][0] += 1
  }
  ts[fn][1] += fs
  ts[fn][1] -= ss
  ts[sn][1] += ss
  ts[sn][1] -= fs
  ts[fn][2] += fs
  ts[sn][2] += ss
}

const ns = Object.keys(ts)
const tsa = []

for (let i = 0; i < ns.length; i++) {
  tsa.push(ts[ns[i]])
}

tsa.sort((ft, st) => ft[0] - st[0] || ft[1] - st[1] || ft[2] - st[2])

for (let i = tsa.length / 2 | 0; i < tsa.length; i++) print(tsa[i][3])

const readline = require('readline');

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

class Info {
    constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {
        this.TeamName = newTeamName;
        this.Points = newPoints;
        this.GoalDiff = newGoalDiff;
        this.ScoredGoals = newScoredGoals;
    }
}

var indicator = 0, N, cont = [];

rl.on('line', (input) => {
    if (indicator == 0) {
        N = parseInt(input);
        indicator++;
    }
    else if (indicator <= N) {
        //var obj=new Info(input,0,0,0);
        cont.push(new Info(input, 0, 0, 0));
        indicator++;
    }
    else {
        var dashIndex = input.indexOf('-');
        var spaceIndex = input.indexOf(' ');
        var colonIndex = input.indexOf(':');

        var Team1Name = input.substring(0, dashIndex);
        var Team2Name = input.substring(dashIndex + 1, spaceIndex);

        var Goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));
        var Goal2 = parseInt(input.substring(colonIndex + 1));

        var Team1Index = cont.findIndex(item => item.TeamName == Team1Name);
        var Team2Index = cont.findIndex(item => item.TeamName == Team2Name);

        //Update Points

        if (Goal1 > Goal2)
            cont[Team1Index].Points += 3;
        else if (Goal1 < Goal2)
            cont[Team2Index].Points += 3;
        else {
            cont[Team1Index].Points++;
            cont[Team2Index].Points++;
        }
        //Update Goal Difference
        cont[Team1Index].GoalDiff += (Goal1 - Goal2);
        cont[Team2Index].GoalDiff += (Goal2 - Goal1);

        //Update Scored Goals
        cont[Team1Index].ScoredGoals += Goal1;
        cont[Team2Index].ScoredGoals += Goal2;

    }

}).on('close', () => {
    //sort by points, then by GoalDiff and then by ScoredGoals in descending order
    cont.sort((obj1, obj2) => {
        if (obj1.Points != obj2.Points)
            return obj2.Points - obj1.Points;

        if (obj1.GoalDiff != obj2.GoalDiff)
            return obj2.GoalDiff - obj1.GoalDiff;

        return obj2.ScoredGoals - obj1.ScoredGoals;
    });

    //delete second half of our array
    cont.splice(N/2);
    //sort by Team name in ascending order
    cont.sort( (obj1,obj2) => {
        return obj1.TeamName.localeCompare(obj2.TeamName);
    });
    //output
    cont.forEach(item => {
        console.log(item.TeamName);
    });
});

const readline = require('readline');

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

class Info {
    constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {
        this.teamName = newTeamName;
        this.points = newPoints;
        this.goalDiff = newGoalDiff;
        this.scoredGoals = newScoredGoals;
    }
}
var indexOfByName = function (cont, searchName) {
    for (let i = 0; i < cont.length; i++)
        if (cont[i].teamName == searchName)
            return i;
    return -1;
}
var indicator = 0, N, cont = [];

rl.on('line', (input) => {
    if (indicator == 0) {
        N = parseInt(input);
        indicator++;
    }
    else if (indicator <= N) {
        cont.push(new Info(input, 0, 0, 0));
        indicator++;
    }
    else {
        let dashIndx = input.indexOf('-');
        let spaceIndx = input.indexOf(' ');
        let colonIndx = input.indexOf(':');

        let team1Name = input.substring(0, dashIndx);
        let team2Name = input.substring(dashIndx + 1, spaceIndx);
        let Goal1 = parseInt(input.substring(spaceIndx + 1, colonIndx));
        let Goal2 = parseInt(input.substring(colonIndx + 1));

        let team1Indx = indexOfByName(cont, team1Name);
        let team2Indx = indexOfByName(cont, team2Name);

        //update points

        if (Goal1 > Goal2)
            cont[team1Indx].points += 3;
        else if (Goal1 < Goal2)
            cont[team2Indx].points += 3;
        else {
            cont[team1Indx].points++;
            cont[team2Indx].points++;
        }

        //update goal diff

        cont[team1Indx].goalDiff += (Goal1 - Goal2);
        cont[team2Indx].goalDiff += (Goal2 - Goal1);

        //update scored goals

        cont[team1Indx].scoredGoals += Goal1;
        cont[team2Indx].scoredGoals += Goal2;

    }
}).on('close', () => {
    //sort by points then by GoalDiff then by scored goals in descending order
    cont.sort((obj1, obj2) => {
        if (obj1.points != obj2.points)
            return obj2.points - obj1.points;
        if (obj1.goalDiff != obj2.goalDiff)
            return obj2.goalDiff - obj1.goalDiff;

        obj2.scoredGoals - obj1.scoredGoals;
    });

    // delete the second half of array
    cont.splice(N / 2);
    //order by teamName in lexicographical order ascending order
    cont.sort((obj1, obj2) => {
        let s1 = obj1.teamName;
        let s2 = obj2.teamName;
        let s1Len = s1.length;
        let s2Len = s2.length;
        let minLen = Math.min(s1Len, s2Len);
        for (let i = 0; i < minLen; i++) {
            if (s1[i] != s2[i])
                return s1.charCodeAt(i) - s2.charCodeAt(i);
        }
        return s1Len - s2Len;
    });

    //output ans
    cont.forEach(element => {
        console.log(element.teamName);
    });
});

const readline = require("readline");

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

class Info {
  constructor(newTeamName, newPoints, newGoalDiff, newScoredGoals) {
    this.teamName = newTeamName;
    this.points = newPoints;
    this.goalDiff = newGoalDiff;
    this.scoredGoals = newScoredGoals;
  }
}

var indexOfByName = function (cont, searchName) {
  for (let i = 0; i < cont.length; i++) {
    if (cont[i].teamName == searchName) return i;
  }
  return -1;
};
/*

4
A
B
C
D
A-B 1:1
A-C 2:2
A-D 1:0
B-C 1:0
B-D 0:3
C-D 0:3

*/

var cont = [],
  indicator = 0,
  N = 0;
rl.on("line", (input) => {
  if (indicator == 0) {
    N = parseInt(input);
    indicator++;
  } else if (indicator <= N) {
    cont.push(new Info(input, 0, 0, 0));
    indicator++;
  } else {
    // 0123456789....
    //"Barcelona-Real 15:10"
    let dashIndex = input.indexOf("-");
    let spaceIndex = input.indexOf(" ");
    let colonIndex = input.indexOf(":");
    let team1Name = input.substring(0, dashIndex);
    let team2Name = input.substring(dashIndex + 1, spaceIndex);
    let goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));
    let goal2 = parseInt(input.substring(colonIndex + 1));
    let team1Index = indexOfByName(cont, team1Name);
    let team2Index = indexOfByName(cont, team2Name);
    // Update Points
    if (goal1 > goal2) cont[team1Index].points += 3;
    else if (goal1 < goal2) cont[team2Index].points += 3;
    else {
      cont[team1Index].points++;
      cont[team2Index].points++;
    }
    //update goal diff
    cont[team1Index].goalDiff += goal1 - goal2;
    cont[team2Index].goalDiff += goal2 - goal1;
    //update Score goals
    cont[team1Index].scoredGoals += goal1;
    cont[team2Index].scoredGoals += goal2;
  }
}).on("close", function () {
  // sort by point then by goalDiff and then by scored goals in descending order
  cont.sort((obj1, obj2) => {
    if (obj1.points != obj2.points) return obj2.points - obj1.points;

    if (obj1.goalDiff != obj2.goalDiff) return obj2.goalDiff - obj1.goalDiff;

    return obj2.scoredGoals - obj2.scoredGoals;
  });

  //erse second half of an array
  cont.splice(N / 2);

  //sort by teamname in ascending order
  cont.sort((obj1, obj2) => {
    let s1 = obj1.teamName;
    let s2 = obj2.teamName;
    let s1Len = s1.length;
    let s2Len = s2.length;
    let minLen = Math.min(s1Len, s2Len);
    for (let i = 0; i < minLen; i++) {
      if (s1[i] != s2[i]) return s1.charCodeAt(i) - s2.charCodeAt(i);
    }
    return s1Len - s2Len;
  });

  //output answer
  cont.forEach((element) => {
    console.log(element.teamName);
  });
});

const readline = require('readline');

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

class Info {
    constructor(teamName, points, goalDiff, scoredGoals) {
        this.teamName = teamName;
        this.points = points;
        this.goalDiff = goalDiff;
        this.scoredGoals = scoredGoals;
    }

}

var outputInfoObj = function (obj) {
    console.log("************************");
    console.log("teamName=%s ", obj.teamName);
    console.log("points  = %d", obj.points);
    console.log("goaldiff  = %d", obj.goalDiff);
    console.log("scoredgoals  = %d", obj.scoredGoals);
    console.log("************************");
}

var customCompare = function (obj1, obj2) {
    if (obj1.points != obj2.points)
        return obj2.points - obj1.points;

    if (obj1.goalDiff != obj2.goalDiff)
        return obj2.goalDiff - obj1.goalDiff;

    return obj2.scoredGoals - obj1.scoredGoals;
}

var compareByName = function (obj1, obj2) {
    var s1 = obj1.teamName;
    var s2 = obj2.teamName;
    var s1Len = s1.Length;
    var s2Len = s2.Length;
    var minLen = (s1Len>s2Len)?s2Len:s1Len;
    for(let i=0;i<minLen;i++){
        if(s1[i]!=s2[i])
            return s1[i]-s2[i];
    }
    return s1Len-s2Len;
}

var n, indicator = 0,
    cont = [];

rl.on('line', (input) => {
    if (indicator == 0) {
        n = parseInt(input);
        indicator++;
    } else if (indicator <= n) {
        cont.push(new Info(input, 0, 0, 0));
        indicator++;
    } else {
        var dashIndex = input.indexOf('-');
        var spaceIndex = input.indexOf(' ');
        var colonIndex = input.indexOf(':');
        var team1Name = input.substring(0, dashIndex);
        var team2Name = input.substring(dashIndex + 1, spaceIndex);
        var goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));
        var goal2 = parseInt(input.substring(colonIndex + 1));
        var team1Index = cont.findIndex(item => item.teamName == team1Name);
        var team2Index = cont.findIndex(item => item.teamName == team2Name);

        //Update points
        if (goal1 > goal2)
            cont[team1Index].points += 3;
        else if (goal2 > goal1)
            cont[team2Index].points += 3;
        else {
            cont[team1Index].points++;
            cont[team2Index].points++;
        }
        //Update Goal Difference
        cont[team1Index].goalDiff += (goal1 - goal2);
        cont[team2Index].goalDiff += (goal2 - goal1);
        //Update Scored Goals
        cont[team1Index].scoredGoals += goal1;
        cont[team2Index].scoredGoals += goal2;

    }
}).on('close', () => {
    /* cont.forEach(item => {
         outputInfoObj(item);
     });*/
    cont.sort(customCompare);
    cont.splice(n / 2);
    //cont.sort((obj1, obj2) => obj1.teamName.localeCompare(obj2.teamName));
    cont.sort(compareByName);
    cont.forEach(item => {
        console.log(item.teamName);
    });

});

const readline = require('readline');

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

class Info {
    constructor(teamName, points, goalDiff, scoredGoals) {
        this.teamName = teamName;
        this.points = points;
        this.goalDiff = goalDiff;
        this.scoredGoals = scoredGoals;
    }

}

var outputInfoObj = function(obj){
    console.log("************************");
    console.log("teamName=%s ",obj.teamName);
    console.log("points  = %d",obj.points);
    console.log("goaldiff  = %d",obj.goalDiff);
    console.log("scoredgoals  = %d",obj.scoredGoals);
    console.log("************************");
}

var customCompare = function (obj1, obj2) {
    if (obj1.points != obj2.points)
        return obj2.points - obj1.points;

    if (obj1.goalDiff != obj2.goalDiff)
        return obj2.goalDiff - obj1.goalDiff;

    return obj2.scoredGoals - obj1.scoredGoals;
}

var n, indicator = 0,
    cont = [];

rl.on('line', (input) => {
    if (indicator == 0) {
        n = parseInt(input);
        indicator++;
    } else if (indicator <= n) {
        cont.push(new Info(input, 0, 0, 0));
        indicator++;
    } else {
        var dashIndex = input.indexOf('-');
        var spaceIndex = input.indexOf(' ');
        var colonIndex = input.indexOf(':');
        var team1Name = input.substring(0, dashIndex);
        var team2Name = input.substring(dashIndex + 1, spaceIndex);
        var goal1 = parseInt(input.substring(spaceIndex + 1, colonIndex));
        var goal2 = parseInt(input.substring(colonIndex+1));
        var team1Index = cont.findIndex(item => item.teamName == team1Name);
        var team2Index = cont.findIndex(item => item.teamName == team2Name);

        //Update points
        if (goal1 > goal2)
            cont[team1Index].points += 3;
        else if (goal2 > goal1)
            cont[team2Index].points += 3;
        else {
            cont[team1Index].points++;
            cont[team2Index].points++;
        }
        //Update Goal Difference
        cont[team1Index].goalDiff += (goal1 - goal2);
        cont[team2Index].goalDiff += (goal2 - goal1);
        //Update Scored Goals
        cont[team1Index].scoredGoals += goal1;
        cont[team2Index].scoredGoals += goal2;

    }
}).on('close', () => {
   /* cont.forEach(item => {
        outputInfoObj(item);
    });*/
    cont.sort(customCompare);
    cont.splice(n / 2);
    cont.sort((obj1, obj2) => obj1.teamName.localeCompare(obj2.teamName));
    cont.forEach(item => {
        console.log(item.teamName);
    });

});


Serge came to the school dining room and discovered that there is a big queue here. There are $$$m$$$ pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. As Serge is very tired, he asks you to compute it instead of him.Initially there are $$$n$$$ dishes with costs $$$a_1, a_2, \ldots, a_n$$$. As you already know, there are the queue of $$$m$$$ pupils who have $$$b_1, \ldots, b_m$$$ togrogs respectively (pupils are enumerated by queue order, i.e the first pupil in the queue has $$$b_1$$$ togrogs and the last one has $$$b_m$$$ togrogs)Pupils think that the most expensive dish is the most delicious one, so every pupil just buys the most expensive dish for which he has money (every dish has a single copy, so when a pupil has bought it nobody can buy it later), and if a pupil doesn't have money for any dish, he just leaves the queue (so brutal capitalism...)But money isn't a problem at all for Serge, so Serge is buying the most expensive dish if there is at least one remaining.Moreover, Serge's school has a very unstable economic situation and the costs of some dishes or number of togrogs of some pupils can change. More formally, you must process $$$q$$$ queries:  change $$$a_i$$$ to $$$x$$$. It means that the price of the $$$i$$$-th dish becomes $$$x$$$ togrogs.  change $$$b_i$$$ to $$$x$$$. It means that the $$$i$$$-th pupil in the queue has $$$x$$$ togrogs now. Nobody leaves the queue during those queries because a saleswoman is late.After every query, you must tell Serge price of the dish which he will buy if he has waited until the queue is clear, or $$$-1$$$ if there are no dishes at this point, according to rules described above.

The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 300\ 000$$$) — number of dishes and pupils respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^{6}$$$) — elements of array $$$a$$$. The third line contains $$$m$$$ integers $$$b_1, b_2, \ldots, b_{m}$$$ ($$$1 \leq b_i \leq 10^{6}$$$) — elements of array $$$b$$$. The fourth line conatins integer $$$q$$$ ($$$1 \leq q \leq 300\ 000$$$) — number of queries. Each of the following $$$q$$$ lines contains as follows:    if a query changes price of some dish, it contains $$$1$$$, and two integers $$$i$$$ and $$$x$$$ ($$$1 \leq i \leq n$$$, $$$1 \leq x \leq 10^{6}$$$), what means $$$a_i$$$ becomes $$$x$$$.  if a query changes number of togrogs of some pupil, it contains $$$2$$$, and two integers $$$i$$$ and $$$x$$$ ($$$1 \leq i \leq m$$$, $$$1 \leq x \leq 10^{6}$$$), what means $$$b_i$$$ becomes $$$x$$$.

For each of $$$q$$$ queries prints the answer as the statement describes, the answer of the $$$i$$$-th query in the $$$i$$$-th line (the price of the dish which Serge will buy or $$$-1$$$ if nothing remains)

NoteIn the first sample after the first query, there is one dish with price $$$100$$$ togrogs and one pupil with one togrog, so Serge will buy the dish with price $$$100$$$ togrogs.In the second sample after the first query, there is one dish with price one togrog and one pupil with $$$100$$$ togrogs, so Serge will get nothing.In the third sample after the first query, nobody can buy the dish with price $$$8$$$, so Serge will take it. After the second query, all dishes will be bought, after the third one the third and fifth pupils will by the first and the second dishes respectively and nobody will by the fourth one.

let globalStdin = '';
const {EOL} = require('os');
const N = 1e6;
process.stdin.on('data', i => globalStdin += i);

let globalOutputString = '';
function output(...str) {
  str.forEach(e => globalOutputString += e.toString());
}

function gettag(cur, tag) {
  cur.v += tag;
  cur.tag += tag;
}

function pushdown(cur) {
  if (cur.tag) {
    gettag(cur.L, cur.tag);
    gettag(cur.R, cur.tag);
    cur.tag = 0;
  }
}

function build(l, r) {
  let cur = {l: l, r: r, tag: 0};
  if (l == r) {
    cur.v = val[l];
  } else {
    let mid = (l + r) >> 1;
    cur.L = build(l, mid);
    cur.R = build(mid+1, r);
    cur.v = Math.max(cur.L.v, cur.R.v);
  }
  return cur;
}

function lognode(cur) {
  if (!cur) return;
  console.log(cur.l, cur.r, cur.v, cur.tag);
  lognode(cur.L);
  lognode(cur.R);
}

function modify(cur, p, v) {
  if (cur.r == p) {
    gettag(cur, v);
    return;
  }
  pushdown(cur);
  let mid = (cur.l + cur.r) >> 1;
  if (p > mid) {
    modify(cur.R, p, v);
    gettag(cur.L, v);
  } else {
    modify(cur.L, p, v);
  }
  cur.v = Math.max(cur.L.v, cur.R.v);
}

function query(cur) {
  if (cur.l == cur.r) {
    return cur.v > 0 ? cur.l : -1;
  }
  pushdown(cur);
  if (cur.R.v > 0)
    return query(cur.R);
  return query(cur.L);
}

process.stdin.on('end', async () => {
  const lines = globalStdin.split(EOL);
  [n, m] = lines[0].split(' ').map((v) => parseInt(v));
  val = new Array(N + 1).fill(0);
  a = lines[1].split(' ').map(v => parseInt(v));
  b = lines[2].split(' ').map(v => parseInt(v));
  a.forEach((v) => val[v]++);
  b.forEach((v) => val[v]--);
  for (let i = N; i; i--) {
    val[i-1] += val[i];
  }
  q = parseInt(lines[3]);
  let root = build(1, N);
  for (let i = 4; i < 4 + q; i++) {
    let [t, p, x] = lines[i].split(' ').map((v) => parseInt(v));
    p--;
    if (t == 1) {
      modify(root, a[p], -1);
      a[p] = x;
      modify(root, a[p], 1);
    } else {
      modify(root, b[p], 1);
      b[p] = x;
      modify(root, b[p], -1);
    }
    output(query(root), '\n');
  }
  console.log(globalOutputString);
});

let globalStdin = '';
const {EOL} = require('os');
const N = 10;
process.stdin.on('data', i => globalStdin += i);

let globalOutputString = '';
function output(...str) {
  str.forEach(e => globalOutputString += e.toString());
}

function gettag(cur, tag) {
  cur.v += tag;
  cur.tag += tag;
}

function pushdown(cur) {
  if (cur.tag) {
    gettag(cur.L, cur.tag);
    gettag(cur.R, cur.tag);
    cur.tag = 0;
  }
}

function build(l, r) {
  let cur = {l: l, r: r, tag: 0};
  if (l == r) {
    cur.v = val[l];
  } else {
    let mid = (l + r) >> 1;
    cur.L = build(l, mid);
    cur.R = build(mid+1, r);
    cur.v = Math.max(cur.L.v, cur.R.v);
  }
  return cur;
}

function lognode(cur) {
  if (!cur) return;
  console.log(cur.l, cur.r, cur.v, cur.tag);
  lognode(cur.L);
  lognode(cur.R);
}

function modify(cur, p, v) {
  if (cur.r == p) {
    gettag(cur, v);
    return;
  }
  pushdown(cur);
  let mid = (cur.l + cur.r) >> 1;
  if (p > mid) {
    modify(cur.R, p, v);
    gettag(cur.L, v);
  } else {
    modify(cur.L, p, v);
  }
  cur.v = Math.max(cur.L.v, cur.R.v);
}

function query(cur) {
  if (cur.l == cur.r) {
    return cur.v > 0 ? cur.l : -1;
  }
  pushdown(cur);
  if (cur.R.v > 0)
    return query(cur.R);
  return query(cur.L);
}

process.stdin.on('end', async () => {
  const lines = globalStdin.split(EOL);
  [n, m] = lines[0].split(' ').map((v) => parseInt(v));
  val = new Array(N + 1).fill(0);
  a = lines[1].split(' ').map(v => parseInt(v));
  b = lines[2].split(' ').map(v => parseInt(v));
  a.forEach((v) => val[v]++);
  b.forEach((v) => val[v]--);
  for (let i = N; i; i--) {
    val[i-1] += val[i];
  }
  q = parseInt(lines[3]);
  let root = build(1, N);
  for (let i = 4; i < 4 + q; i++) {
    let [t, p, x] = lines[i].split(' ').map((v) => parseInt(v));
    p--;
    if (t == 1) {
      modify(root, a[p], -1);
      a[p] = x;
      modify(root, a[p], 1);
    } else {
      modify(root, b[p], 1);
      b[p] = x;
      modify(root, b[p], -1);
    }
    output(query(root), '\n');
  }
  console.log(globalOutputString);
});


You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types:  Choose any array and clone it. After that there is one more copy of the chosen array.  Swap two elements from any two copies (maybe in the same copy) on any positions. You need to find the minimal number of operations needed to obtain a copy where all elements are equal.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case output a single integer — the minimal number of operations needed to create at least one copy where all elements are equal.

NoteIn the first test case all elements in the array are already equal, that's why the answer is $$$0$$$.In the second test case it is possible to create a copy of the given array. After that there will be two identical arrays:$$$[ \ 0 \ 1 \ 3 \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ 0 \ 1 \ 3 \ 3 \ 7 \ 0 \ ]$$$After that we can swap elements in a way so all zeroes are in one array:$$$[ \ 0 \ \underline{0} \ \underline{0} \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ \underline{1} \ 1 \ 3 \ 3 \ 7 \ \underline{3} \ ]$$$Now let's create a copy of the first array:$$$[ \ 0 \ 0 \ 0 \ 3 \ 7 \ 0 \ ]$$$, $$$[ \ 0 \ 0 \ 0 \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ 1 \ 1 \ 3 \ 3 \ 7 \ 3 \ ]$$$Let's swap elements in the first two copies:$$$[ \ 0 \ 0 \ 0 \ \underline{0} \ \underline{0} \ 0 \ ]$$$, $$$[ \ \underline{3} \ \underline{7} \ 0 \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ 1 \ 1 \ 3 \ 3 \ 7 \ 3 \ ]$$$.Finally, we made a copy where all elements are equal and made $$$6$$$ operations.It can be proven that no fewer operations are enough.

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

void (function main() {
  const _ = Number(inputs[0])
  let res = []
  for (let __ = 0; __ < _; __++) {
    let n = Number(inputs[__ * 2 + 1])
    const data = inputs[__ * 2 + 2].trim().split(' ')
    let map = new Map()
    for (let num of data) {
      if (!map.has(num)) map.set(num, 0)
      map.set(num, map.get(num) + 1)
    }

    let max = [...map.values()].sort((a, b) => b - a)[0]
    n -= max
    let ans = 0

    while (n > 0) {
      ans++
      ans += Math.min(max, n)
      n -= max
      max *= 2
    }
    res.push(ans)
  }
  console.log(res.join('\n'))
})()

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var a = lines[i].split(' ').map(Number);
            var m = new Map();
            var max = 0;
            for(j = 0; j < n; j++){
                if(m.has(a[j])){
                    var temp = m.get(a[j]);
                    temp++;
                    m.set(a[j], temp);
                }else{
                    m.set(a[j], 1);
                }
            }
            for(var [key, value] of m){
                if(value > max){
                    max = value;
                }
            }
            var ans = 0;
            while(max < n){
                var c = Math.min(n - max, max);
                ans += 1 + c;
                max += c;
            }
            console.log(ans);
        }
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    let n = parseInt(readLine());
    let arr = readLine().split(" ");
    counter = 0;
    return solution(arr)
}
function solution(arr) {
    if (arr.length == 1) {
        return 0;
    }
    let same = true;
    for (let i = 0; i < arr.length; i++) {
        if (arr[0] != arr[i]) same = false;
    }
    if (same) {
        return 0;
    }
    let maxRep = -1;
    let map = new Map();
    for (const val of arr) {
        if (map.has(val)) map.set(val, map.get(val) + 1);
        else map.set(val, 1);
    }
    maxRep = Array.from(map.values()).sort((a, b) => a - b);
    maxRep = maxRep[maxRep.length - 1];
    let cnt = 0;
    while (maxRep !== arr.length) {
        let temp = Math.min(Math.abs(arr.length - maxRep), maxRep);
        cnt += 1 + temp
        maxRep += temp
    }
    return cnt;
}

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

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const MOD = 1e9+7;

class SegmTree {

}

const calc = (n, arr)=>{
  let cnt = new Map();
  for (let a of arr)
    cnt.set(a, (cnt.get(a)||0)+1)
  let max = 0;
  for (let [k, v] of cnt){
    if (v>max){
      max = v;
    }
  }
  let ans = 0;
  let eq = max;
  let potential = 0;
  while (eq<n){
    if (potential==0){
      ans++;
      potential = eq;
    }
    potential--;
    ans++;
    eq++;
  }

  return ans;
};

function main() {
    let T = +readline()
    while (T--){
      let [n] = ra();
      let arr = ra();
      l('ans')
      print(calc(n, arr));
    }
}

E.calc = calc;

var total = +readline();
while (total--) {
    var len = +readline();
    var map = new Map();
    readline().split(" ").map(Number).forEach(function (x) {
        if (map.has(x)) {
            map.set(x, map.get(x) + 1);
        } else {
            map.set(x, 1);
        }
    });
    var anst = 0;
    var val = -1;
    map.forEach(function (v, k) {
        if (v > val) {
            val = v;
            anst = k;
        }
    });
    var longest = val;
    var ans = 0;
    while (len > longest) {
        ans += 1 + longest;
        longest += longest;
    }
    ans += len - longest;
    print(ans);
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

void (function main() {
  const _ = Number(inputs[0])
  let res = []
  for (let __ = 0; __ < _; __++) {
    let n = Number(inputs[__ * 2 + 1])
    const data = inputs[__ * 2 + 2].trim().split(' ').map(Number)
    const h = new Array(n).fill(-1),
      e = [],
      ne = [],
      d = new Array(n).fill(0)
    let idx = 0
    const add = (i, j) => {
      ;(e[idx] = j), (ne[idx] = h[i]), (h[i] = idx++), d[j]++
    }
    for (let i = 2; i <= n; i++) {
      add(data[i - 2] - 1, i - 1)
    }
    const queue = [0]
    const g = new Array(n).fill(0).map(() => [])
    for (let i of queue) {
      for (let k = h[i]; k !== -1; k = ne[k]) {
        const j = e[k]
        if (--d[j] === 0) {
          g[i].push(j)
          queue.push(j)
        }
      }
    }
    let hasSon = 0,
      maxSon = 0
    for (let children of g) {
      if (children.length) hasSon++
      maxSon = Math.max(maxSon, children.length)
    }

    maxSon -= hasSon + 1
    let ans = 1 + hasSon + Math.ceil(Math.max(maxSon, 0) / 2)
    res.push(ans)
  }

  console.log(res.join('\n'))
})()

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

void (function main() {
  const _ = Number(inputs[0])
  let res = []
  for (let __ = 0; __ < _; __++) {
    let n = Number(inputs[__ * 2 + 1])
    const data = inputs[__ * 2 + 2].split(' ')
    let map = new Map()
    for (let num of data) {
      map.set(num, (map.get(num) || 0) + 1)
    }

    let max = [...map.values()].sort((a, b) => b - a)[0]
    n -= max
    let ans = 0
    while (n > 0) {
      ans++
      ans += Math.min(max, n)
      n -= max
      max *= 2
    }
    res.push(ans)
  }
  console.log(res.join('\n'))
})()


Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.There are $$$n$$$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $$$i$$$-th position. Thus each of $$$n$$$ positions should contain exactly one flower: a rose or a lily.She knows that exactly $$$m$$$ people will visit this exhibition. The $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to $$$r_i$$$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n, m\leq 10^3$$$) — the number of flowers and visitors respectively. Each of the next $$$m$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1\leq l_i\leq r_i\leq n$$$), meaning that $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to $$$r_i$$$ inclusive.

Print the string of $$$n$$$ characters. The $$$i$$$-th symbol should be «0» if you want to put a rose in the $$$i$$$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.

NoteIn the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;  in the segment $$$[1\ldots3]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$;  in the segment $$$[2\ldots4]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$;  in the segment $$$[2\ldots5]$$$, there are two roses and two lilies, so the beauty is equal to $$$2\cdot 2=4$$$. The total beauty is equal to $$$2+2+4=8$$$.In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;  in the segment $$$[5\ldots6]$$$, there are one rose and one lily, so the beauty is equal to $$$1\cdot 1=1$$$;  in the segment $$$[1\ldots4]$$$, there are two roses and two lilies, so the beauty is equal to $$$2\cdot 2=4$$$;  in the segment $$$[4\ldots6]$$$, there are two roses and one lily, so the beauty is equal to $$$2\cdot 1=2$$$. The total beauty is equal to $$$1+4+2=7$$$.

var result = '1';
var i = 1;
const numbers = readline().split(' ').map(function(v){return +v;});
const n = numbers[0];

function first() {
    while (result.length < n) {
        i = Number(!i);
        result += i;
    }
}

first();

print(result);

const numbers = readline().split(' ').map(function(v){return +v;});
const n = numbers[0];

var result = '1';
var i = 1;
while (result.length < n) {
    i = Number(!i);
    result += i;
}

print(result);


You have a connected undirected graph made of $$$n$$$ nodes and $$$m$$$ edges. The $$$i$$$-th node has a value $$$v_i$$$ and a target value $$$t_i$$$.In an operation, you can choose an edge $$$(i, j)$$$ and add $$$k$$$ to both $$$v_i$$$ and $$$v_j$$$, where $$$k$$$ can be any integer. In particular, $$$k$$$ can be negative.Your task to determine if it is possible that by doing some finite number of operations (possibly zero), you can achieve for every node $$$i$$$, $$$v_i = t_i$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$), the number of test cases. Then the test cases follow. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$2 \leq n \leq 2\cdot 10^5$$$, $$$n-1\leq m\leq \min(2\cdot 10^5, \frac{n(n-1)}{2})$$$) — the number of nodes and edges respectively. The second line contains $$$n$$$ integers $$$v_1\ldots, v_n$$$ ($$$-10^9 \leq v_i \leq 10^9$$$) — initial values of nodes. The third line contains $$$n$$$ integers $$$t_1\ldots, t_n$$$ ($$$-10^9 \leq t_i \leq 10^9$$$) — target values of nodes. Each of the next $$$m$$$ lines contains two integers $$$i$$$ and $$$j$$$ representing an edge between node $$$i$$$ and node $$$j$$$ ($$$1 \leq i, j \leq n$$$, $$$i\ne j$$$). It is guaranteed that the graph is connected and there is at most one edge between the same pair of nodes. It is guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$2 \cdot 10^5$$$ and the sum of $$$m$$$ over all testcases does not exceed $$$2 \cdot 10^5$$$.

For each test case, if it is possible for every node to reach its target after some number of operations, print "YES". Otherwise, print "NO".

NoteHere is a visualization of the first test case (the orange values denote the initial values and the blue ones the desired values):   One possible order of operations to obtain the desired values for each node is the following:  Operation $$$1$$$: Add $$$2$$$ to nodes $$$2$$$ and $$$3$$$.  Operation $$$2$$$: Add $$$-2$$$ to nodes $$$1$$$ and $$$4$$$.  Operation $$$3$$$: Add $$$6$$$ to nodes $$$3$$$ and $$$4$$$. Now we can see that in total we added $$$-2$$$ to node $$$1$$$, $$$2$$$ to node $$$2$$$, $$$8$$$ to node $$$3$$$ and $$$4$$$ to node $$$4$$$ which brings each node exactly to it's desired value.For the graph from the second test case it's impossible to get the target values.

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var [v, e] = lines[l++].split(' ').map(Number)
        var vs = lines[l++].split(' ').map(Number)
        var ts = lines[l++].split(' ').map(Number)
        var edges = lines.slice(l, l + e).map(str => str.split(' ').map(Number))
        console.log(solve(v, e, vs, ts, edges) ? 'YES' : 'NO');
        l += e
    }
});

function solve(v, e, vs, ts, edges) {
    const vp = vs.reduce((s, x) => s + x, 0) & 1
    const tp = ts.reduce((s, x) => s + x, 0) & 1
    if (vp !== tp) return false

    const adj = {}
    edges.forEach(([a, b]) => {
        a--
        b--
        adj[a] = adj[a] || []
        adj[b] = adj[b] || []
        adj[a].push(b)
        adj[b].push(a)
    })

    const [bip, s] = bipartite(adj, v)
    // console.log(bip, s)
    if (!bip) return true

    let s0 = 0
    let s1 = 0
    s.forEach((g, i) => {
        if (g) {
            s1 += ts[i] - vs[i]
        } else {
            s0 += ts[i] - vs[i]
        }
    })
    return s0 === s1
}

function bipartite(adj, n) {
    let bip = true;
    const s = [];

    for(let i = 0;i < n;i++)
        s[i] = -1;

    const q = [];
    for(let i = 0;i < n;i++){
        if(s[i] != -1)continue;

        // q.push(i);
        s[i] = 0;

        // while(q.length){
        //     const v = q.shift();

        //     (adj[v] || []).some(u => {
        //         if(s[u] == -1){
        //             s[u] = s[v] ^ 1;
        //             q.push(u);
        //         }else{
        //             bip &= s[u] != s[v];
        //             if (!bip) return true
        //         }
        //     })
        //     if (!bip) return [bip, s];
        // }
        bip &= dfs(adj, i, s)
        if (!bip) return [bip, s]
    }
    return [bip, s];
}
function dfs(adj, r, s) {
    const stack = [[r, 0]]
    while (stack.length) {
        const [u, i] = stack[stack.length - 1]
        // visited[u] = 1

        const nb = adj[u] || []
        if (i < nb.length) {
            stack[stack.length - 1][1]++
            const v = nb[i]
            // console.log(u, v)
            if (s[v] == -1){
                s[v] = s[u] ^ 1;
                stack.push([v, 0]);
            } else if (s[u] === s[v]){
                // bip &= s[u] != s[v];
                // if (!bip) return
                return false
            }
            // if (!visited[v]) {
            //     stack.push([v, 0])
            // }
        } else {
            stack.pop()
        }
    }
    return true
}


Today at the lesson of mathematics, Petya learns about the digital root.The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached. Let's denote the digital root of $$$x$$$ as $$$S(x)$$$. Then $$$S(5)=5$$$, $$$S(38)=S(3+8=11)=S(1+1=2)=2$$$, $$$S(10)=S(1+0=1)=1$$$.As a homework Petya got $$$n$$$ tasks of the form: find $$$k$$$-th positive number whose digital root is $$$x$$$.Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all $$$n$$$ tasks from Petya's homework.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$) — the number of tasks in Petya's homework. The next $$$n$$$ lines contain two integers $$$k_i$$$ ($$$1 \le k_i \le 10^{12}$$$) and $$$x_i$$$ ($$$1 \le x_i \le 9$$$) — $$$i$$$-th Petya's task in which you need to find a $$$k_i$$$-th positive number, the digital root of which is $$$x_i$$$.

Output $$$n$$$ lines, $$$i$$$-th line should contain a single integer — the answer to the $$$i$$$-th problem.

var qq = readline().split(" ").map(function(x) { return parseInt(x); });
//var numbers = prompt("Enter data: ").split(" ").map(function(x) { return parseInt(x); });   // Chrome run

var T = qq[0];
for (var i=0; i<T; i++) {
	qq = readline().split(" ").map(function(x) { return parseInt(x); });
	var K = qq[0];
	var DIG = qq[1];
	var res = (K-1)*9 + DIG;
	write(res,"\n");
}

var n = parseInt(readline(), 10);
for(var i=1;i<=n;i++)
{
    var seq = readline().split(" ").map(function(x) { return parseInt(x); });
    var k=seq[0],x=seq[1];
    if(x==9)
        print(k*9);
    else
        print((k-1)*9+x);
}

'use strict';
const io = (function() {
  process.stdin.resume(); process.stdin.setEncoding('utf-8');
  let inputString = '', currentLine = 0, curTok = 0, input = [];
  function _check() { if (currentLine >= input.length) throw 'EOF!'; }
  process.stdin.on('data', data => { inputString += data; });
  process.stdin.on('end', _ => {
      for (const i of inputString.split('\n')) { input.push(i.split(' ')); }
      main();
  });
  function nextLine() {
    _check();
    const ret = input[currentLine++].slice(curTok).join(' ');
    curTok = 0;
    return ret;
  }
  function next() {
    _check();
    while (curTok == input[currentLine].length) {
      currentLine++;
      curTok = 0;
      _check()
    }
    return input[currentLine][curTok++];
  }
  function nextInt() { return parseInt(next()); }
  return {
    nextLine: nextLine,
    next: next,
    nextInt: nextInt,
  };
})();

const deal = () => {
  let k = io.nextInt();
  let x = io.nextInt();
  let ans = x + (k-1)*9;
  console.log(ans);
};

function main() {
  const n = io.nextInt();
  for (const i of Array(n).keys()) {
    deal();
  }
}

(function() {
    var n = +readline();
    var r = '';
    for(var i = 0; i < n; i++) {
        var l = readline().split(' ');
        var k = +l[0];
        var x = +l[1];

        var d = 0;
        var arr = [x];
        var index = 0;

        while(arr.length < k) {
            for(var j = 0; j <=  arr.length; j++) {
                var newV  = arr[j] - d;
                if(newV != x && newV >= 0 && newV < 10) {
                    arr.push(+(d.toString() + newV));
                }
            }
            d++;
        }
        print(arr);
        r += arr[k - 1] + '\n';
    }
    print(r);

   // 2 11 20 29 38
   // 1 10 19 28 30
}());

(function() {
    var n = +readline();
    var r = '';
    for(var i = 0; i < n; i++) {
        var l = readline().split(' ');
        var k = +l[0];
        var x = +l[1];

        var d = 0;
        var arr = [x];
        var index = 0;

        while(arr.length < k) {
            for(var j = 0; j <=  arr.length; j++) {
                var newV  = arr[j] - d;
                if(newV != x && newV >= 0 && newV < 10) {
                    arr.push(+(d.toString() + newV));
                }
            }
            d++;
        }
        r += arr[k - 1] + '\n';
    }
    print(r);

   // 2 11 20 29 38
   // 1 10 19 28 30
}());

(function() {
    var q = +readline();
    var res = '';
    for(var i = 0; i < q; i++) {
        var t = readline().split(' ');
        res += t[1] + '\n'
    }
    print(res);
}());


I, Fischl, Prinzessin der Verurteilung, descend upon this land by the call of fate an — Oh, you are also a traveler from another world? Very well, I grant you permission to travel with me.It is no surprise Fischl speaks with a strange choice of words. However, this time, not even Oz, her raven friend, can interpret her expressions! Maybe you can help us understand what this young princess is saying?You are given a string of $$$n$$$ lowercase Latin letters, the word that Fischl just spoke. You think that the MEX of this string may help you find the meaning behind this message. The MEX of the string is defined as the shortest string that doesn't appear as a contiguous substring in the input. If multiple strings exist, the lexicographically smallest one is considered the MEX. Note that the empty substring does NOT count as a valid MEX.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:   $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$. A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.Find out what the MEX of the string is!

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the length of the word. The second line for each test case contains a single string of $$$n$$$ lowercase Latin letters. The sum of $$$n$$$ over all test cases will not exceed $$$1000$$$.

For each test case, output the MEX of the string on a new line.

3
28
qaabzwsxedcrfvtgbyhnujmiklop
13
cleanairactbd
10
aannttoonn

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim().split("");
    let ans;
    let arr = new Array(26)
      .fill(97)
      .map((cur, ind) => String.fromCharCode(cur + ind));
    const subStr = (str, find) => {
      let flag = false;
      for (let i = 0; i < n; i++) {
        if (str[i] === find[0]) {
          flag = true;
          let j = i,
            k = 0;
          while (k < find.length) {
            if (find[k] !== str[j]) flag = false;
            k++;
            j++;
          }
          if (flag) {
            return false;
          }
        }
      }
      ans = find;
      return true;
    };
    const isPr = (str, find) => {
      let flag = true;
      for (let i = 0; i < 26; i++) {
        let k = find + arr[i];
        if (subStr(str, k)) return true;
      }
      return false;
    };
    if (isPr(str, "")) console.log(ans);
    else {
      let check = "";
      for (let i = 0; i < 27; i++) {
        let flag = false;
        for (let j = 0; j < 26; j++) {
          if (isPr(str, check + arr[j])) {
            flag = true;
            break;
          }
        }
        if (flag) break;
        check = arr[i];
      }
      console.log(ans);
    }
  }
};
solve();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main()
});

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

function main() {
  let testCases = readline()
  while(testCases--)
    solve()
}

// function to solve problems
function solve (){
  let n = readline()
  let str = readline()

  let substr = 'a',
    ansFound = 0
  while (ansFound != -1) {
    ansFound = str.indexOf(substr)
    if (ansFound != -1) {
      substr = getNextSubstring(substr)
    }
  }
  // console.log('==========\nANS = ', substr)
  console.log(substr)
}

function getNextSubstring (substr) {
  if (!substr) return 'a'
  // console.log('substr:', substr)
  let index = substr.length - 1,
    lastChar = substr[index]
    // console.log('index:', index)
    // console.log('lastChar:', lastChar)
  if (substr.charCodeAt(index) == 'z'.charCodeAt(0)) {
    // console.log('Inside if')
    return getNextSubstring(substr.substring(0, index)) + 'a'
  } else {
    return substr.substring(0, index) + String.fromCharCode(lastChar.charCodeAt(0) + 1)
  }
}

function sortAscending(a, b) {
  return a[0] - b[0]
}
// String.prototype.replaceAt = function (index, replacement) {
//   return this.substring(0, index) + replacement + this.substring(index + replacement.length)
// }

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}
var all = [];
var acode = 'a'.charCodeAt(0);
var zcode = 'z'.codePointAt(0);
var count = zcode - acode + 1;
for (var i = acode; i <= zcode; i++) {
   all.push(String.fromCharCode(i));
}
for (var i = 0; i < count; i++) {
   for (var j = 0; j < count; j++) {
      all.push(all[i] + all[j]);
   }
}
for (var i = 0; i < count; i++) {
   for (var j = 0; j < count; j++) {
      for (var k = 0; k < count; k++) {
         all.push(all[i] + all[j] + all[k]);
      }
   }
}

function solve() {
   read();
   var str = read();
   for (var i = 0; i < all.length; i++) {
      if (str.indexOf(all[i]) === -1) {
         write(all[i]);
         return;
      }
   }
}

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

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var search = 'a'
    var len = +readline();
    var word = readline();
    while (word.indexOf(search) > -1) {
      search = updateSearch(search);
    }
    print(search);
  }
}

function updateSearch(str) {
  var result = '';
  var lastNotZ = -1;
  for (var k = str.length - 1; k > -1; k--) {
    if (str[k] !== 'z') {
      lastNotZ = k;
      break;
    }
  }
  if (lastNotZ > -1) {
    result = str.slice(0, lastNotZ) +
      String.fromCharCode(str.charCodeAt(lastNotZ) + 1);
    for (var k = lastNotZ + 1; k < str.length; k++) {
      result += 'a';
    }
  } else {
    for (var k = 0; k < str.length + 1; k++) {
      result += 'a';
    }
  }
  return result;
}
main();

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var search = 'a'
    var len = +readline();
    var word = readline();
    while (word.indexOf(search) > -1) {
      search = updateSearch(search);
    }
    print(search);
  }
}

function updateSearch(str) {
  var result = '';
  var lastNotZ = -1;
  for (var k = str.length - 1; k > -1; k--) {
    if (str[k] !== 'z') {
      lastNotZ = k;
      break;
    }
  }
  if (lastNotZ > -1) {
    result = str.slice(0, lastNotZ) +
      String.fromCharCode(str.charCodeAt(lastNotZ) + 1) +
      str.slice(lastNotZ + 1);
  } else {
    for (var k = 0; k < str.length + 1; k++) {
      result += 'a';
    }
  }
  return result;
}
main();


There are $$$n$$$ participants in a competition, participant $$$i$$$ having a strength of $$$s_i$$$. Every participant wonders how much of an advantage they have over the other best participant. In other words, each participant $$$i$$$ wants to know the difference between $$$s_i$$$ and $$$s_j$$$, where $$$j$$$ is the strongest participant in the competition, not counting $$$i$$$ (a difference can be negative).So, they ask you for your help! For each $$$i$$$ ($$$1 \leq i \leq n$$$) output the difference between $$$s_i$$$ and the maximum strength of any participant other than participant $$$i$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The descriptions of the test cases follow. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2\cdot10^5$$$) — the length of the array. The following line contains $$$n$$$ space-separated positive integers $$$s_1$$$, $$$s_2$$$, ..., $$$s_n$$$ ($$$1 \leq s_i \leq 10^9$$$) — the strengths of the participants. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, output $$$n$$$ space-separated integers. For each $$$i$$$ ($$$1 \leq i \leq n$$$) output the difference between $$$s_i$$$ and the maximum strength of any other participant.

NoteFor the first test case: The first participant has a strength of $$$4$$$ and the largest strength of a participant different from the first one is $$$7$$$, so the answer for the first participant is $$$4 - 7 = -3$$$.  The second participant has a strength of $$$7$$$ and the largest strength of a participant different from the second one is $$$5$$$, so the answer for the second participant is $$$7 - 5 = 2$$$. The third participant has a strength of $$$3$$$ and the largest strength of a participant different from the third one is $$$7$$$, so the answer for the third participant is $$$3 - 7 = -4$$$. The fourth participant has a strength of $$$5$$$ and the largest strength of a participant different from the fourth one is $$$7$$$, so the answer for the fourth participant is $$$5 - 7 = -2$$$.

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for(let i = 0; i<testNumbers; i++){
        solve(parseInt(readline()), readline().split(" ").map(x=>parseInt(x)));
    }
}

function solve(size, input){
    let max=0, secondMax = 0;
    for (let i = 0; i<size; i++){
        if(input[i] >= max){
            secondMax = max;
            max = input[i];
        }

        if(secondMax <= input[i] && input[i] !== max){
            secondMax = input[i]
        }
    }
    let ans = "";
    for (let j = 0; j<size; j++){
        if(input[j] !== max){
            ans += `${input[j] - max}`;
        }else{
            ans += `${max-secondMax}`;
        }

        if(j !== size-1){
            ans += ' ';
        }
    }
    console.log(ans)
}

let buf='';

process.stdin.on('readable', function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end', function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[2*_-1]);
        let a=line[2*_].split(' ').map(x=>{return parseInt(x)});
        let b=[];
        for(let x of a) b.push(x);
        b.sort(function(a,b){
            return a-b;
        });
        // console.log(b);
        let ans='';
        for(let i=0;i<n;i++)
        {
            if(a[i]===b[n-1]) ans+=(a[i]-b[n-2])+' ';
            else ans+=(a[i]-b[n-1])+' ';
        }
        console.log(ans);
    }
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    //let mod = 10**9+7
    loopwhile:
    while(t--)
    {

        let n = parseInt(readLine());

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

        let max = Math.max(...s)
        let index = s.indexOf(max)
        //console.log("index " + index)
        ///console.log("s.slice() " + s.slice())
        let copy = s.slice()
        copy.splice(index,1)
        //console.log("copy " +copy)
        let secondmax = Math.max(...copy)
        //console.log("secondmax " + secondmax)

        let line=""
        s[index] += max - secondmax
        for(let i=0;i<n;i++)
        {
            line+=(s[i]-max) + " "
        }
        console.log(line.trim())
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const testCases = Number(readline());
    for (let i = 0; i < testCases; i++) {
        let len = Number(readline());
        let arr = readline().split(" ").map(elem => Number(elem))
        console.log(calculateAdvantage(len, arr).join(" "))
    }
}

function calculateAdvantage(len, arr) {
    let arrcopy = [...arr]
    arrcopy.sort((a, b) => a - b)
    console.log()
    let max = arrcopy[len - 1]
    let ans = []
    for (let i = 0; i < len; i++) {
        if (arr[i] === max) {
            ans.push(max - arrcopy[len - 2])
        } else
            ans.push(arr[i] - max)
    }
    return ans
}

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline();
	var a = readline().split(" ").map(w => parseInt(w));
	var b = [...a].sort((x,y) => y-x)
	var ans = []
	for(var i=0;i<n;i++) {
		if(a[i] == b[0]) ans[i] = a[i]-b[1];
		else ans[i] = a[i]-b[0]
	}
	console.log(ans.join(" "))
}

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

let lines = []

const createReadLine = () => {
  i = 0;
  return () => lines[i++]
}
const int = (num, radix=10) => parseInt(num, radix)

rl.on('line', line => lines.push(line))

rl.on("close", () => {
  const readLine = createReadLine();
  // const alphabet = "abcdefghijklmnopqrstuvwxyz".toUpperCase();
  let t = int(readLine());
  let alphabet = "abcdefghijklmnopqrstuvwxyz"
  while (t--) {
    let n = int(readLine());
    let arr = readLine().split(' ').map(a => int(a))
    // let maxx = Math.max(arr)
    let maxx = 0
    let prevmaxx = 0
    let cnt = -1
    let ans = ''
    for (let i = 0; i < n; i++) {
      if (arr[i] >= maxx) {
        prevmaxx = maxx
        maxx = arr[i]
      }
      else if (arr[i] > prevmaxx) {
        prevmaxx = arr[i]
      }
    }

    for (let i = 0; i < n; i++) {
      cnt += arr[i] == maxx ? 1 : 0
    }

    for (let i = 0; i < n; i++) {
      if (arr[i] == maxx) {
        if (!cnt) {
          ans += `${(arr[i] - prevmaxx)} `
        } else {
          ans += `0 `
        }
      }
      else {
        ans += `${(arr[i] - maxx)} `
      }
    }
    console.log(ans)
  }
});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var alpha = "abcdefghijklmnopqrstuvwxyz";
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var map = getCountMap(list);
		var tmp = Array.from(new Set(makeClone(list)));
		tmp.sort(function(a,b){
			return b - a;
		});
		var max = tmp[0];
		var nx = tmp[0];
		if(tmp.length > 1){
			nx = tmp[1];
		}
		var output = new Array(N);
		for(var i = 0; i < N; i++){
			if(list[i] == max){
				if(map[list[i]] > 1){
					output[i] = 0;
				}else{
					output[i] = list[i] - nx;
				}
			}else{
				output[i] = list[i] - max;
			}
		}
		myout(myconv(output, 8));
	}
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const sorted = arr.map((x, i) => [x, i])
        .sort((a, b) => b[0] - a[0])
    const a = sorted[0][0]
    const b = sorted[1][0]
    const r = Array(n)
    // console.log(sorted, a)
    for (let i = 0; i < sorted.length; i++) {
        const [x, j] = sorted[i]
        if (x === a) {
            r[j] = a - b
        } else {
            r[j] = x - a
        }
    }
    return r.join(' ')
}

var t = +readline();

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

      var nums = [];
    var arr = readline()
    var arr = readline().split(' ').map((t) => +t)

    print(alphabet(arr).join(' '))

}

function alphabet(arr){

 var res = [];
    var max = Math.max(...arr);
    var count = 0;
    var second = -Infinity;
    for(var each of arr){
        if (max == each){
            count++;
        }else {
            second = Math.max(second,each);
        }
    };
    //
    if (count >= 2){
        for(var num of arr){
            res.push(num - max);
        }
    }else {
        for(var num of arr){
            if (num == max){
                res.push(num-second)
            }else {
                res.push(num-max)
            }
        }
    }

    return res;
}

t = +readline()

while(t--) {
    readline()
    s = readline().split(' ').map(value => +value)

    maxFirst = Math.max(...s)
    foundIndex = s.findIndex(value => value === maxFirst)
    maxSecond = Math.max(...[...s.slice(0, foundIndex), ...s.slice(foundIndex + 1, s.length)])

    difference = s.map((value, index) => {
        if (index === foundIndex) {
            return value - maxSecond
        }

        return value - maxFirst
    })

    print(difference.join(' '))
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for(let i = 0; i<testNumbers; i++){
        solve(parseInt(readline()), readline().split(" ").map(x=>parseInt(x)));
    }
}

function solve(size, input){
    let max=0, secondMax = 0;
    for (let i = 0; i<size; i++){
        if(input[i] >= max){
            secondMax = max;
            max = input[i];
        }
    }
    let ans = "";
    for (let j = 0; j<size; j++){
        if(input[j] !== max){
            ans += `${input[j] - max}`;
        }else{
            ans += `${max-secondMax}`;
        }

        if(j !== size-1){
            ans += ' ';
        }
    }
    console.log(ans)
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for(let i = 0; i<testNumbers; i++){
        solve(parseInt(readline()), readline().split(" ").map(x=>parseInt(x)));
    }
}

function solve(size, input){
    let max=0, secondMax = 0;
    for (let i = 0; i<size; i++){
        if(input[i] >= max){
            secondMax = max;
            max = input[i];
        }
    }
    let ans = "";
    for (let j = 0; j<size; j++){
        if(input[j] !== max){
            ans += `${input[j] - max}`;
        }else{
            ans += `${max-secondMax}`;
        }

        if(j !== size-1){
            ans += ' ';
        }
    }
}

let buf='';

process.stdin.on('readable', function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end', function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[2*_-1]);
        let a=line[2*_].split(' ').map(x=>{return parseInt(x)});
        let b=[];
        for(let x of a) b.push(x);
        // console.log(b);
        b.sort();
        let ans='';
        for(let i=0;i<n;i++)
        {
            if(a[i]===b[n-1]) ans+=(a[i]-b[n-2])+' ';
            else ans+=(a[i]-b[n-1])+' ';
        }
        console.log(ans);
    }
})

var t = +readline();

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

      var nums = [];
    var arr = readline()
    var arr = readline().split(' ').map((t) => +t)

    print(alphabet(arr))

}

function alphabet(arr){

 var res = [];
    var max = Math.max(...arr);
    var count = 0;
    var second = -Infinity;
    for(var each of arr){
        if (max == each){
            count++;
        }else {
            second = Math.max(second,each);
        }
    };
    //
    if (count >= 2){
        for(var num of arr){
            res.push(num - max);
        }
    }else {
        for(var num of arr){
            if (num == max){
                res.push(num-second)
            }else {
                res.push(num-max)
            }
        }
    }

    return res;
}

t = +readline()

while(t--) {
    readline()
    s = readline().split(' ').map(value => +value)

    maxFirst = Math.max(...s)
    foundIndex = s.findIndex(value => value === maxFirst)
    maxSecond = Math.max(...[...s.slice(0, foundIndex), ...s.slice(foundIndex + 1, s.length)])

    difference = s.map((value, index) => {
        if (index === foundIndex) {
            return value - maxSecond
        }

        return value - maxFirst
    })

    print(difference)
}


In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced.

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Print the k-th pronounced identifier (assume that the numeration starts from 1).

NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.

var firstLine = readline().split(' ');

var IDs = readline().split(' ');

var n = +firstLine[0];
var k = +firstLine[1];

var x = 0;
var max = 0;

for(var i = 1; i <= n; i ++) {
	x += i;
	if(x >= k) {
		max = i;
		break;
	}
}

var s = k - ((max*(max-1))/2);

print(IDs[s-1]);

var nk = readline().trim().split(' ').map((_x)=>parseInt(_x));
var n=nk[0],k=nk[1];
var t = readline().trim().split(' ').map((_x)=>parseInt(_x));

var m=0;
k--;
while(true){
    if(k>=(m*(m+1)/2) && k<((m+1)*(m+2)/2)){
        break;
    }
    m++;
}
var i = k-m*(m+1)/2

print(t[i]);

var nk = readline().split(' ').map(Number);
var robots = readline().split(' ').map(Number);

var n = nk[0];
var k = nk[1];

var array = [];
var m = 0;

for (var i = 0; i < n; i++) {
	m += i + 1;
	array[i] = m;
}

var index = 0;

for (var i = 0; i < array.length; i++) {
	if (k == 1) {
		index = 1;
		break;
	} else if (k <= array[i]) {
		index = (array[i] - array[i - 1]) - (array[i] - k);
		break;
	}
}

print(robots[index - 1]);

var meta = readline().split(" ");
    ids = readline().split(" ");

    k = meta[1];

var i = k, n = 1;

while (i > n) {
    i -= n++;
}

print(ids[i-1]);

var nk = readline().split(' ').map(Number);
var n = nk[0];
var k = nk[1];
var id = readline().split(' ').map(Number);

var s = Math.floor(Math.sqrt(k * 2));
while ((s + 1) * s / 2 >= k)
    s--;

print(id[k - 1 - (s + 1) * s / 2]);

var be = readline().split(' ');

var n = be[0];
var k = be[1];

var x = Math.floor(Math.sqrt(1/4+2*k) - 1/2);
var y = k - x*(x+1)/2;
if(y<=0) y = x;

print(readline().split(' ')[y-1]);

var nk = readline().split(' ').map(Number);
var robots = readline().split(' ').map(Number);

var n = nk[0];
var k = nk[1];

var array = [];
var m = 0;

for (var i = 0; i < n; i++) {
	m += i + 1;
	array[i] = m;
}

print(array);

var index = 0;

for (var i = 0; i < array.length; i++) {
	if (k == 1) {
		index = 1;
		break;
	} else if (k <= array[i]) {
		index = (array[i] - array[i - 1]) - (array[i] - k);
		break;
	}
}

print(robots[index - 1]);

var n = readline();
var k = readline();

var x = Math.floor(Math.sqrt(1+4*k)/2 - 1/2);
var y = k - x*(x+1);

for(var i=0; i<y; i++){
    var id = readline();
}
print(id);

var be = readline().split(' ');

var n = be[0];
var k = be[1];

var x = Math.floor(Math.sqrt(1+4*k)/2 - 1/2);
var y = k - x*(x+1)/2;
if(y===0) y = n;

print(readline().split(' ')[y-1]);

var be = readline().split(' ');

var n = be[0];
var k = be[1];

var x = Math.floor(Math.sqrt(1/4+2*k) - 1/2);
var y = k - x*(x+1)/2;
if(y===0) y = n;

print(readline().split(' ')[y-1]);

var n = readline();
var k = readline();

var x = Math.floor(Math.sqrt(1+4*k)/2 - 1/2);
var y = k - x*(x+1);

var id;
for(var i=0; i<y; i++){
    id = readline();
}
print(id);

var be = readline().split(' ');

var n = be[0];
var k = be[1];

var x = Math.floor(Math.sqrt(1+4*k)/2 - 1/2);
var y = k - x*(x+1);

print(readline().split(' ')[y-1]);