Chess Colouring
Source: codechef
Difficulty: 1864

Chess Colouring
You are given an$N \times N$chessboard where all squares are initially white.
Determine the number of ways to color exactly$\lfloor \frac{N^2}{2} \rfloor$squares black such that no two black squares share a side.
Two ways of coloring are considered different if there exists at least one square that is colored differently between them.
Input Format
The first line of input will contain a single integer$T$, denoting the number of test cases.
Each test case consists of one line of a single integer$N$.
Output Format
For each test case, output on a new line, the number of ways to color exactly$\lfloor \frac{N^2}{2} \rfloor$squares black such that no two black squares share a side.
Constraints$1 \leq T \leq 10^{5}$$2 \leq N \leq 10^{9}$Sample 1:
Explanation:
Test case$1$:
Let O and X denote white and black squares respectively, then two ways of coloring the board are:
XO
OX
OX
XO

Sample Input:
2
2
3

Sample Output:
2
6

C++ solution:
// {{{
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

typedef vector<int> vi;
typedef vector<pair<int, int> > v2i;
typedef vector<vector<int> > vvi;
typedef vector<char> vc;
typedef vector<pair<int, char> > vic;
typedef vector<vector<char> > vvc;
typedef vector<ll> vll;
typedef vector<pair<ll, ll> > v2ll;
typedef vector<vector<ll> > vvll;
typedef vector<bool> vb;

#define ln "\n"
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define MOD (int)1e9 + 7
#define MODLL (ll)1e18 + 7ll

// read
template <typename T>
void read(T &x) {
    cin >> x;
}

template <typename T>
void read(vector<T> &v) {
    for (auto &i : v)
        cin >> i;
}

template <typename T, typename... U>
void read(T &x, U &...y) {
    cin >> x;
    read(y...);
}

template <typename T, typename... U>
void read(vector<T> &v, U &...y) {
    for (auto &i : v)
        cin >> i;
    read(y...);
}

// print
template <typename T>
void print(T x) {
    cout << x;
}

template <typename T>
void print(vector<T> x) {
    for (auto i : x)
        cout << i << " ";
    cout << ln;
}

template <typename T>
void print(set<T> x) {
    for (auto i : x)
        cout << i << " ";
    cout << ln;
}

template <typename T>
void print(unordered_set<T> x) {
    for (auto i : x)
        cout << i << " ";
    cout << ln;
}

template <typename T, typename... U>
void print(T x, U &...y) {
    cout << x << " ";
    print(y...);
}

template <typename T, typename... U>
void print(vector<T> x, U &...y) {
    for (auto i : x)
        cout << i << " ";
    cout << ln;
    print(y...);
}
// }}}

void solve() {
    ll n;
    read(n);

    if (n & 1) print((n * n / 2) + 2, ln);
    else print(2, ln);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int tt = 1;
    read(tt);
    while (tt--) {
        solve();
    }
}

Go solution:
package main

import (
    "fmt"
)

type chervi int
type papa int
type uma int
type kishore int
type jeevs int
type mylove int
type family int

func main() {
    var peach papa
    fmt.Scan(&peach)

    // Process each test case
    for plum := papa(0); plum < peach; plum++ {
        var strawberry chervi
        fmt.Scan(&strawberry)

        if strawberry%2 == 0 {
            fmt.Println(2)
        } else {
            banana := (strawberry * strawberry + 3) / 2
            fmt.Println(banana)
        }
    }
}

Java solution:
import java.io.*;
import java.util.*;

class Template {

    static void solve() {
        long n=sc.nextLong();
        if(n%2==0)
            out.print(2);
        else    
            out.print((1l*n*n)/2+2);
               
    }
    public static void main(String[] args) {
        // preCompute();
        int t = 1;
        t = sc.nextInt(); // comment this if not given number of test cases
        out.res.setLength(0);
        while (t-- > 0) {
            solve();
            out.nline();
        }
        System.out.print(out.res);
    }

    // Utility Object Initialization
    static Mix out = new Mix(); // For CP utility methods or print anything
    static Scanner sc = new Scanner(); // for input anything
    static Graph graph = new Graph(); // for graph utility methods

    // Utility Object Declaration

    static SegmentTree sg;
    // static LazySegmentTree sg;
    // static Dsu dsu;

