Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------
int main(){
ll n;
cin>>n;
ll a;
ll array[n];
ll sum=0;
for(int i=0;i<n;i++){
    cin>>a;
    array[i]=a;
    sum+=a;
}
ll avr=sum/n;
ll b;
if(n%2==0){
b=avr-(n/2);
}else{
b=avr-(n/2)-1;
}
ll sad=0;
for(int i=0;i<n;i++){
    sad+=abs(array[i]-(b+i+1));#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------
int main(){
ll n;
cin>>n;
ll a;
ll array[n];
ll sum=0;
for(int i=0;i<n;i++){
    cin>>a;
    array[i]=a;
    sum+=a;
}
ll avr=sum/n;
ll b;
if(n%2==0){
b=avr-(n/2);
}else{
b=avr-(n/2)-1;
}
ll sad=0;
for(int i=0;i<n;i++){
    sad+=abs(array[i]-(b+i+1));
}
cout<<sad<<endl;
}






}
cout<<sad<<endl;
}







Compiler output:
a.cc:202:32: error: stray '#' in program
  202 |     sad+=abs(array[i]-(b+i+1));#include <iostream>
      |                                ^
a.cc: In function 'int main()':
a.cc:202:33: error: 'include' was not declared in this scope
  202 |     sad+=abs(array[i]-(b+i+1));#include <iostream>
      |                                 ^~~~~~~
a.cc:202:50: error: expected primary-expression before '>' token
  202 |     sad+=abs(array[i]-(b+i+1));#include <iostream>
      |                                                  ^
a.cc:215:1: error: expected primary-expression before 'using'
  215 | using namespace std;
      | ^~~~~
a.cc:223:1: error: a template declaration cannot appear at block scope
  223 | template <class T>
      | ^~~~~~~~
a.cc:245:1: error: a function-definition is not allowed here before '{' token
  245 | {
      | ^
a.cc:257:1: error: a function-definition is not allowed here before '{' token
  257 | {
      | ^
a.cc:262:1: error: a function-definition is not allowed here before '{' token
  262 | {
      | ^
a.cc:294:1: error: a template declaration cannot appear at block scope
  294 | template <typename T>
      | ^~~~~~~~
a.cc:324:1: error: a template declaration cannot appear at block scope
  324 | template <typename T>
      | ^~~~~~~~
a.cc:340:1: error: a template declaration cannot appear at block scope
  340 | template <class ForwardIt, class T>
      | ^~~~~~~~
a.cc:362:1: error: a function-definition is not allowed here before '{' token
  362 | {
      | ^
a.cc:367:1: error: a function-definition is not allowed here before '{' token
  367 | {
      | ^
a.cc:383:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  383 | int main(){
      |         ^~
a.cc:383:9: note: remove parentheses to default-initialize a variable
  383 | int main(){
      |         ^~
      |         --
a.cc:383:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:383:11: error: a function-definition is not allowed here before '{' token
  383 | int main(){
      |           ^