Counting 01 and 10
Source: codechef
Difficulty: 1776

Counting 01 and 10
Given a binary string$S$, let$X$denote the number of$01$subsequences and$Y$denote the number of$10$subsequences in it.
For example, for$S = 10010$, there are$2$$01$subsequences and$4$$10$subsequences, so$X = 2$and$Y = 4$.
Let$f(S) = (X, Y)$, i.e. the function value is the pair of values$X$and$Y$for the given string.
Consider all binary strings of length$N$. How many distinct values of$f(S)$exist? It can be proven that the answer does not exceed$10^{18}$in the given constraints.
Input Format
The first line of input will contain a single integer$T$, denoting the number of test cases.
Each test case consists of multiple lines of input.
The first and only line contains a single integer$N$.
Output Format
For each test case, output on a new line the number of distinct values of$f(S)$possible.
It can be proven that the answer does not exceed$10^{18}$in the given constraints.
Constraints$1 \le T \le 10^4$$1 \le N \le 2 \cdot 10^5$The sum of$N$over all test cases does not exceed$2 \cdot 10^5$.
Sample 1:
Explanation:
Test Case 1
: For all length$1$strings,$f(S) = (0, 0)$.
Test Case 2
: Here are the calculations:$f(S) = (0, 1)$for$S = 10$$f(S) = (1, 0)$for$S = 01$$f(S) = (0, 0)$for$S = 00$and$S = 11$.
Thus, there are$3$distinct values possible.

Sample Input:
7
1
2
3
4
5
6
100000

Sample Output:
1
3
4
10
13
26
83334583375001

C++ solution:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

void solve()
{
    ll N;
    cin>>N;
    ll res=0;
    if (N % 2 == 0)
    {
            ll m = floor(N / 2);
             res = floor((m + 1) * (4 * m * m - m + 6) / 6);
    }
        else
        {
             res = floor((N + 1) * (N * N - N + 6) / 12);
        }
    cout<<res<<endl;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
}

Go solution:
package main

import (
    "fmt"
)

func main() {
    var studentsofkluy23_1 int
    fmt.Scan(&studentsofkluy23_1)

    for studentsofkluy23_1 > 0 {
        studentsofkluy23_1--

        var studentsofkluy23_2 int64
        fmt.Scan(&studentsofkluy23_2)

        studentsofkluy23_3 := studentsofkluy23_2 / 2
        studentsofkluy23_4 := studentsofkluy23_3*(3*studentsofkluy23_2-2*studentsofkluy23_3-1) + 6
        studentsofkluy23_5 := (studentsofkluy23_3 + 1) * studentsofkluy23_4 / 6

        fmt.Println(studentsofkluy23_5)
    }
}

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

class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        
        while(t-- > 0) {
            
            int n = sc.nextInt();
            int mod = (int)(1e9 + 7);
            long ans = 1l;
            
            int TComb = n / 2;
            
            for(int z = 1; z <= TComb; z++) {
                int o = n - z;
                long comb = 1l * o * z;
                ans = (ans + comb + 1);
            }
            
            System.out.println(ans);
        }

    }
}

JavaScript solution:
// your code goes here
const amalapuram = require("readline");

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

let input = [];

ramachandrapuram.on("line", (line) => {
    input.push(line);
}).on("close", () => {
    if (input.length === 0) return;
    
    let kothapeta = parseInt(input[0]);
    let outputLines = [];
    
    for (let i = 1; i <= kothapeta; i++) {
        let ainavilli = parseInt(input[i]);
        let mummidivaram = Math.floor(ainavilli / 2); // Floor division

        // Correcting the summation formula
        let allavaram = (mummidivaram * (mummidivaram + 1)) / 2; // Sum of first mummidivaram numbers
        let mandapeta = (mummidivaram * (mummidivaram + 1) * (2 * mummidivaram + 1)) / 6; // Sum of squares

        let yatavakili = ainavilli * allavaram - mandapeta;
        let gollavilli = (mummidivaram + 1) + yatavakili; // Adjusted calculation

        outputLines.push(gollavilli.toString());
    }

    console.log(outputLines.join("\n"));
});

Python solution:
# cook your dish here
# cook your dish here
def compute_result():
    input_value=int(input())
    half_value=input_value//2
    top_part=half_value*(3*input_value-2*half_value-1)+6
    final_result=(half_value+1)*top_part//6
    print(final_result)
    
test_cases=int(input())
for _ in range(test_cases):
    compute_result()

Ruby solution:
def solve
  input = $stdin.read.split.map(&:to_i)
  idx = 0
  t = input[idx]
  idx += 1
  results = []
  t.times do
    n = input[idx]
    idx += 1
    ans = 0
    (1..(n / 2)).each do |i|
      count = i * (n - i)
      ans += count + 1
    end
    ans += 1
    results << ans
  end
  puts results.join("\n")
end

solve