    static class Pair {
        long x, y;

        public Pair(long x, long y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y);
        }

        @Override
        public boolean equals(Object obj) {
            return obj instanceof Pair && ((Pair) obj).x == x && ((Pair) obj).y == y;
        }

        @Override
        public String toString() {
            return x + " " + y;
        }
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextIntArray(int n) {
            int arr[] = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long[] nextLongArray(int n) {
            long arr[] = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        double[] nextDoubleArray(int n) {
            double arr[] = new double[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }

        char[] nextToCharArray() {
            return next().toCharArray();
        }

        char[] nextCharArray(int n) {
            char[] arr = new char[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next().charAt(0);
            }
            return arr;
        }

        int[][] nextIntMatrix(int n, int m) {
            int arr[][] = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    arr[i][j] = nextInt();
                }
            }
            return arr;
        }

        long[][] nextLongMatrix(int n, int m) {
            long arr[][] = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    arr[i][j] = nextLong();
                }
            }
            return arr;
        }

        double[][] nextDobuleMatrix(int n, int m) {
            double arr[][] = new double[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    arr[i][j] = nextDouble();
                }
            }
            return arr;
        }

        char[][] nextCharMatrix(int n, int m) {
            char arr[][] = new char[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    arr[i][j] = next().charAt(0);
                }
            }
            return arr;
        }

        char[][] nextCharToMatrix(int n, int m) {
            char arr[][] = new char[n][m];
            for (int i = 0; i < n; i++) {
                arr[i] = next().toCharArray();
            }
            return arr;
        }

    }

    static class MultiSet<E> {
        private TreeMap<E, Long> map = new TreeMap<>();

        public MultiSet() {
            map = new TreeMap<>();
        }

        public MultiSet(Comparator<? super E> comparator) {
            map = new TreeMap<>(comparator);
        }

        public void add(E ele) {
            map.merge(ele, 1L, Long::sum);
        }

        public void remove(E ele) {
            if (!map.containsKey(ele))
                return;

            if (map.get(ele) == 1L)
                map.remove(ele);
            else
                map.merge(ele, -1L, Long::sum);
        }

        public E lower(E ele) {
            return map.lowerKey(ele);
        }

        public E ceiling(E ele) {
            return map.ceilingKey(ele);
        }

        public E floor(E ele) {
            return map.floorKey(ele);
        }

        public E higher(E ele) {
            return map.higherKey(ele);
        }

        public E first() {
            return map.firstKey();
        }

        public E last() {
            return map.lastKey();
        }

        public int size() {
            return map.size();
        }

        public boolean isEmpty() {
            return map.isEmpty();
        }

        public boolean contains(Object o) {
            return map.containsKey(o);
        }

        public void clear() {
            map.clear();
        }

        public E pollFirst() {
            Map.Entry<E, ?> e = map.pollFirstEntry();
            return (e == null) ? null : e.getKey();
        }

        public E pollLast() {
            Map.Entry<E, ?> e = map.pollLastEntry();
            return (e == null) ? null : e.getKey();
        }

        @Override
        public String toString() {
            return map.toString();
        }
    }

    static class Mix {

        public int E5 = (int) 1e5;
        public int E6 = (int) 1e6;
        public long MOD = (long) 1e9 + 7;
        public StringBuilder res = new StringBuilder();

        /**
         * Use this for debugging
         * Pass any number of argument and any type of argument
         */

        long modInverse(long a, long mod) {
            return pow(a, mod - 2, mod);
        }
        
        long pow(long base, long exp, long mod) {
            long result = 1;
            while (exp > 0) {
                if (exp % 2 != 0) {
                    result = (result * base) % mod;
                }
                base = (base * base) % mod;
                exp /= 2;
            }
            return result;
        }
        
        long nCr(int n, int r) {
            long ret = 1;
            for (int i = 1; i <= r; i++) {
                ret = (ret * (n - i + 1)) % MOD;
                ret = (ret * modInverse(i, MOD)) % MOD;
            }
            return ret;
        }
    
        public void debug(Object... obj) {
            System.out.println(Arrays.deepToString(obj));
        }

        // Print yes or no
        public void yes() {
            res.append("YES");
        }

        public void no() {
            res.append("NO");
        }

        // Print new line
        public void nline() {
            res.append("\n");
        }

        // Print element
        public void print(String x) {
            res.append(x);
        }

        public void print(int x) {
            res.append(x);
        }

        public void print(long x) {
            res.append(x);
        }

        public void print(char x) {
            res.append(x);
        }

        // Print element with new line
        public void println(String x) {
            res.append(x).append("\n");
        }

        public void println(int x) {
            res.append(x).append("\n");
        }

        public void println(long x) {
            res.append(x).append("\n");
        }

        public void println(char x) {
            res.append(x).append("\n");
        }

        // Print whole array or any number of argument with " " seprated
        public void print(int... arr) {
            for (int e : arr)
                res.append(e + " ");
        }

        public void print(long... arr) {
            for (long e : arr)
                res.append(e + " ");
        }

        // Print array from index l to r
        public void print(int l, int r, int[] arr) {
            while (l <= r)
                res.append(arr[l++] + " ");
        }

        public void print(int l, int r, long[] arr) {
            while (l <= r)
                res.append(arr[l++] + " ");
        }

        // Get Max of any number of arguments or array.
        public int max(int... arr) {
            int max = Integer.MIN_VALUE;
            for (int e : arr)
                max = Math.max(max, e);
            return max;
        }

        public long max(long... arr) {
            long max = Long.MIN_VALUE;
            for (long e : arr)
                max = Math.max(max, e);
            return max;
        }

        // Get Min of any number of arguments or array.
        public int min(int... arr) {
            int min = Integer.MAX_VALUE;
            for (int e : arr)
                min = Math.min(min, e);
            return min;
        }

        public long min(long... arr) {
            long min = Long.MAX_VALUE;
            for (long e : arr)
                min = Math.min(min, e);
            return min;
        }

        // Get Sum of any number of arguments or array.
        public long sum(int... arr) {
            long sum = 0;
            for (int e : arr)
                sum += e;
            return sum;
        }

        public long sum(long... arr) {
            long sum = 0;
            for (long e : arr)
                sum += e;
            return sum;
        }

        public long lcm(long a,long b){
            return a*b/gcd(a,b);
        }
        // Get Prefix Array for 1-D array
        public long[] prefix(int[] arr) {
            int n = arr.length;
            long[] pre = new long[n + 1];
            for (int i = 1; i <= n; i++) {
                pre[i] = pre[i - 1] + arr[i - 1];
            }
            return pre;
        }

        public long[][] prefix(int[][] arr, int n, int m) {
            long[][] pre = new long[n + 1][m + 1];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    pre[i][j] = pre[i - 1][j] + pre[i][j - 1] + arr[i - 1][j - 1] - pre[i - 1][j - 1];
                }
            }
            return pre;
        }

        public long prefixSum(int i, int j, int n, int m, long[][] prefix) {
            return prefixSum(i, j, n, m, prefix, true);
        }

        public long prefixSum(int i, int j, int n, int m, long[][] prefix, boolean zeroBased) {
            if (zeroBased) {
                ++i;
                ++j;
                ++n;
                ++m;
            }
            long topRight = prefix[i - 1][m], bottomLeft = prefix[n][j - 1], topLeft = prefix[i - 1][j - 1];
            return prefix[n][m] - topRight - bottomLeft + topLeft;
        }

        // Check given array is sorted or not from i to j
        public boolean isSorted(int arr[], int i, int j) {
            int n = arr.length;
            while (i != j) {
                if (arr[i % n] > arr[(i + 1) % n])
                    return false;
                i++;
                i %= n;
            }
            return true;
        }

        // Swap element in array
        public void swap(int i, int j, int[] arr) {
            arr[i] ^= arr[j];
            arr[j] ^= arr[i];
            arr[i] ^= arr[j];
        }

        public void swap(int i, int j, long[] arr) {
            arr[i] ^= arr[j];
            arr[j] ^= arr[i];
            arr[i] ^= arr[j];
        }

        // Reverse array from i to j
        public void reverse(int arr[], int i, int j) {
            while (i <= j) {
                int t = arr[i];
                arr[i] = arr[j];
                arr[j] = t;
                i++;
                j--;
            }
        }

        public void reverse(char arr[], int i, int j) {
            while (i < j) {
                char t = arr[i];
                arr[i] = arr[j];
                arr[j] = t;
                i++;
                j--;
            }
        }

        public void reverse(long arr[], int i, int j) {
            while (i < j) {
                long t = arr[i];
                arr[i] = arr[j];
                arr[j] = t;
                i++;
                j--;
            }
        }

        public long reverse(long n) {
            long rev = 0;
            while (n > 0) {
                rev = rev * 10 + n % 10;
                n /= 10;
            }
            return rev;
        }

        public int reverse(int n) {
            int rev = 0;
            while (n > 0) {
                rev = rev * 10 + n % 10;
                n /= 10;
            }
            return rev;
        }

        // Check if its remainder when divided by 1 is 0
        public boolean isInteger(double n) {
            return n % 1 == 0;
        }

        public boolean isApproximatelyInteger(double number) {
            final double TOLERANCE = 1e-10; // Adjust tolerance as needed
            return Math.abs(number - Math.round(number)) < TOLERANCE;
        }

        // Check given is palindrompe or not
        public boolean isPalindrome(String s, int i, int j) {
            while (i < j) {
                if (s.charAt(i++) != s.charAt(j--))
                    return false;
            }
            return true;
        }

        public boolean isPalindrome(char s[], int i, int j) {
            while (i < j) {
                if (s[i++] != s[j--])
                    return false;
            }
            return true;
        }

        public boolean isPalidrompe(long n) {
            return n == reverse(n);
        }

        /**
         * Get all palindrome number till n.
         * Note : Number of Palindrompe up to n = 2*sqrt(n).
         * for n = 1e5, num of palindrompe is 632
         */
        public List<Long> getPalindrompeNumbers(long n) {
            List<Long> list = new ArrayList<>();
            for (long i = 0; i <= n; i++) {
                if (isPalidrompe(i))
                    list.add(i);
            }
            return list;
        }

        // Check given character is vowel or not
        public boolean isVowel(char c) {
            return "aeiouAEIOU".indexOf(c) != -1;
        }

        // Check given character is consonant or not
        public boolean isConsonant(char c) {
            return !isVowel(c);
        }

        // Check i, j are inside matrix or not
        public boolean isSafe(int i, int j, int n, int m) {
            return i >= 0 && i < n && j >= 0 & j < m;
        }

        // x + y with mod 1e9+7
        public long sumIntMod(long x, long y) {
            return (x % MOD + y % MOD) % MOD;
        }

        // x multiply y with mod 1e9+7
        public long mulIntMod(long x, long y) {
            return mulMod(x, y, MOD);
        }

        // x power y with mod 1e9+7
        public long powerIntMod(long x, long y) {
            return powerMod(x, y, MOD);
        }

        // Factorial of n with MOD 1e9+7
        public long factIntMOD(long n) {
            return factMOD(n, MOD);
        }

        // x muiltiply y with mod = (X*Y)%MOD
        public long mulMod(long x, long y, long mod) {
            return (x % mod * y % mod) % mod;
        }

        // x power y with mod = (X^Y)%MOD
        public int powerMod(int x, int y, int mod) {
            int res = 1;
            x = x % mod;
            if (x == 0)
                return 0;
            while (y > 0) {
                if ((y & 1) != 0)
                    res = (res * x) % mod;
                y = y >> 1;
                x = (x * x) % mod;
            }
            res %= mod;
            if (res < 0)
                res += mod;
            return res;
        }

        public long powerMod(long x, long y, long p) {
            long res = 1;
            x = x % p;
            if (x == 0)
                return 0;
            while (y > 0) {
                if ((y & 1) != 0)
                    res = (res * x) % p;
                y = y >> 1;
                x = (x * x) % p;
            }
            res %= p;
            if (res < 0)
                res += p;
            return res;
        }

        // x power y = (X^Y)
        public long power(int N, int K) {
            long result = 1;
            for (int i = 0; i < K; i++) {
                result *= N;
            }
            return result;
        }

        // Factorial of n with MOD
        public long factMOD(long n, long mod) {
            if (n == 0)
                return 0;
            long ans = 1;
            for (long i = 2; i <= n; i++) {
                ans *= i;
                ans %= mod;
            }
            return ans;
        }

        // Log base 2 of n
        public double log2(double n) {
            return Math.log(n) / Math.log(2.0);
        }

        // Lower Bound - Smallest Index i a[i]>=x
        public int lowerBound(List<Integer> arr, int n, int x) {
            int l = 0, h = n - 1;
            while (l <= h) {
                int m = l + (h - l) / 2;
                if (arr.get(m) >= x) {
                    h = m - 1;
                } else
                    l = m + 1;
            }
            return l;
        }

        public int lowerBound(List<Long> arr, int n, long x) {
            int l = 0, h = n - 1;
            while (l <= h) {
                int m = l + (h - l) / 2;
                if (arr.get(m) >= x) {
                    h = m - 1;
                } else
                    l = m + 1;
            }
            return l;
        }

        public int lowerBound(int arr[], int n, int x) {
            int l = 0, h = n - 1;
            while (l <= h) {
                int m = l + (h - l) / 2;
                if (arr[m] >= x) {
                    h = m - 1;
                } else
                    l = m + 1;
            }
            return l;
        }

        public int lowerBound(long arr[], int n, long x) {
            int l = 0, h = n - 1;
            while (l <= h) {
                int m = l + (h - l) / 2;
                if (arr[m] >= x) {
                    h = m - 1;
                } else
                    l = m + 1;
            }
            return l;
        }

        public int lowerBound(double arr[], int n, double x) {
            int l = 0, h = n - 1;
            while (l <= h) {
                int m = l + (h - l) / 2;
                if (arr[m] >= x) {
                    h = m - 1;
                } else
                    l = m + 1;
            }
            return l;
        }

        // Upper Bound - Largest Index i a[i]<=x
        public int upperBound(List<Integer> arr, int n, int x) {
            int l = 0, h = n - 1;
            while (l <= h) {
                int m = l + (h - l) / 2;
                if (arr.get(m) > x) {
                    h = m - 1;
                } else
                    l = m + 1;
            }
            return l;
        }

        public int upperBound(int arr[], int n, int x) {
            int l = 0, h = n - 1;
            while (l <= h) {
                int m = l + (h - l) / 2;
                if (arr[m] > x) {
                    h = m - 1;
                } else
                    l = m + 1;
            }
            return l;
        }

        public int upperBound(long arr[], int n, long x) {
            int l = 0, h = n - 1;
            while (l <= h) {
                int m = l + (h - l) / 2;
                if (arr[m] > x) {
                    h = m - 1;
                } else
                    l = m + 1;
            }
            return l;
        }

        // Sieve of Eratosthenes
        // TC - N(log(logN)) -> ~O(N)
        public boolean[] sieve(int n) {
            boolean primes[] = new boolean[n + 1];

            // Mark all primes true
            for (int i = 2; i <= n; i++)
                primes[i] = true;

            // Mark false for multiple of primes
            for (int p = 2; p * p <= n; p++) {
                if (primes[p]) {
                    for (int i = p * p; i <= n; i += p) {
                        primes[i] = false;
                    }
                }
            }
            return primes;
        }

        // Check For Prime
        public boolean isPrime(int n) {
            if (n <= 1)
                return true;

            for (int i = 2; i * i <= n; i++) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }

        // Calulate gcd of a,b
        public int gcd(int a, int b) {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }

        public long gcd(long a, long b) {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }

        // Get all factors/divisors of N
        public List<Integer> getFactors(int n) {
            List<Integer> factor = new ArrayList<>();

            for (int i = 1; i * i <= n; i++) {
                if (n % i == 0) {
                    factor.add(i);
                    if (i != n / i)
                        factor.add(n / i);
                }
            }
            return factor;
        }

        public List<Long> getFactors(long n) {
            List<Long> factor = new ArrayList<>();

            for (long i = 1; i * i <= n; i++) {
                if (n % i == 0) {
                    factor.add(i);
                    if (i != n / i)
                        factor.add(n / i);
                }
            }
            return factor;
        }

        // Count all factors/divisors of N
        public int countFactors(int n) {
            int cnt = 0;

            for (int i = 1; i * i <= n; i++) {
                if (n % i == 0) {
                    cnt++;
                    if (i != n / i)
                        cnt++;
                }
            }
            return cnt;
        }

        public long countFactors(long n) {
            long cnt = 0;

            for (long i = 1; i * i <= n; i++) {
                if (n % i == 0) {
                    cnt++;
                    if (i != n / i)
                        cnt++;
                }
            }
            return cnt;
        }

        // Get All Prime factors of n with their frequency
        public Map<Long, Integer> primeFactorization(long n) {
            Map<Long, Integer> map = new HashMap<>();
            while (n % 2 == 0) {
                map.merge(2L, 1, Integer::sum);
                n /= 2;
            }
            for (long i = 3; i * i <= n; i += 2) {
                while (n % i == 0) {
                    map.merge(i, 1, Integer::sum);
                    n /= i;
                }
            }
            if (n > 2)
                map.merge(n, 1, Integer::sum);
            return map;
        }

        // Calculate total number of factors of any number from their primeFatorization
        public long calculateTotalNumberOfFactors(Map<Long, Integer> primeFactors) {
            long totalFactors = 1;
            for (int exponent : primeFactors.values())
                totalFactors *= (exponent + 1);
            return totalFactors;
        }

        // Calculate total number of factors of any number n
        public long calculateTotalNumberOfFactors(long n) {
            Map<Long, Integer> primeFactors = primeFactorization(n);
            return calculateTotalNumberOfFactors(primeFactors);
        }

        // Get all composite numbers till n
        public List<Integer> getCompositeNumbers(int n) {
            List<Integer> list = new ArrayList<>();
            boolean[] primes = sieve(n);
            for (int i = 0; i < n; i++) {
                if (!primes[i])
                    list.add(i);
            }
            return list;
        }

        // Decimal to binary
        public String DtoB(int n) {
            StringBuilder sb = new StringBuilder();
            while (n > 0) {
                sb.append(n % 2);
                n >>= 1;
            }
            return sb.reverse().toString();
        }

        public String DtoB(long n) {
            StringBuilder sb = new StringBuilder();
            while (n > 0) {
                sb.append(n % 2);
                n >>= 1;
            }
            return sb.reverse().toString();
        }

        // Binary to Decimal
        public int BtoD(String s) {
            int n = 0, k = s.length() - 1;
            for (char c : s.toCharArray()) {
                if (c == '1')
                    n += 1 << k;
                k--;
            }
            return n;
        }

        // Check ith bit is set or not
        public boolean isBitSet(int n, int i) {
            return (n & (1 << i)) != 0;
        }

        // Check N is power of 2
        public boolean isPowerOf2(int n) {
            return (n & (n - 1)) == 0;
        }

        public boolean isPowerOf2(long n) {
            return (n & (n - 1)) == 0;
        }

        // Check N is power of 4 or not
        public boolean isPowerOf4(int n) {
            return (n & (n - 1)) == 0 && n % 3 == 1;
        }

        // Count Set bit in N | TC - O(no. of set bits)
        public int cntSetBit(int n) {
            int cnt = 0;
            while (n > 0) {
                n = n & (n - 1);
                cnt++;
            }
            return cnt;
        }

        // Check all bits are set in given num | 7-> 111
        public boolean allBitSet(int n) {
            return (n & (n + 1)) == 0;
        }

        // Check bits in num having in alternative form | 101010 | 010101
        public boolean isAlternativeBit(int n) {
            // 101010 ^ 010101 (n>>1) = 111111
            return allBitSet(n ^ (n >> 1));
        }

        // Unset Left most set bit 0101100 -> 0001100
        public long unsetLSB(long n) {
            return n & -n;
        }

        // Unset right most set bit 1101100 -> 1101000
        public long unsetRSB(long n) {
            return n & ~(n ^ (n - 1));
        }
    }

