What's the difference?

My issue

my friend submitted this code in cpp which gave us the right answer:
include <bits/stdc++.h>
define ll long long
define ld long double
define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
using namespace std;

int main()
{
fastio;
ll t;
cin >> t;
while (t–)
{
ll n;
cin >> n;
ll ans = (n * (n + 1)) / 2;
ans -= 1;
ans += n;
cout << ans << “\n”;
}
return 0;
}
so he and I have submitted the same code but mine is in different style and did not pass the test case on this question maximum and minimum II

My code

#include <bits/stdc++.h>

using namespace std;

int s(int n) {
    return (n * (n + 1)) / 2;
}

int main() {
    long long t, n, res;
    cin >> t;

    while (t--) {
        cin >> n;
        res = s(n) + n;
        cout << res - 1 << endl;
    }

    return 0;
}

Problem Link: Minimum And Maximum II Practice Coding Problem - CodeChef

int s(int n) {
    return (n * (n + 1)) / 2;
}

The problem is in this function as the data type here is int and the result of the expression would be of type long and gets stored in int.

long long s(long long n) {
    return (n * (n + 1)) / 2;
}

Try this, I hope it helps…