criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

ll MOD = 1000000007;
ll lcm(ll a, ll b) { return (a / __gcd(a, b) * b); }

int main() {
  //
  int n;
  cin >> n;
  ll ans = INT_MAX;
  vi a(n);
  rep(i, n) cin >> a[i];
  REP(x, -100, 101) {
    ll total = 0;
    rep(i, n) { total += (x - a[i]) * (x - a[i]); }
    ans = min(total, ans);
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:36:12: error: 'INT_MAX' was not declared in this scope
   36 |   ll ans = INT_MAX;
      |            ^~~~~~~
a.cc:15:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   14 | #include <unordered_set>
  +++ |+#include <climits>
   15 | #include <vector>
Language: C++


#include <iostream>
#include <vector>
#include <numeric>
#include <functional>
using namespace std;

int main() {
	int n;
	cin >> n;
	auto v = vector<int>(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	int avg = round(accumulate(v.begin(), v.end(), 0, plus<int>()) / (double)n);
	cout << avg << endl;
	cout << accumulate(v.begin(), v.end(), 0, [avg](auto acc, auto x) {
		return acc + (avg - x) * (avg - x);
	}) << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:14:19: error: 'round' was not declared in this scope
   14 |         int avg = round(accumulate(v.begin(), v.end(), 0, plus<int>()) / (double)n);
      |                   ^~~~~
Language: C++

#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
//AtCoderC++.cpp

using namespace std;


int main() {
	int N; cin >> N;
	auto sum = 0.0; 
	auto as = vector<int>(N);
	for (size_t i = 0; i < N; i++) {
		cin >> as[i];
		sum += as[i];
	}
	int average = round(sum / N);
	int answer = 0;
	for (size_t i = 0; i < N; i++) {
		answer += (as[i] - average)*(as[i] - average);
	}
	cout << answer << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:23: error: 'round' was not declared in this scope
   23 |         int average = round(sum / N);
      |                       ^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int cost_function(int val1,int val2){
	int val = val1-val2;
	return val*val;
}
int main() {
	int n; cin>>n;
	int a[n+2];
	bool allEq = true;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		if(!allEq) continue;
		if(i>0){
			if(a[i]!=a[i-1]) allEq = false;
		}
	}
	
	if(allEq) {
		printf("0\n"); return 0;
	}
	
	int minTotalCost = INT_MAX;
	for(int num = -100; num<=100;num++){
		int cost = 0;
		for(int i=0;i<n;i++) cost+=cost_function(num,a[i]);
		minTotalCost = min(minTotalCost, cost);
	}
	printf("%d\n", minTotalCost);
	return 0;
}#include <bits/stdc++.h>
using namespace std;
int cost_function(int val1,int val2){
	int val = val1-val2;
	return val*val;
}
int main() {
	int n; cin>>n;
	int a[n+2];
	bool allEq = true;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		if(!allEq) continue;
		if(i>0){
			if(a[i]!=a[i-1]) allEq = false;
		}
	}
	
	if(allEq) {
		printf("0\n"); return 0;
	}
	
	int minTotalCost = INT_MAX;
	for(int num = -100; num<=100;num++){
		int cost = 0;
		for(int i=0;i<n;i++) cost+=cost_function(num,a[i]);
		minTotalCost = min(minTotalCost, cost);
	}
	printf("%d\n", minTotalCost);
	return 0;
}

Compiler output:
a.cc:31:2: error: stray '#' in program
   31 | }#include <bits/stdc++.h>
      |  ^
a.cc:31:3: error: 'include' does not name a type
   31 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:33:5: error: redefinition of 'int cost_function(int, int)'
   33 | int cost_function(int val1,int val2){
      |     ^~~~~~~~~~~~~
a.cc:3:5: note: 'int cost_function(int, int)' previously defined here
    3 | int cost_function(int val1,int val2){
      |     ^~~~~~~~~~~~~
a.cc:37:5: error: redefinition of 'int main()'
   37 | int main() {
      |     ^~~~
a.cc:7:5: note: 'int main()' previously defined here
    7 | int main() {
      |     ^~~~
Language: C++

#include <cstdio>
using namespace std;
 
int main() {
    int n;
    scanf("%d", &n);
 
    int a[100];
    for (int i=0; i<n; ++i)
        scanf("%d", &a[i]);
 
    int ans = 100000;
    for (int i=-100; i<=100; i++) {
        int sum = 0;
        for (int j=0; j<N; ++j){
            sum += (a[j]-i)*(a[j]-i);
        }
        if (ans > sum)
            ans = sum;
    }
 
    printf("%d\n", ans);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:25: error: 'N' was not declared in this scope
   15 |         for (int j=0; j<N; ++j){
      |                         ^
Language: C++

#include <cstdio>
using namespace std;
 
int main() {
    int n;
    scanf("%d", &n);
 
    int a[100];
    for (int i=0; i<N; ++i)
        scanf("%d", &a[i]);
 
    int ans = 100000;
    for (int i=-100; i<=100; i++) {
        int sum = 0;
        for (int j=0; j<N; ++j){
            sum += (a[j]-i)*(a[j]-i);
        }
        if (ans > sum)
            ans = sum;
    }
 
    printf("%d\n", ans);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:21: error: 'N' was not declared in this scope
    9 |     for (int i=0; i<N; ++i)
      |                     ^
a.cc:15:25: error: 'N' was not declared in this scope
   15 |         for (int j=0; j<N; ++j){
      |                         ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a[i];

	ll ans = INF;
	REP(i, -100, 100) {
		int cst = 0;
		rep(j, N) {
			cst += (a[j] - i) * (a[j] - i);
		}
		ans = min(ans, cst);
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:26: error: no matching function for call to 'min(ll&, int&)'
   27 |                 ans = min(ans, cst);
      |                       ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:27:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   27 |                 ans = min(ans, cst);
      |                       ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:27:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   27 |                 ans = min(ans, cst);
      |                       ~~~^~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,minN=191,maxN=-1001;
  cin>>n;
  vector<int> a(n);
  for(auto &i:a)
  {
    cin>>i;
    minN = min(minN,i);
    maxN = max(maxN,i);
  }
  if(minN==maxN)
  {
    cout<<"0\n";return 0;
  }
  int ans_val=1e9;
  for(int i=minN;i<=maxN;i++)
  {
    temp = 0;
    for(auto k:a) temp += ((k-i)*(k-i));
    if(temp<ans_val)
    {
      ans_val = temp;
    }
  }
  cout<<ans_val<<"\n";
  
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:5: error: 'temp' was not declared in this scope; did you mean 'tm'?
   22 |     temp = 0;
      |     ^~~~
      |     tm
Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>

#define ll long long
#define endl \'n'
using namespace std;
const ll mod = (ll)10e9+7;
const int INF = 0x3f3f3f3f;
int a[101];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    int ans=INT_MAX;
    for(int i=-100; i<=100; i++)
    {
        int cur=0;
        for(int j=1; j<=n; j++)
        {
            cur += (i-a[j])*(i-a[j]);
        }
        ans = min(ans, cur);
    }
    cout << ans;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:23:13: error: 'INT_MAX' was not declared in this scope
   23 |     int ans=INT_MAX;
      |             ^~~~~~~
a.cc:6:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    5 | #include <vector>
  +++ |+#include <climits>
    6 |
Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>

#define ll long long
#define endl \'n'
using namespace std;
const ll mod = (ll)10e9+7;
const int INF = 0x3f3f3f3f;
int a[101];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    int ans=MAX_INT;
    for(int i=-100; i<=100; i++)
    {
        int cur=0;
        for(int j=1; j<=n; j++)
        {
            cur += (i-a[j])*(i-a[j]);
        }
        ans = min(ans, cur);
    }
    cout << ans;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:23:13: error: 'MAX_INT' was not declared in this scope
   23 |     int ans=MAX_INT;
      |             ^~~~~~~
Language: C++

import java.util.*;
class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = seer.nextInt();
		}
		int mincost = Integer.MAX_VALUE;
		for(int val = -100; val <= 100; val++){
			int cost = 0;
			for(int k: arr){
				cost += (k - val)*(k - val);
			}
			mincost = Integer.min(mincost, cost);
		}
		System.out.println(mincost);
	}

}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:15: error: expected ':' before 'static'
    4 |         public static void main(String[] args) {
      |               ^~~~~~~
      |               :
a.cc:4:33: error: 'String' has not been declared
    4 |         public static void main(String[] args) {
      |                                 ^~~~~~
a.cc:4:42: error: expected ',' or '...' before 'args'
    4 |         public static void main(String[] args) {
      |                                          ^~~~
a.cc:22:2: error: expected ';' after class definition
   22 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:5:17: error: 'Scanner' was not declared in this scope
    5 |                 Scanner seer = new Scanner(System.in);
      |                 ^~~~~~~
a.cc:6:25: error: 'seer' was not declared in this scope
    6 |                 int n = seer.nextInt();
      |                         ^~~~
a.cc:7:20: error: structured binding declaration cannot have type 'int'
    7 |                 int[] arr = new int[n];
      |                    ^~
a.cc:7:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:7:20: error: empty structured binding declaration
a.cc:7:23: error: expected initializer before 'arr'
    7 |                 int[] arr = new int[n];
      |                       ^~~
a.cc:9:25: error: 'arr' was not declared in this scope
    9 |                         arr[i] = seer.nextInt();
      |                         ^~~
a.cc:11:31: error: 'Integer' was not declared in this scope
   11 |                 int mincost = Integer.MAX_VALUE;
      |                               ^~~~~~~
a.cc:14:36: error: 'arr' was not declared in this scope
   14 |                         for(int k: arr){
      |                                    ^~~
a.cc:19:17: error: 'System' was not declared in this scope
   19 |                 System.out.println(mincost);
      |                 ^~~~~~
Language: C++

import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = seer.nextInt();
		}
		int mincost = Integer.MAX_VALUE;
		for(int val = -100; val <= 100; val++){
			int cost = 0;
			for(int k: arr){
				cost += (k - val)*(k - val);
			}
			mincost = Integer.min(mincost, cost);
		}
		System.out.println(mincost);
	}

}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: expected unqualified-id before 'public'
    2 | public class Main {
      | ^~~~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

int main()
{
  cin >> n;
  int a[n+1];
  for (int i=1; i<=n; i++) cin >> a[i];
  int res = 1e9;
  for (int i=-100; i<=100; i++)
  {
    int sum = 0;
    for (int j=1; j<=n; j++)
    {
      sum += (i-a[j])*(i-a[j]);
    }
    res = min(res, sum);
  }
  cout << res;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:10: error: 'n' was not declared in this scope; did you mean 'yn'?
    7 |   cin >> n;
      |          ^
      |          yn
a.cc:9:35: error: 'a' was not declared in this scope
    9 |   for (int i=1; i<=n; i++) cin >> a[i];
      |                                   ^
a.cc:16:17: error: 'a' was not declared in this scope
   16 |       sum += (i-a[j])*(i-a[j]);
      |                 ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, i, ave = 0, sum = 0;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> a[i];
        ave += a[i];
    }
    ave = round((float)ave/n);
    for(i=0; i<n; i++){
        sum += (ave - a[i])*(ave -a[i]);
    }
    cout << sum;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:16: error: 'a' was not declared in this scope
    8 |         cin >> a[i];
      |                ^
a.cc:13:23: error: 'a' was not declared in this scope
   13 |         sum += (ave - a[i])*(ave -a[i]);
      |                       ^
Language: C

#include <stdio.h>

int mean(int a[], int n){
  int sum;
  for(int i=0;i<n;i++)
    sum += a[i];
  return (sum+1) / n;
}

int cost(int a[], int num, int mean){
  int cost = 0;
  for(int i=0;i<num;i++)
    cost += (a[i] - mean) * (a[i] - mean);
  return cost;
}

int main()
{
  int N;
  scanf("%d", &N);
  int a[N];
  for(int i=0;i<N;i++)
    scanf("%d", a[i]);
  int mean = mean(a, N);
  int cost = cost(a, N, mean);
  printf("%d", cost);
  return 0;
}

Compiler output:
main.c: In function 'main':
main.c:24:14: error: called object 'mean' is not a function or function pointer
   24 |   int mean = mean(a, N);
      |              ^~~~
main.c:24:7: note: declared here
   24 |   int mean = mean(a, N);
      |       ^~~~
main.c:25:14: error: called object 'cost' is not a function or function pointer
   25 |   int cost = cost(a, N, mean);
      |              ^~~~
main.c:25:7: note: declared here
   25 |   int cost = cost(a, N, mean);
      |       ^~~~
Language: C

#include <stdio.h>

int mean(int a[], int n){
  int sum;
  for(int i=0;i<n;i++)
    sum += a[i];
  return (sum+1) / n;
}

int cost(int a[], int num, int mean){
  int cost = 0;
  for(int i=0;i<num;i++)
    cost += (a[i] - mean) * (a[i] - mean);
  return cost;
}

int main()
{
  int N;
  scanf("%d", &N);
  for(int i=0;i<N;i++)
    scanf("%d", a[i]);
  int mean = mean(a, N);
  int cost = cost(a, N, mean);
  printf("%d", cost);
  return 0;
}


Compiler output:
main.c: In function 'main':
main.c:22:17: error: 'a' undeclared (first use in this function)
   22 |     scanf("%d", a[i]);
      |                 ^
main.c:22:17: note: each undeclared identifier is reported only once for each function it appears in
main.c:23:14: error: called object 'mean' is not a function or function pointer
   23 |   int mean = mean(a, N);
      |              ^~~~
main.c:23:7: note: declared here
   23 |   int mean = mean(a, N);
      |       ^~~~
main.c:24:14: error: called object 'cost' is not a function or function pointer
   24 |   int cost = cost(a, N, mean);
      |              ^~~~
main.c:24:7: note: declared here
   24 |   int cost = cost(a, N, mean);
      |       ^~~~
Language: C++

#include<iostream>
#include<vector>
using namespace std;

int main(){
	int N,ans=0,minv=(1<<20);
  	cin>>N;
  	vector<int>a(N);
	for(int i=0;i<N;++i)cin>>a[i];
  	for(int i=-100;i<=100;++i){
      	ans=0;
    	for(int j=0;j<N;++j){
        	ans+=pow((i-a[j]),2);
		 }minv=min(minv,ans);
    }cout<<minv<<endl;
  	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:22: error: 'pow' was not declared in this scope
   13 |                 ans+=pow((i-a[j]),2);
      |                      ^~~
Language: Java

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int count = scanner.nextInt();
    List<Integer> numbers = new ArrayList<>();
    long sum = 0;
    for (int ix = 0; ix < count; ix++) {
      int value = scanner.nextInt();
      sum += value;
      numbers.add(value);
    }

    int cost = 0;
    int average = (int)sum / numbers.size();
    for (int num : numbers) {
      int distance = Math.abs(num - average);
      average += (distance * distance);
    }

    System.out.println(average);
  }
}

Compiler output:
Main.java:3: error: cannot find symbol
    Scanner scanner = new Scanner(System.in);
    ^
  symbol:   class Scanner
  location: class Main
Main.java:3: error: cannot find symbol
    Scanner scanner = new Scanner(System.in);
                          ^
  symbol:   class Scanner
  location: class Main
Main.java:6: error: cannot find symbol
    List<Integer> numbers = new ArrayList<>();
    ^
  symbol:   class List
  location: class Main
Main.java:6: error: cannot find symbol
    List<Integer> numbers = new ArrayList<>();
                                ^
  symbol:   class ArrayList
  location: class Main
4 errors
Language: Java

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    int count = scanner.nextInt();
    List<Integer> numbers = new ArrayList<>();
    long sum = 0;
    for (int ix = 0; ix < count; ix++) {
	  int value = scanner.nextInt();
      sum += value;
      numbers.add(value);
    }
 	
    int cost = 0;
    int average = sum / numbers.size();
    for (int num : numbers) {
      int distance = Math.abs(num - average);
      average += (distance * distance);
    }
    
    System.out.println(average);
  }
}

Compiler output:
Main.java:17: error: incompatible types: possible lossy conversion from long to int
    int average = sum / numbers.size();
                      ^
1 error
Language: C++

#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int answer;
    vector<int> ans;
    for(int j=-100;j<101;j++){
        ans[j] = 0;
        for(int i=0;i<N;i++){
        ans[j]+=pow((a[i]-j),2);
    }    
    }
    answer = ans[-100];
    for(int j=-99;j<101;j++){
        if(ans[j-1]>ans[j]) answer= ans[j];
    }
    cout << answer << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:17: error: 'pow' was not declared in this scope
   16 |         ans[j]+=pow((a[i]-j),2);
      |                 ^~~
Language: C++

    #include<iostream>
    #include<string>
    #include<math.h>
    #include<algorithm>
    using namespace std;

    #define sqr(x) ((x)*(x))

    int main(){
        int i, n;
        long long find, find2;
        int a[100];
        cin >> n;
        for(i=0; i<n; i++){
            if((n <= -100) or (n >= 100)){
                continue;
            }
            cin >> a[i];
            if(a[i-1] == a[i]){
                cnt++; //중복 값 검증
            }
        }
        if((cnt == n) and (cnt != 0)){
            cout << 0 << endl; // 중복 값 검증_2
            return 0;
        }
        sort(a, (a + n));
        for(int i=-101; i<101; i++){
            find = 0;
            for(int j = 0; j < n; j++){
                find += sqr(i - a[j]);
            }
            find2 = min(find2, find);
        }
        cout << find2;

    }

Compiler output:
a.cc: In function 'int main()':
a.cc:20:17: error: 'cnt' was not declared in this scope; did you mean 'int'?
   20 |                 cnt++; //중복 값 검증
      |                 ^~~
      |                 int
a.cc:23:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   23 |         if((cnt == n) and (cnt != 0)){
      |             ^~~
      |             int
Language: C++

    #include<iostream>
    #include<string>
    #include<math.h>
    #include<algorithm>
    using namespace std;

    #define sqr(x) ((x)*(x))

    int main(){
        int i, n;
        long long find, find2;
        int a[100];
        cin >> n;
        for(i=0; i<n; i++){
            if((n <= -100) or (n >= 100)){
                continue;
            }
            cin >> a[i];
            if(a[i-1] == a[i]){
                cnt++; //중복 값 검증
            }
        }
        if((cnt == n) and (cnt != 0)){
            cout << 0 << endl; // 중복 값 검증_2
            exit();
        }
        sort(a, (a + n));
        for(int i=-101; i<101; i++){
            find = 0;
            for(int j = 0; j < n; j++){
                find += sqr(i - a[j]);
            }
            find2 = min(find2, find);
        }
        cout << find2;

    }

Compiler output:
a.cc: In function 'int main()':
a.cc:20:17: error: 'cnt' was not declared in this scope; did you mean 'int'?
   20 |                 cnt++; //중복 값 검증
      |                 ^~~
      |                 int
a.cc:23:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   23 |         if((cnt == n) and (cnt != 0)){
      |             ^~~
      |             int
a.cc:25:17: error: too few arguments to function 'void exit(int)'
   25 |             exit();
      |             ~~~~^~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/stdlib.h:756:13: note: declared here
  756 | extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
      |             ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);
 
	int N;
	cin >> N;
	int a[100];
	for(int i=0; i<N; i++) cin >> a[i];
	LL ans = LL_MAX;
	for(int i=-100; i<=100; i++){
		LL tmp = 0;
		for(int j=0; j<N; j++){
			tmp += (i-a[j])*(i-a[j]);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
 
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:9: error: 'LL' was not declared in this scope
   12 |         LL ans = LL_MAX;
      |         ^~
a.cc:14:19: error: expected ';' before 'tmp'
   14 |                 LL tmp = 0;
      |                   ^~~~
      |                   ;
a.cc:16:25: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   16 |                         tmp += (i-a[j])*(i-a[j]);
      |                         ^~~
      |                         tm
a.cc:18:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   18 |                 ans = min(ans, tmp);
      |                 ^~~
      |                 abs
a.cc:18:32: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   18 |                 ans = min(ans, tmp);
      |                                ^~~
      |                                tm
a.cc:20:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   20 |         cout << ans << endl;
      |                 ^~~
      |                 abs
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 100
#define Pair pair<int,int>

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};


int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = MM;
    for(int i = -100; i <= 100; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum += (i-a[j])*(i-a[j]);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:16: error: 'a' was not declared in this scope
   17 |         cin >> a[i];
      |                ^
a.cc:23:23: error: 'a' was not declared in this scope
   23 |             sum += (i-a[j])*(i-a[j]);
      |                       ^
Language: C

#include <stdio.h>
#include <math.h>

int main(void){
	int n,i,j,min=4000000,res,a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(j=-100;j<=100;j++){
		res = 0
		for(i=0;i<n;i++){
			res += (a[i] - j) * (a[i] - j);
		}
		if(res < min)min = res;
	}
	printf("%d\n",min);
}

Compiler output:
main.c: In function 'main':
main.c:11:24: error: expected ';' before 'for'
   11 |                 res = 0
      |                        ^
      |                        ;
   12 |                 for(i=0;i<n;i++){
      |                 ~~~
Language: C

#include <stdio.h>
#include <math.h>

int main(void){
	int n,i,j,min=4000000,res;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf",&a[i]);
	}
	for(j=-100;j<=100;j++){
		res = 0
		for(i=0;i<n;i++){
			res += (a[i] - j) * (a[i] - j);
		}
		if(res < min)min = res;
	}
	printf("%d\n",min);
}

Compiler output:
main.c: In function 'main':
main.c:8:30: error: 'a' undeclared (first use in this function)
    8 |                 scanf("%lf",&a[i]);
      |                              ^
main.c:8:30: note: each undeclared identifier is reported only once for each function it appears in
main.c:11:24: error: expected ';' before 'for'
   11 |                 res = 0
      |                        ^
      |                        ;
   12 |                 for(i=0;i<n;i++){
      |                 ~~~
Language: C++

v]#include <bits/stdc++.h>
using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    sort(A.begin(), A.end());
    int cost=pow(10,9);
    for(int x=A[0]; x<A[N-1]+1; x++){
        
        int tmp=0;
        for(int i=0; i<N; i++) tmp += (A[i]-x)*(A[i]-x);
        cost=min(tmp,cost);

    }

    cout << cost << endl;
    return 0;
}

Compiler output:
a.cc:1:3: error: stray '#' in program
    1 | v]#include <bits/stdc++.h>
      |   ^
a.cc:1:1: error: 'v' does not name a type
    1 | v]#include <bits/stdc++.h>
      | ^
a.cc: In function 'int main()':
a.cc:6:5: error: 'cin' was not declared in this scope
    6 |     cin >> N;
      |     ^~~
a.cc:7:5: error: 'vector' was not declared in this scope
    7 |     vector<int> A(N);
      |     ^~~~~~
a.cc:7:12: error: expected primary-expression before 'int'
    7 |     vector<int> A(N);
      |            ^~~
a.cc:8:35: error: 'A' was not declared in this scope
    8 |     for(int i=0; i<N; i++) cin >> A[i];
      |                                   ^
a.cc:10:10: error: 'A' was not declared in this scope
   10 |     sort(A.begin(), A.end());
      |          ^
a.cc:10:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   10 |     sort(A.begin(), A.end());
      |     ^~~~
      |     short
a.cc:11:14: error: 'pow' was not declared in this scope
   11 |     int cost=pow(10,9);
      |              ^~~
a.cc:16:14: error: 'min' was not declared in this scope; did you mean 'main'?
   16 |         cost=min(tmp,cost);
      |              ^~~
      |              main
a.cc:20:5: error: 'cout' was not declared in this scope; did you mean 'cost'?
   20 |     cout << cost << endl;
      |     ^~~~
      |     cost
a.cc:20:21: error: 'endl' was not declared in this scope
   20 |     cout << cost << endl;
      |                     ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum++;
  }
  int x = sum / n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += abs(a[i] - sum);
  }
  cout < ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:14: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'
   18 |   cout < ans << endl;
      |          ~~~~^~~~~~~
Language: C++

// Created by sz
#include <bits/stdc++.h>
using namespace std;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<int> a(n);
    int sum = 0;
    for(int i = 0; i< n;i++){cin>>a[i];sum+= a[i];}
    
    int avg = sum/n;
    int less_avg = avg-1, more_avg = avg + 1;
    
    int sum_avg = 0, sum_le = 0, sum_mo = 0;
    for(int i = 0; i < n; i++){
        sum_avg += (a[i] - avg)*(a[i] - avg);
        sum_le +=(a[i] - less_avgavg)*(a[i] - less_avg);
        sum_mo +=(a[i] - more_avg)*(a[i] - more_avg);
    }
    cout<<min(min(sum_avg, sum_mo), sum_le)<<endl;
    
    
    
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:26: error: 'less_avgavg' was not declared in this scope; did you mean 'less_avg'?
   24 |         sum_le +=(a[i] - less_avgavg)*(a[i] - less_avg);
      |                          ^~~~~~~~~~~
      |                          less_avg
Language: C++

# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    optimize_cin();
    int N; cin >> N;
    vector<int> a;
    a.resize(N);
    rep (i, N) { cin >> a[i]; }

    sort(ALL(a));

    int d = abs(a[a.size() - 1] - a[0]);
    bool can = false;
    if (d % 2) // 奇数
    {
        int target = d / 2 + a[0];
        rep (i, N)
        {
            if (target == a[i])
            {
                can = true;
                break;
            }
        }

        if (can)
        {
            int cost = 0;
            rep (i, N)
            {
                cost += (a[i] - target)*(a[i] - target);
            }
            cout << cost << "\n";
        }
        else
        {
            target += (a[i] < 0 && a[a.size()-1] < 0) ? -1 : 1;
            int cost = 0;
            rep (i, N)
            {
                cost += (a[i] - target)*(a[i] - target);
            }
            cout << cost << "\n";
        }
    }
    else
    {
        int target = d / 2 + a[0];
        int cost = 0;
        rep (i, N)
        {
            cost += (a[i] - target)*(a[i] - target);
        }
        cout << cost << "\n";
    }


    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:50:26: error: 'i' was not declared in this scope
   50 |             target += (a[i] < 0 && a[a.size()-1] < 0) ? -1 : 1;
      |                          ^
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> vc;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		vc.push_back(a);
	}
	int Min = 100000000;
	for (int j = -100; j <= 100; j++) {
		int cost = 0;
		for (int i = 0; i < N; i++) {
			int dif = vc[i] - j;
			cost += pow(dif, 2);
		}
		Min = min(Min, cost);
	}
	cout << Min << endl;
	//system("pause");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:33: error: 'pow' was not declared in this scope
   18 |                         cost += pow(dif, 2);
      |                                 ^~~
Language: C++

#include<bits/stdc++.h>
#include<string>
using namespace std;
int n;
int main(){
  cin >> n;
  int a;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    int cost = 0;
    for(int j = i+1; j < n; j++){
      if(a[i] == a[j]) {
        a[j] = a[i];
        cost += pow(a[j] - a[i], 2);
        
      }
    }
  }
  cout << cost << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:13: error: invalid types 'int[int]' for array subscript
    9 |     cin >> a[i];
      |             ^
a.cc:12:11: error: invalid types 'int[int]' for array subscript
   12 |       if(a[i] == a[j]) {
      |           ^
a.cc:12:19: error: invalid types 'int[int]' for array subscript
   12 |       if(a[i] == a[j]) {
      |                   ^
a.cc:13:10: error: invalid types 'int[int]' for array subscript
   13 |         a[j] = a[i];
      |          ^
a.cc:13:17: error: invalid types 'int[int]' for array subscript
   13 |         a[j] = a[i];
      |                 ^
a.cc:14:22: error: invalid types 'int[int]' for array subscript
   14 |         cost += pow(a[j] - a[i], 2);
      |                      ^
a.cc:14:29: error: invalid types 'int[int]' for array subscript
   14 |         cost += pow(a[j] - a[i], 2);
      |                             ^
a.cc:19:11: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   19 |   cout << cost << endl;
      |           ^~~~
      |           cosl
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int m=1000000;
  vector<int> a(102),s(202);
  for(int i-1;i<=N;i++){cin >> a[i];}
  for(int i=-100;i<=100;i++){s[i]=0;}
  for(int i=-100;i<=100;i++){
    for(int j=1;j<=N;j++){
      s[i]+=(i-a[j])*(i-a[j]);
    }
    if(m>s[i]){m=s[i];}
  }
  cout << m << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:12: error: expected ';' before '-' token
    9 |   for(int i-1;i<=N;i++){cin >> a[i];}
      |            ^
      |            ;
a.cc:9:19: error: expected ')' before ';' token
    9 |   for(int i-1;i<=N;i++){cin >> a[i];}
      |      ~            ^
      |                   )
a.cc:9:20: error: 'i' was not declared in this scope
    9 |   for(int i-1;i<=N;i++){cin >> a[i];}
      |                    ^
Language: C++

#include<iostream>
using namespace std;

int main(void)
{
        int N;
        cin >> N;
        int cost[N][201];
        int now;

        for(int i=1;i<=N;i++)
        {
                cin >> now;
                for(int j=-100;j<=100;j++)
                {
                        cost[i-1][j+101-1]=(now-j)*(now-j);
                }
        }

        int total_cost[201];
        for(int i=1;i<=201;i++)
        {
                total_cost[i-1]=0;
                for(int j=1;j<=N;j++)
                {
                        total_cost[i-1]+=cost[j-1][i-1];
                }
        }
        sort(total_cost,total_cost+201);
        cout << total_cost[0] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   29 |         sort(total_cost,total_cost+201);
      |         ^~~~
      |         short
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
            a[i]=0;
    }
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>a[i];
        sum+=a[i];
    }
    float k=(float)sum/(float)N;
    if(k>sum/N+0.5){
        int ave=sum/N+1;
    }else{
        int ave=sum/N;
    }

    int kei=0;
    for(int i=0;i,N;i++){
        kei+=(a[i]-ave)*(a[i]-ave);
    }
    cout<<kei<<endl;





 return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:20: error: 'ave' was not declared in this scope
   24 |         kei+=(a[i]-ave)*(a[i]-ave);
      |                    ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int a[105];
int f(int k)
{
    int ans=0;
    for(int i=0;i<n;i++)
        ans+=(k-a[i])*(k-a[i]);
    return ans;
}
int main()
{
    int n,sum=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i],sum+=a[i];
    int k;
    if(sum>0) k=ceil(sum*1.0/n);
    else k=sum/n;
    int ans=1e9;
    ans=min(ans,f(k));
    ans=min(ans,f(k-1));
    ans=min(ans,f(k+1));
    printf("%d\n",ans);
}


Compiler output:
a.cc: In function 'int f(int)':
a.cc:7:19: error: 'n' was not declared in this scope
    7 |     for(int i=0;i<n;i++)
      |                   ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

static const int INF = (1<<29)
int N;
int a[109];

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a[i];
  }

  int sum=0;
  for(int i=0;i<N;i++) sum += a[i];

  int ans = INF;
  for(int i=(-100);i<=100;i++){
    int cost = 0;
    for(int j=0;j<N;j++){
      cost += (a[j]-i) * (a[j]-i);
    }
    ans = min(ans,cost);
  }

  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc:5:1: error: expected ',' or ';' before 'int'
    5 | int N;
      | ^~~
a.cc: In function 'int main()':
a.cc:9:10: error: 'N' was not declared in this scope
    9 |   cin >> N;
      |          ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
inline int sqr(int x) return x*x;
int main()
{
	int n,a[101];
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		ans+=sqr(a[i]-0);
	}
	for(x=-100;x<=100;x++)
	{
		int tmp=0;
		for(int i=1;i<=n;i++)
		{
			tmp+=sqr(a[i]-x);
		}
		ans=min(ans,tmp);
	}
	cout<<ans;
}


Compiler output:
a.cc: In function 'int sqr(int)':
a.cc:3:23: error: named return values are no longer supported
    3 | inline int sqr(int x) return x*x;
      |                       ^~~~~~
a.cc:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
   24 | }
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin >> N;
    long long sum{}, result{}, input;
    vector<long long> a(N);
    for(auto& item: a) {
        cin >> input;
        item = input;
        sum += input;
    }
    if (sum % N) {
        auto y = sum / N;
        size_t _1{};
        for(auto&& x: a) {
             _1 += pow(x - y, 2);
        }
        y = sum / N + 1;
        size_t _2{};
        for(auto&& x: a) {
            _2 += pow(x - y, 2);
        }
        result = std::min(_1, _2);
    }
    else {
        for(auto&& x: a) {
            result += pow(x - y, 2);
        }
    }
    cout << result << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:31: error: 'y' was not declared in this scope
   28 |             result += pow(x - y, 2);
      |                               ^