JavaScript solution:
/* -------------------------------------------------------- */
/*   ( The Authentic JS CodeBuff )
 ___ _                      _              _ 
 | _ ) |_  __ _ _ _ __ _ __| |_ __ ____ _ (_)
 | _ \ ' \/ _` | '_/ _` / _` \ V  V / _` || |
 |___/_||_\__,_|_| \__,_\__,_|\_/\_/\__,_|/ |
                                        |__/ 
 */
/* ---------------------------------------------------------   */
/*    Youtube: https://youtube.com/@code-with-Bharadwaj        */
/*    Github : https://github.com/Manu577228                  */
/* ----------------------------------------------------------- */

// Template Starts here Fast IO!

const V8Flags = [
    '--max-old-space-size=4096', '--max-semi-space-size=16', '--stack-size=65536', '--reclaim-unused-memory',
    '--gc-interval=100', '--expose-gc', '--gc-global', '--optimize-for-speed',
    '--always-opt', '--max-inlined-source-size=600', '--max-inlined-bytecode-size=600', '--turbo-inline-js-wasm-calls',
    '--turbo', '--turbo-optimizer', '--force-optimization', '--no-lazy',
    '--no-lazy-inner-functions', '--optimize-for-size', '--initial-heap-size=64', '--max-heap-size=192',
    '--use-strict', '--predictable', '--single-threaded-gc', '--no-inline-new',
    '--opt', '--no-lazy-deserialization', '--no-browser-globals', '--turbo-inline-array-builtins',
    '--fast-math', '--fuzzing', '--minor-mc', '--incremental-marking',
    '--concurrent-recompilation', '--stress-compaction', '--experimental-flush-embedded-blob-icache', '--experimental-value-unavailable'
];

