link: https://www.codechef.com/CU1PP0009/problems/DISABLEDKING

Chef loves Chess and has thus invented a new piece named “Disabled King”.

Let’s denote the cell at the intersection of the ii-th column from the left and jj-th row from the top by (i,j)(i,j).

If he is currently in cell (x,y)(x,y), the disabled king can move to the following positions in one move (provided that he remains in the chessboard):

  • (x,y+1)(x,y+1)
  • (x,y−1)(x,y−1)
  • (x+1,y+1)(x+1,y+1)
  • (x+1,y−1)(x+1,y−1)
  • (x−1,y+1)(x−1,y+1)
  • (x−1,y−1)(x−1,y−1)

In short, the Disabled King cannot move horizontally.

In an N×NN×N chessboard, the Disabled King is currently situated at the top-left corner (cell (1,1)(1,1)) and wants to reach the top-right corner (cell (N,1)(N,1)). Determine the minimum number of moves in which the task can be accomplished.

Input Format

  • The first line will contain TT, the number of test cases. Then the test cases follow.
  • Each test case contains a single integer NN in a separate line.

Output Format

Output the minimum number of moves to get from the top-left cell to the top-right one.


  • 1≤T≤5001≤T≤500
  • 2≤N≤5002≤N≤500

Sample Input 1 


Sample Output 1 



Test case 1:

Initially chef is at (1,1)(1,1). He cannot directly move to (2,1)(2,1) as the disabled king cannot move horizontally. So he needs at least 22 moves to reach (2,1)(2,1). And that can be achieved by first moving to (1,2)(1,2) and then moving to (2,1)(2,1) from there.

Test case 2:

Clearly we cannot reach (3,1)(3,1) from (1,1)(1,1) in just one move. We require at least 22 moves. And this can be achieved by first moving to (2,2)(2,2) and then moving to (3,1)(3,1) from there.


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

int main(){

    int T; cin >> T;
        int N; cin >> N;
        if(N&1) cout << N-1 << "\n";
        else cout << N << "\n";

    return 0;

* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first.