Language: C++

#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
#define ll long long
#define W 1000000007
using namespace std;

int main(){
	int n,a,sum1=0,sum2=0;
	cin>>n;
	lp2(i,n){
		cin>>a;
		sum1+=a;
		sum2+=pow(a,2);
	}
	sum1= pow(sum1,2);
	double ans = sum2 - sum1/n;
	int num=(ans*10)%10;
	if(num!=0)ans++;
	int ans1 = ans;
	cout<<ans<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:25: error: invalid operands of types 'double' and 'int' to binary 'operator%'
   18 |         int num=(ans*10)%10;
      |                 ~~~~~~~~^~~
      |                     |    |
      |                     |    int
      |                     double
Language: C++

#include <iostream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

typedef long long ll;

using namespace std;

int main(){
  int N;
  cin>>N;
  int a[N];
  for(int i=0;i<N;i++)cin>>a[i];
  int ans=INT_MAX;
  for(int i=-100;i<=100;i++){
    int cost=0;
    for(int j=0;j<N;j++)cost+=(a[j]-i)*(a[j]-i);
    if(cost<ans)ans=cost;
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:11: error: 'INT_MAX' was not declared in this scope
   18 |   int ans=INT_MAX;
      |           ^~~~~~~
a.cc:8:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    7 | #include <string.h>
  +++ |+#include <climits>
    8 |
Language: C++

#include<iostream>
#include<vector>
using namespace std;
int main(){
	int s=0,n;
	vector<int> a;
	cin>>n;
	for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		a.push_back(temp);
		s+=temp;
	}
	s/=n;
	int res=0;
	for(int i=s;i<=s+1;i++){
		for(int j=0;j<n;j++){
			res+=(i-a[j])*(i-a[j]);
		}if(i==s){
			int k=res
		}else if(k<res){
			cout<<k;
		}else{
			cout<<res;
		}
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:17: error: expected ',' or ';' before '}' token
   21 |                 }else if(k<res){
      |                 ^
a.cc:21:26: error: 'k' was not declared in this scope
   21 |                 }else if(k<res){
      |                          ^
Language: C++

#include <iostream>

int main()
{
	int total = 0;

	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
		total += a[i];
	}

	int ave;

	if (total%N == 0)
		ave = total / N;
	else
		if (total > 0)
			ave = total / N + 1;
		else
			ave = total / N - 1;

	int ans = 0;
	for (int i = 0; i < N; i++)
		ans += (ave - a[i])*(ave - a[i]);

	std::cout << ans << '\n';

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:21: error: 'N' was not declared in this scope
    7 |         std::cin >> N;
      |                     ^
a.cc:9:29: error: 'a' was not declared in this scope
    9 |                 std::cin >> a[i];
      |                             ^
a.cc:25:31: error: 'a' was not declared in this scope
   25 |                 ans += (ave - a[i])*(ave - a[i]);
      |                               ^
Language: C++

#include <iostream>
#include <cmath>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::pow;
using std::vector;

int main() {
  int n, min, max, ave, cost;
  vector<int> a;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    a.push_back(num);
  }

  sort(a.begin(), a.end() );
  max = a.back();
  min = a.front();

  ave = ceil((double(max) + double(min)) / 2.0);

  // 書き換え
  for (int x : a) {
    cost += pow(ave - x, 2);
  }

  cout << cost << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:3: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   23 |   sort(a.begin(), a.end() );
      |   ^~~~
      |   sqrt
Language: C++

#include <iostream>
#include <cmath>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::pow;
using std::vector;

int main() {
  int n, min, max, ave, cost;
  vector<int> a;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    a.push_back(num);
  }
  
  sort(a.begin(), a.end() );
  max = a.back();
  min = a.front();

  ave = (max + min) / 2;

  // 書き換え
  for (int x : a) {
    cost += pow(ave - x, 2);
  }

  cout << cost << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:3: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   23 |   sort(a.begin(), a.end() );
      |   ^~~~
      |   sqrt
Language: C++

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    int main()
    {
    int n,cost=0;
    float m=0.0;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++)
    {
    scanf("%d",&a[i]);
    m+=a[i];
    }
     
    m/=n;
     
    m=ceil(m);
     
    for(int i=0;i<n;i++)
    cost+=((a[i]-m)*(a[i]-m));
    printf("%d",cost);
    return 0;
    }

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int n,cost=0;
float m=0.0;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
m+=a[i];
}

m/=n;
int p;

p=m;
if((m-p)>0.5)p++;

for(int i=0;i<n;i++)
cost+=((a[i]-p)*(a[i]-p));
printf("%d",cost);
return 0;
}


Compiler output:
a.cc:31:5: error: redefinition of 'int main()'
   31 | int main()
      |     ^~~~
a.cc:5:9: note: 'int main()' previously defined here
    5 |     int main()
      |         ^~~~
Language: C++

#include <iostream>
#include <string>
#include <cmath>
int main(){
   int a[100];
   int n,ans=INT_MAX;

   std::cin>>n;

   for(int i=0;i<n;++i){
       std::cin>>a[i];
   }

   for(int i=-100;i<100;++i){
       int tmp=0;
       for(int j=0;j<n;++j){
            tmp+=std::pow(i-a[j],2);                
       }
       if(ans>tmp){
           ans=tmp;

       }

   }
   std::cout<<ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:14: error: 'INT_MAX' was not declared in this scope
    6 |    int n,ans=INT_MAX;
      |              ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include <cmath>
  +++ |+#include <climits>
    4 | int main(){
Language: C++

#include <iostream>                                                                             
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int N;
    cin >> N;
    
    vector<int> A;
    int num;
    for(int i=0; i<N; i++){
        cin >> num;
        A.push_back(num);
    }

    std::sort(A.begin(), A.end() );

    int min_cost;
    
    int cost, target_num;　// temp cost, temp target_num
    for(int i = A.front(); i <= A.back(); i++){
        cost = 0;
        target_num = i;
    
        for(vector<int>::iterator it = A.begin(); it != A.end(); it++){
            cost += (*it - target_num) * (*it - target_num);
        }
        if ( i == A.front() || min_cost > cost){
            min_cost = cost;
        }
    }
    cout << min_cost << endl;

    return 0;
}

Compiler output:
a.cc:22:26: error: extended character 　 is not valid in an identifier
   22 |     int cost, target_num;　// temp cost, temp target_num
      |                          ^
a.cc: In function 'int main()':
a.cc:22:26: error: '\U00003000' was not declared in this scope
   22 |     int cost, target_num;　// temp cost, temp target_num
      |                          ^~
a.cc:23:28: error: 'i' was not declared in this scope
   23 |     for(int i = A.front(); i <= A.back(); i++){
      |                            ^