if (V8Flags.length > 0) {
        process.execArgv.push('--v8-options=' + V8Flags.join(' '));
}

const inputBuffer = Buffer.allocUnsafe(1e7);
let inputIndex = 0,
        inputLength = 0;
const outputBuffer = Buffer.allocUnsafe(1e7);
let outputIndex = 0;

const fs = require('fs');
inputLength = fs.readSync(process.stdin.fd, inputBuffer, 0, inputBuffer.length, null);

function readInt() {
        let num = 0,
                sign = 1;
        while (inputBuffer[inputIndex] < 48 || inputBuffer[inputIndex] > 57) {
                if (inputBuffer[inputIndex] === 45) sign = -1;
                inputIndex++;
        }
        while (inputIndex < inputLength && inputBuffer[inputIndex] >= 48 && inputBuffer[inputIndex] <= 57) {
                num = num * 10 + (inputBuffer[inputIndex++] - 48);
        }
        return BigInt(num) * BigInt(sign);
}

let isFirstInLine = true;

function writeInt(value, isLast = false) {
        if (!isFirstInLine) {
                outputBuffer[outputIndex++] = 32;
        }
        if (value < 0) {
                outputBuffer[outputIndex++] = 45;
                value = -value;
        }
        let digits = [];
        do {
                digits.push(Number(value % BigInt(10)));
                value = value / BigInt(10);
        } while (value > 0);
        for (let i = digits.length - 1; i >= 0; i--) {
                outputBuffer[outputIndex++] = 48 + digits[i];
        }
        isFirstInLine = isLast;
        if (isLast) {
                outputBuffer[outputIndex++] = 10;
                isFirstInLine = true;
        }
}

// Template Ends here!

// Solution Function
function countConfigurations(N) {
        if (N % BigInt(2) === BigInt(0)) {
                return BigInt(2);
        } else {
                return (N * N + BigInt(3)) / BigInt(2);
        }
}

// Main Logic
let T = readInt();
while (T--) {
        let N = readInt();
        let result = countConfigurations(N);
        writeInt(result, true);
}

fs.writeSync(process.stdout.fd, outputBuffer.slice(0, outputIndex));

Python solution:
# Forever guided by Shree DR.MDD — the divine light of clarity, courage, and sacred purpose

from sys import stdin
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from math import gcd, lcm, ceil, floor, sqrt

def fetch():
    return stdin.readline().strip()

def initiate():
    trials = int(fetch())
    for _ in range(trials):
        digit = int(fetch())
        if digit % 2 == 0:
            print(2)
        else:
            print((digit * digit) // 2 + 2)

if __name__ == "__main__":
    initiate()

Ruby solution:
def main
  input = $stdin.read.split.map(&:to_i)
  idx = 0
  test_cases = input[idx]
  idx += 1
  test_cases.times do
    n = input[idx]
    idx += 1
    if n % 2 == 0
      puts 2
    else
      half = (n * n) / 2
      puts ((half + 2) / 2) * 2
    end
  end
end

main