criyle/codenet-compile-errors huggingface dataset:
Language: Java

import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		int sum = 0, ans = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			sum += A[i];
		}
		Set<Integer> cd = new HashSet<>();
		for(int i = 1; i <= Math.sqrt(sum); i++)
			if(sum % i == 0) {
				cd.add(i);
				cd.add(sum/i);
			}
		for(int i : cd) {
			int[] B = new int[N];
			for(int j = 0; j < N; j++)
				B[j] = A[j] % i;
			Arrays.sort(B);
			int[] M = new int[N+1];
			int[] P = new int[N+1];
			for(int j = 0; j < N; j++)
				M[j+1] = M[j] + B[j];
			for(int j = N-1; j >= 0; j--)
				if(B[j] != 0)
					P[j] = P[j+1] + (i - B[j]);
			for(int j = 1; j < N; j++)
				if((M[j] - P[j]) % i == 0)
					min = Math.min(min, Math.max(M[j], P[j]));
			if(min <= K)
				ans = Math.max(ans, i);
		}
		System.out.println(ans);
	}

}

Compiler output:
Main.java:34: error: cannot find symbol
					min = Math.min(min, Math.max(M[j], P[j]));
					^
  symbol:   variable min
  location: class Main
Main.java:34: error: cannot find symbol
					min = Math.min(min, Math.max(M[j], P[j]));
					               ^
  symbol:   variable min
  location: class Main
Main.java:35: error: cannot find symbol
			if(min <= K)
			   ^
  symbol:   variable min
  location: class Main
3 errors
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;
 
vector<ll> divisor(ll a){
    vector<ll> res;
    for(ll i=2; i<=sqrt(a); i++){
        if(a%i==0){
            res.push_back(i);
            if(i!=a/i) res.push_back(a/i);
        }
    }
    res.push_back(a);
    sort(all(res));
    return res;
}


int main(){
    int n,k; cin >> n >> k;
    vector<int> a(n);
    int sum=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }

    vector<int> p=divisor(sum);
    reverse(all(p));

    rep(i,p.size()){
        vector<ll> moda;
        rep(j,n){
            if(a[j]%p[i]) moda.push_back(a[j]%p[i]);
        }
        int ms=moda.size();
        /*if(!ms){
            cout << p[i] << endl;
            return 0;
        }*/
        sort(all(moda));
        vector<ll> rmoda(ms+1);
        rmoda[0]=0;
        rep(j,ms) rmoda[j+1]=p[i]-moda[j]+rmoda[j];
        ll now=0;
        rep(j,ms){
            now+=moda[j];
            if(now==rmoda[ms]-rmoda[j+1]){
                if(now<=k){
                    cout << p[i] << endl;
                    return 0;
                }
                break;
            }
            else if(now>rmoda[ms]-rmoda[j+1]) break;
        }
    }
    cout << 1 << endl;
return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:26: error: conversion from 'vector<long long int>' to non-scalar type 'vector<int>' requested
   34 |     vector<int> p=divisor(sum);
      |                   ~~~~~~~^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k,a[500];
	cin>>n>>k;
	ll sum1=0;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		sum1+=a[i];
	}
	vector<ll>sq;
	for(ll i=1;i<=sqrt(sum1);i++){
		if(sum1%i==0){
			sq.push_back(i);
			sq.push_back(sum1%i);
		}
	}
	sort(sq.begin(),sq.end());
	reverse(sq.begin(),sq.end());
	for(ll i=0;i<sq.sizer();i++){
		ll now=sq[i];
		if(sum1%now!=0){
			continue;
		}
		ll b[500];
		ll sum2=0;
		for(ll j=0;j<n;j++){
			b[j]=abs(now-a[j]%now);
			sum2+=b[j];
		}
		ll sum3=0;
		for(ll j=0;j<n;j++){
			sum2-=b[j];
			sum3+=a[j]%now;
			if(max(sum3,sum2)<=k){
				cout <<now;
				return 0;
			}
		}
	}
	// your code goes here
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:25: error: 'class std::vector<long long int>' has no member named 'sizer'; did you mean 'size'?
   24 |         for(ll i=0;i<sq.sizer();i++){
      |                         ^~~~~
      |                         size
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define MAXN 500
#define LL long long int

int N, K, A[MAXN + 3], sumA;

bool check(int g) {
    int r[MAXN + 3];
    LL sumNeg[MAXN + 3], sumPos[MAXN + 3];

    for (int i = 1; i <= N; i++)
        r[i] = A[i]%g;

    sort(r + 1, r + N + 1);

    sumNeg[0] = 0;
    for (int i = 1; i <= N; i++) sumNeg[i] = sumNeg[i - 1] + r[i];

    sumPos[N + 1] = 0;
    for (int i = N; i >= 1; i--) sumPos[i] = sumPos[i + 1] + (g - r[i]);

    for (int i = 1; i <= N - 1; i++) {
        if (sumNeg[i] == sumPos[i + 1] && sumNeg[i] <= K)
            return true;
    }

    //Corner case, no need to perform operation
    if (sumNeg[N] == 0)
        return true;

    return false;
}

int main() {
    cin >> N >> K;

    sumA = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        sumA += A[i];
    }

    if (DEBUG) {
        cout << "sumA: " << sumA << endl;
    }

    int answer = 0;
    for (int g = 1; g * g <= sumA; g++) {
        if (sumA % g == 0) {
            if (check(g)) answer = max(answer, g);
            if (check(sumA/g)) answer = max(answer, sumA/g);
        }
    }

    cout << answer << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:44:9: error: 'DEBUG' was not declared in this scope
   44 |     if (DEBUG) {
      |         ^~~~~
Language: C++

#include <cstdio>

using namespace std;

int main()
{
  int n, k;
  int a[500], b[500];
  long long S = 0;
  
  scanf("%d %d", &n, &k);
  
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    S += a[i];
  }
  
  vector<long long> div;
  for (long long i = 1; i * i <= S; i++) {
   	if (S % i == 0) {
      div.push_back(i);
      if (i != S / i) div.push_back(S / i);
    }
  }
  
  sort(div.rbegin(), div.rend());
  
  for (int i = 0; i < div.size(); i++) {
    for (int j = 0; j < n; j++) {
      b[j] = a[j] % div[i];
    }
    sort(b, b + n);
    long long cnt1 = 0, cnt2 = 0;
    for (int j = 0; j < n; j++) {
      if (cnt1 + b[j] <= k) cnt1 += b[j];
      else cnt2 += (div[i] - b[j]) % div[i];
    }
    if (min(cnt1, cnt2) <= k) {
      printf("%lld\n", div[i]);
      break;
    }
  }
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:3: error: 'vector' was not declared in this scope
   18 |   vector<long long> div;
      |   ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <cstdio>
  +++ |+#include <vector>
    2 | 
a.cc:18:10: error: expected primary-expression before 'long'
   18 |   vector<long long> div;
      |          ^~~~
a.cc:21:7: error: 'div' was not declared in this scope
   21 |       div.push_back(i);
      |       ^~~
a.cc:26:8: error: 'div' was not declared in this scope
   26 |   sort(div.rbegin(), div.rend());
      |        ^~~
a.cc:26:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   26 |   sort(div.rbegin(), div.rend());
      |   ^~~~
      |   short
a.cc:38:9: error: 'min' was not declared in this scope; did you mean 'main'?
   38 |     if (min(cnt1, cnt2) <= k) {
      |         ^~~
      |         main
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

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

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(rall(ret));
  return (ret);
}



int main(){
  ll int n ,k;
  cin>>n>>k;
  ll int a[n];
  ll int s=0;
  ll int m=0;
  ll int ans=0;
  rep(i,n){
    ll int tmp;
    cin>>tmp;
    s+=tmp;
    a[i]=tmp;
    m = max(m,tmp);
  }
  if(s-m<=k){
    cout<<s<<endl;
  }
  else{
    vector< int64_t > v=divisor(s);
    for (const auto& e : v) {
      if(m+k<e){
        continue;
      }
      ll int s_e=0;
      rep(i,n){
        if(a[i]%e!=0){
          if(abs((a[i]/e)*e-a[i])>abs((a[i]/e+1)*e-a[i])){
            s_e += (a[i]/e+1)*e-a[i]);
          }
          else{
            s_e+=(a[i]/e)*e-a[i];
          }

        }
        
      }
      if(abs(s_e)<=k){
        ans=e;
        break;
      }
      

    }
    cout<<ans<<endl;
  }
  
  

}

Compiler output:
a.cc: In function 'int main()':
a.cc:66:37: error: expected ';' before ')' token
   66 |             s_e += (a[i]/e+1)*e-a[i]);
      |                                     ^
      |                                     ;
Language: C++

//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,k;
vi a;

vi divs(int x){
    vi ret;
    for (int i = 1; i*i <= x; i++){
        if (x%i == 0){
            ret.pb(i);
            ret.pb(x/i);
        }
    }
    sort(all(ret));
    uniq(ret);
    return ret;
}
bool f(int x){
    auto ai = a;
    int op = 0;
    REP(i,n) ai[i] %= x;
    sort(all(ai));
    int ac = accumulate(all(ai),0LL) / x;
    // cerr << x << " " << ac << endl;
    REPS(i,ac) op += x - ai[n-i];
    return op <= k;
}
 
signed main(){
    I(n); I(k);
    a.resize(n);
    REP(i,n) I(a[i]);
    int asum = accumulate(all(a), 0LL);
    auto dv = divs(asum);
    int ok = 0;
    int dlen = sz(dv);
    int ok = 0;
    int ng = dlen;
    while(ng-ok > 1){
        int mid = (ok+ng)/2;
        (f(dv[mid]) ? ok : ng) = mid;
    }
    cout << dv[ok] << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:78:9: error: redeclaration of 'll ok'
   78 |     int ok = 0;
      |         ^~
a.cc:76:9: note: 'll ok' previously declared here
   76 |     int ok = 0;
      |         ^~
Language: C++

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

using int64 = long long;

vector<int64> divisor(int64 n) {
    vector<int64> res;
    for (int64 i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i * i != n) res.emplace_back(n / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(){
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    int54 sum = 0;
    for (int i = 0; i < N; ++i) sum += A[i];
    
    vector<int64> div = divisor(sum);
    sort(div.rbegin(), div.rend());
    
    for (auto& d: div) {
        vector<int64> m(N);
        int64 sum = 0;
        for(int i = 0; i < N; ++i) {
            m[i] = A[i] % d;
            sum += m[i];
        }
        sort(m.ebegin(), m.rend());
        int64 t = sum;
        for (int i = 0; i < t / d; ++i) sum -= m[i];
        
        if (sum <= K) {
            cout << d << endl;
            return 0;
        }
        
        
        
    } 
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:5: error: 'int54' was not declared in this scope; did you mean 'int64'?
   23 |     int54 sum = 0;
      |     ^~~~~
      |     int64
a.cc:24:33: error: 'sum' was not declared in this scope
   24 |     for (int i = 0; i < N; ++i) sum += A[i];
      |                                 ^~~
a.cc:26:33: error: 'sum' was not declared in this scope
   26 |     vector<int64> div = divisor(sum);
      |                                 ^~~
a.cc:36:16: error: 'class std::vector<long long int>' has no member named 'ebegin'; did you mean 'begin'?
   36 |         sort(m.ebegin(), m.rend());
      |                ^~~~~~
      |                begin
Language: C++

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N;

int main() {
    ll n, k;
    cin >> n >> k;

    vl a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    vl yakusu;  // yakusu[i] : sumのi番目(iは0-index)の約数
    for(ll i = 1; i*i <= sum; i++) {
        if(sum%i == 0) {
            yakusu.pb(i);
            if(i*i != sum) {
                yakusu.pb(sum/i);
            }
        }
    }

    ll ans = 1;
    rep(I, yakusu.size()) {
        ll d = yakusu[I];
        vl r(n);
        rep(i, n) {
            r[i] = a[i]%d;
        }
        sort(all(r));

        ll tot = 0;
        rep(i, n) {
            tot += r[i];
        }

        ll l = n - tot/d;
        ll need = 0;
        rep(i, l) {
            need += r[i];
        }
        
        if(need <= k) {
            ans = max(ans, d);
        }
    }
    
    out(ans);
    re0;
}

Compiler output:
a.cc:25:10: error: uninitialized 'const MAX_N' [-fpermissive]
   25 | const ll MAX_N;
      |          ^~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    vector<ll>y(0);
    for(int i=1;i<sqrt(sum);i++){
        if(sum%i==0){
            if(sum/i!=i)y.pb(sum/i)
            y.pb(i);
        }
    }
    ll ans=1;
    for(int i=0;i<y.size();i++){
        ll s=y[i];
        priority_queue<ll>pq;
        ll ss=0;
        for(int j=0;j<n;j++){
            ss+=a[j]%s;
            pq.push(a[j]%s);
        }
        ll cnt=ss;
        for(int j=0;j<ss/sum;j++){
            cnt+=sum-2*pq.top();
            pq.pop();
        }
        if(cnt<=2*k){
            ans=y[i];
        }
    }
    cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:36: error: expected ';' before 'y'
   16 |             if(sum/i!=i)y.pb(sum/i)
      |                                    ^
      |                                    ;
   17 |             y.pb(i);
      |             ~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    vector<ll>y(10000);
    ll j=0;
    for(int i=1;i<sum+1;i++){
        if(sum%i){
            y[j]=i;
            j++;
        }
    }
    ll ans=1;
    for(int i=0;y[i];i++){
        ll s=y[i];
        priority_queue<ll>pq;
        ll ss=0;
        for(int j=0;j<n;j++){
            ss+=a[i]%ss;
            pq.push(ss%sum);
        }
        ll cnt=ss;
        for(int j=0;j<ss/sum;j++){
            cnt+=sum-2*pq.top();
            pq.pop();
        }
        if(cnt<=2*k){
            ans=i;
        }
    }
    cout<<i<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:11: error: 'i' was not declared in this scope
   38 |     cout<<i<<endl;
      |           ^
Language: C++

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(INT(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();

vector<INT> divisor(INT n){
    vector<INT> ret={};
    for (INT i=1;i<pow(n,0.5);i++){
        if (n%i==0){
            ret.push_back(i);
            if (n!=i*i){
                ret.push_back(n/i);
            }
        }
    }
    sort(ret.begin(),ret.end());
    return ret;
}


int main()
{
    INT N,K;
    cin>>N>>K;
    INT A[N];
    REP(i,N) cin>>A[i];
    INT total=0;
    REP(i,N) total+=A[i];
    vector<INT> div = divisor(total);
    INT ans=0;
    INT plus=0,minus=0;
    for(INT i=(div.size()-1);i>=0;--i){
        vector <INT> tmpvec;
        REP(j,N){
            tmpvec.push_back(A[j]%div[i]);
        }
        sort(tmpvec.begin(),tmpvec.end());
        plus=0,minus=0;
        REP(j,N){
            if (plus<=K){
                minus += tmpvec[j];
            }else{
                plus += div[i]-tmpvec[j];
            }
        }

        if (tmp<=2*K){
            ans = div[i];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:52:13: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   52 |         if (tmp<=2*K){
      |             ^~~
      |             tm
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int sz = 500;


bool check(vector<int>& a, long long k, long long d)
{
	int n = a.size();
	vector<ll> r;
	for (int i = 0; i < n; i++)if (a[i] % d)r.emplace_back(a[i] % d);
	n = r.size();
	if (n == 0)return 1;
	sort(begin(r), end(r));
	ll s = 0;
	for (int i = 0; i < n; i++)s += d - r[i];
	ll x = 0;
	for (int i = 0; i < n; i++)
	{
		x += r[i];
		s -= d - r[i];
		if (x == s)return x<=k;
	}
	return 1;
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector<ll > a(n);
	ll sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >>a[i];
		sum += a[i];
	}
	ll ans = 1;
	for (ll x = 1; x * x <= sum; x++)
	{
		if (sum % x == 0)
		{
			if (check(a, k, x)chmax(ans, x);
			if (check(a, k, sum / x)chmax(ans, sum / x);
		}
	}
	cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:46:35: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   46 |                         if (check(a, k, x)chmax(ans, x);
      |                                   ^
a.cc:9:25: note: in passing argument 1 of 'bool check(std::vector<int>&, long long int, long long int)'
    9 | bool check(vector<int>& a, long long k, long long d)
      |            ~~~~~~~~~~~~~^
a.cc:47:25: error: expected primary-expression before 'if'
   47 |                         if (check(a, k, sum / x)chmax(ans, sum / x);
      |                         ^~
a.cc:46:57: error: expected ')' before 'if'
   46 |                         if (check(a, k, x)chmax(ans, x);
      |                            ~                            ^
      |                                                         )
   47 |                         if (check(a, k, sum / x)chmax(ans, sum / x);
      |                         ~~
Language: C++

#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    i64 K, S = 0;
    cin >> N >> K;
    vector<i64> A(N);
    for(auto &x : A) {
        cin >> x;
        S += x;
    }
    vector<i64> factor;
    for(i64 x = 1; x <= sqrt(S) + 100; x++) {
        if(S % x == 0) {
            factor.push_back(x);
            factor.push_back(S / x);
        }
    }
    for(auto x : factor) {
        i64 ans = -1;
        vector<i64> R;
        for (int i = 0; i < N; i++) {
            i64 tmp = A[i] % x;
            if(tmp) R.push_back(tmp);
        }
        i64 M = R.size();
        vector<i64> acc_p(M, 0), acc_n(M, 0);
        sort(WHOLE(R));
        for(int i = 0; i < M; i++) {
            acc_p[i] = (x - R[i]) % x;
            acc_n[i] = R[i];
            if(i) {
                acc_p[i] += acc_p[i - 1];
                acc_n[i] += acc_n[i - 1];
            }
        }
        for(int i = -1; i < M; i++) {
            i64 p = 0, n = acc_p[M - 1];
            if(i >= 0) {
                p += acc_n[i];
                n -= acc_p[i];
            }
            if((p - n) % x == 0 && p <= K && n <= K) {
                ans = x;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   56 |     cout << ans << endl;
      |             ^~~
      |             abs
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

vector<ll> get_div(ll n){
	vector<ll> div;
	for(ll i(1);i*i<=n;++i){
		if(s%i == 0){
			div.push_back(i);
			if(i * i != n) div.push_back(n / i);
		}
	}
	sort(div.begin(),div.end());
	return div;
}

int main(){
	int n,k;
	cin >> n >> k;
	vector<ll> a(n);
	ll s(0);
	rep(i,n){
		cin >> a[i];
		s+=a[i];
	}
	vector<ll> div = get_div(s);
	ll ans(0);
	rep(i,div.size()){
		ll d = div[i];
		auto b = a;
		ll s1(0),s2(0);
		rep(j,n){
			b[j] %= d;
			s1 += d-b[j];
		}
		sort(b.begin(),b.end());
		rep(j,n){
			s2 += b[j];
			s1 -= d-b[j];
			if(s1 == s2) break;
		}
		if(s2 <= k && ans < d) ans = d;
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'std::vector<long long int> get_div(ll)':
a.cc:9:20: error: 's' was not declared in this scope
    9 |                 if(s%i == 0){
      |                    ^
Language: C++

#include<iostream>
#include<vector>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int A[N];

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

    vector<int> list;
    int cnt = 0;

    for(int i = 1; i<= sum; i++){
        if(sum % i == 0){
            list.emplace_back(i);
            cnt++;
        }
    }

    int ans = 0;
    for(int i = cnt-1; i >= 0; i--){
        int p[N];
        int n[N];
        int rev[N];
        int divsum;
        for(int j = 0; j<N; j++){
            rev[j] = A[j] % list[i];
        }

        sort(rev, rev + N);


        p[0] = rev[0];
        for(int j = 0; j < N-1; j++){
            p[j +  1] = p[j] + rev[j+1];
        }

        n[N-1] = list[i] - rev[N-1];
        for(int j = N-1; j>=0; j--){
            n[j-1] = n[j] + list[i] - rev[j-1];
            if(n[j] == p[j-1]){
                divsum = n[j];
            }
        }

        if(divsum <=K){
            ans = list[i];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

def divisors(num)
  ans = []
  1.upto(Math.sqrt(num).ceil) do |i|
    if num % i == 0
      ans << i
      ans << num / i if i != num / i
    end
  end
  ans.sort
end

def max_gcd(n, k, arr)
  sum = arr.inject(:+)

  divs = divisors(sum)
  divs.shift

  divs.reverse_each do |d|
    remainders = arr.map { |a| a % d }.sort
    remainders.shift while !remainders.empty? && remainders[0] == 0
    count = 0
    until remainders.empty?
      minus_count = remainders.shift
      count += minus_count

      while minus_count > 0
        need_plus_count = (d - remainders[-1])
        plus_count = [need_plus_count, minus_count].min
        minus_count -= plus_count
        remainders[-1] += plus_count
        remainders.pop if remainders[-1] % d == 0
      end
    end

    if count <= k
      puts d
      exit
    end
  end

  puts 1
end

n, k = gets.split.map
arr = gets.split.map

max_gcd(n, k, arr)

Compiler output:
a.cc:1:1: error: 'def' does not name a type
    1 | def divisors(num)
      | ^~~
a.cc:19:39: error: expected unqualified-id before '.' token
   19 |     remainders = arr.map { |a| a % d }.sort
      |                                       ^
Language: C++

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  ll sum = 0;
  rep(i, N) { sum += [i]; }
  set<ll> candidates;
  for (int i = 1; i * i <= sum; ++i) {
    if (S % i == 0) {
      candidates.insert(i);
      candidates.insert(S / i);
    }
  }
  ll ans = 1;
  for (ll x : candidates) {
    ll need; // required operations
    {
      vector<ll> r(N);
      rep(i, N) { r[i] = A[i] % x; }
      sort(all(r));
      ll B = 0;
      rep(i, N) { B += x - r[i]; }
      ll A = 0;
      need = 1e18;
      rep(i, N) {
        A += r[i];
        B -= x - r[i];
        need = min(need, max(A, B));
      }
    }
    if (need <= K) {
      ans = max(ans, x);
    }
  }
  cout << ans << endl;
}


Compiler output:
a.cc: In lambda function:
a.cc:40:25: error: expected '{' before ';' token
   40 |   rep(i, N) { sum += [i]; }
      |                         ^
a.cc: In function 'int main(int, char**)':
a.cc:40:19: error: no match for 'operator+=' (operand types are 'll' {aka 'long long int'} and 'main(int, char**)::<lambda()>')
   40 |   rep(i, N) { sum += [i]; }
      |               ~~~~^~~~~~
a.cc:43:9: error: 'S' was not declared in this scope
   43 |     if (S % i == 0) {
      |         ^
Language: C++

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class EMaxGCD {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, K;
	    in >> N >> K;
	    vector<int> A(N);
	    REP(i,0,N) in >> A[i];

	    ll answer = 1;
	    ll sum = accumulate(all(A), 0);
	    REP(i,1,pow(sum, 0.5f)+1) {
	        if (sum % i != 0) continue;
	        for (const ll divisor : {sum / i, i}) {
	            if (answer > divisor) continue;
	            vector<ll> costs;
	            REP(j,0,N) {
	                if (A[j] % divisor == 0) continue;
	                costs.push_back(divisor - A[j] % divisor);
	            }
	            if (costs.size() == 0) {
	                answer = divisor;
	                continue;
	            }
	            sort(all(costs));
	            ll k = K;
	            int left = 0, right = costs.size()-1;
	            while (left < right) {
	                if (costs[left] > 0) {
	                    const ll diff = costs[left];
	                    costs[left] = 0;
	                    while (diff > 0 && left < right) {
	                        costs[right] += min(diff, divisor - costs[right]);
	                        if (costs[right] % divisor == 0) right--;
	                        else break;
	                    }
	                    k -= diff;
	                } else {
	                    left++;
	                }
	                if (k < 0) break;
	            }
	            if (costs[left] % divisor == 0 && costs[right] % divisor == 0 && k >= 0) answer = divisor;
	        }
	    }
	    out << answer << "\n";
	}
};


unsigned main() {
	EMaxGCD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class EMaxGCD {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, K;
	    in >> N >> K;
	    vector<int> A(N);
	    REP(i,0,N) in >> A[i];

	    ll answer = 1;
	    ll sum = accumulate(all(A), 0);
	    REP(i,1,pow(sum, 0.5f)+1) {
	        if (sum % i != 0) continue;
	        for (const ll divisor : {sum / i, i}) {
	            if (answer > divisor) continue;
	            vector<ll> costs;
	            REP(j,0,N) {
	                if (A[j] % divisor == 0) continue;
	                costs.push_back(divisor - A[j] % divisor);
	            }
	            if (costs.size() == 0) {
	                answer = divisor;
	                continue;
	            }
	            sort(all(costs));
	            ll k = K;
	            int left = 0, right = costs.size()-1;
	            while (left < right) {
	                if (costs[left] > 0) {
	                    const ll diff = costs[left];
	                    costs[left] = 0;
	                    while (diff > 0 && left < right) {
	                        costs[right] += min(diff, divisor - costs[right]);
	                        if (costs[right] % divisor == 0) right--;
	                        else break;
	                    }
	                    k -= diff;
	                } else {
	                    left++;
	                }
	                if (k < 0) break;
	            }
	            if (costs[left] % divisor == 0 && costs[right] % divisor == 0 && k >= 0) answer = divisor;
	        }
	    }
	    out << answer << "\n";
	}
};


int main() {
	EMaxGCD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)

int main(){
  int n,k,i=1,ma=0,mo,ans=0;
  cin>>n>>k;
  vector<int> a(n,0),m(n,0);
  REP(i,n) cin>>a.at(i);
  sort(a.begin(),a.end(),greater<int>());
  ma=a.at(0);
  
  while(i<=ma+k){
    mo=0;
    REP(j,n){
      m.at(j)=a.at(j)%i;
      mo+=m.at(j);
    }
    if(!(mo%i)){
      int ko=mo/i,sa=0;
      REP(k,ko) sa+=i-m.at(k);
      if(sa<=k) ans=i;
    }
    //cout<<" i:"<<i<<" mo:"<<mo<< " mo%i:"<<mo%i<<endl;
    i++;
  }

  cout<<ans<<endl;

Compiler output:
a.cc: In function 'int main()':
a.cc:28:19: error: expected '}' at end of input
   28 |   cout<<ans<<endl;
      |                   ^
a.cc:5:11: note: to match this '{'
    5 | int main(){
      |           ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  int n,k,s=0;
  cin>>n>>k;
  vector<int> a(n),div,b;
  for(auto &i:a)cin>>i,s+=i;
  for(int p=1;p*p<=s;p++){
    if(s%p==0){
      div.push_back(p);
      if(s%(s/p)==0)div.push_back(s/p);
    }
  }
  sort(div.begin(),div.end(),greater<>());
  for(auto p:div){
    b=a;
    int l=0,q=0;
    for(int i=0;i<n;++i){
      int r=b[i]%p;
      //if(r>p-r)r-=p;
      if(abs(q+r)>p-abs(q+r))r-=p;
      q+=r;
      b[i]-=r;
      l+=max(r,0);
      //cerr<<"p="<<p<<",b[i]="<<b[i]<<",r="<<r<<",q="<<q<<",l="<<l<<"\n";
    }
    if(l>k||b[n-1]%p||q)continue;
    cout<<p;
    return 0;
  }
}


Compiler output:
a.cc:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:25:13: error: no matching function for call to 'max(long int&, int)'
   25 |       l+=max(r,0);
      |          ~~~^~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:25:13: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   25 |       l+=max(r,0);
      |          ~~~^~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:25:13: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   25 |       l+=max(r,0);
      |          ~~~^~~~~
Language: C++

#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define  ll long long
using namespace std;

int main(){
  int n,k; cin >> n >> k;
  int A[n]; int sum = 0;
  rep(i,n){
    cin >> A[i];
    sum += A[i];
  }
  int ans = 1;
  set<ll> D;
  for(int i=1;i*i<=sum;i++){
    if(sum % i ==0){
      D.insert(i);
      D.insert(sum/i);
    }
  }
  vector<int> a(n);
  for(int u : D){
    rep(i,n){
      a[i] = A[i] % u;
    }
    sort(a.begin(),a.end());
    ll left = 0;
    ll right = 0;
    rep(i,n) right += u-a[i];
    ll need = 1e18;
    rep(i,n){
      left += a[i];
      right -= u-a[i];
      need = min(need,max(left,right));
    }
    if(need <= k) ans = max(ans,u);
  }
  cout << ans << endl;
  return 0;
}

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

#include <iostream>
#include <vector>
#include <numeric>

int main(){
  int N,K;
  std::cin >> N >> K;

  std::vector<int> A_arr(N);
  for(int i = 0; i < N; i++) std::cin >> A_arr[i];
  int acc = std::accumulate(A_arr.begin(), A_arr.end(), 0);

  int nd = acc;
  for(; nd > 0; nd--){
    if(acc%nd != 0) continue;
    std::sort(A_arr.begin(), A_arr.end(), [nd](int l, int r){return (l%nd)<(r%nd);});
    int l = -1, r = N;
    int pacc = 0, ppacc = 0;
    while(r-l > 1){
      if(pacc < 0){
        l++;
        pacc += A_arr[l]%nd;
        ppacc += A_arr[l]%nd;
      }else{
        r--;
        pacc += (A_arr[r]%nd)-nd;
      }
      if(ppacc > K) break;
    }
    if(ppacc <= K) break;
  }

  std::cout << nd << std::endl;

  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:16:10: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   16 |     std::sort(A_arr.begin(), A_arr.end(), [nd](int l, int r){return (l%nd)<(r%nd);});
      |          ^~~~
      |          qsort
Language: C++

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>
#include <bitset>

using namespace std;
typedef long long ll;
ll MOD = 1000000007;

vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main()
{
    int n, K;
    cin >> n >> K;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    vector<ll> s = divisor(accumulate(a, a + n, 0));
    for (int k = s.size() - 1; k > -1; k--)
    {
        int t[n];
        for (int i = 0; i < n; i++)
        {
            t[i] = a[i] % s[k];
        }
        sort(t, t + n);
        ll l = accumulate(t, t + n, 0), r = 0;
        for (int i = n - 1; i > -1; i--)
        {
            if (r + l <= K * 2 && l == r)
            {
                cout << s[k] << endl;
                return 0;
            }
            r += s[k] - t[i];
            l -= t[i];

            if (r + l < (K * 2) && r == l)
            {
                cout << s[k] << endl;
                return 0;
            }
        }
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:28: error: 'accumulate' was not declared in this scope
   44 |     vector<ll> s = divisor(accumulate(a, a + n, 0));
      |                            ^~~~~~~~~~
a.cc:56:17: error: 'r' was not declared in this scope
   56 |             if (r + l <= K * 2 && l == r)
      |                 ^
a.cc:61:13: error: 'r' was not declared in this scope
   61 |             r += s[k] - t[i];
      |             ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int n,k;cin>>n>>k;
  int sum=0;
  int a[n];
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  vectot<int> p;
  for(int i=1;i*i<=sum;++i){
    if(sum%i==0){
      p.push_back(i);
      if(i*i!=sum)p.push_back(sum/i);
    }
  }
  reverse(all(p));
  rep(i,p.size()){
    int b[n];rep(j,n)b[j]=a[j]%p[i];
    sort(b,b+n);
    ll sum[n+1];sum[0]=0;
    rep(j,n)sum[j+1]=sum[j]+b[j];
    rep(j,n){
      if(max(sum[j+1]-sum[0],(n-j-i)*p[i]-(sum[n]-sum[j+1]))<=k){
        cout<<p[i]<<endl;exit(0);
      }
    }
  }
}
    
    

Compiler output:
a.cc: In function 'int main()':
a.cc:23:3: error: 'vectot' was not declared in this scope
   23 |   vectot<int> p;
      |   ^~~~~~
a.cc:23:10: error: expected primary-expression before 'int'
   23 |   vectot<int> p;
      |          ^~~
a.cc:26:7: error: 'p' was not declared in this scope
   26 |       p.push_back(i);
      |       ^
a.cc:30:15: error: 'p' was not declared in this scope
   30 |   reverse(all(p));
      |               ^
a.cc:13:17: note: in definition of macro 'all'
   13 | #define all(x) (x).begin(),(x).end()
      |                 ^
Language: C++

#include <iostream>
#include <algorithm>
using namespace std;
int n,k,arr[505],ans;
void go(int g)
{
	int sum=0,cnt=0;
	vector<int> tmp;
	for (int i=0;i<n;i++)
	{
		sum+=(arr[i]%g);
		tmp.push_back(g-arr[i]%g);
	}
	sort(tmp.begin(),tmp.end());
	for (int i=0;i<sum/g;i++)
	cnt+=tmp[i];
	if (cnt<=k)
	ans=max(ans,g);
}
int main()
{
	int sum=0;
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;i++)
	scanf("%d",&arr[i]),sum+=arr[i];
	for (int i=1;i*i<=sum;i++)
	{
		if (sum%i==0)
		{
			go(i);
			go(sum/i);
		}
	}
	printf("%d",ans);
}

Compiler output:
a.cc: In function 'void go(int)':
a.cc:8:9: error: 'vector' was not declared in this scope
    8 |         vector<int> tmp;
      |         ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
a.cc:8:16: error: expected primary-expression before 'int'
    8 |         vector<int> tmp;
      |                ^~~
a.cc:12:17: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   12 |                 tmp.push_back(g-arr[i]%g);
      |                 ^~~
      |                 tm
a.cc:14:14: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   14 |         sort(tmp.begin(),tmp.end());
      |              ^~~
      |              tm
Language: C++

#include<iostream>
using namespace std;

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

    int B[N];
    int a;
    int b;
    int amari_sum1 = 0;
    int amari_sum2 = 0;
    int ans = 0;
    cout << endl;
    for(int j = sum; j > 0; j--) {
        a = sum % j;
        if(a == 0) {
            amari_sum1 = 0;
            amari_sum2 = 0;
            // 合計の約数のiがくる
            // K回の操作でA[i]の中身がすべて割り切れるようになれば良い
            for(int i = 0; i < N; i++) {
                B[i] = A[i] % j;
                amari_sum1 += B[i];
            }
            sort(B, B+N);
            
            for(int i = 0; amari_sum2 < amari_sum1 / 2; i++) {
                amari_sum2 += B[i];
                if(amari_sum2 > amari_sum1 / 2) {
                    amari_sum2 -= B[i];
                    break;
                }
            }

            if(amari_sum2 <= K) {
                ans = j;
                break;
            }
        }
    }

    cout << ans;

}


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

#include <bits/stdc++.h>
using namespace std;
 
bool check(int x , vector<int> as , int k) {}
	vector <int> bs;
	bs = as;
	const int n = as.size();
	for(int i = 0; i < n; i++) {
		bs[i] = bs[i] % x;
	}
	sort(bs.begin() , bs.end());
	int we = k, rt = k;
	int qr = 0, qt = 0;
 
	while(qr < n) {
		int b = bs[qr];
		if(b > we) {
			break;
		}
		qr += 1;
		we -= b;
	}
 
	while(qt < n) {
		int b = x - bs[n - 1 - qt];
		if(b > rt) {
			break;
		}
		qt += 1;
		rt -= b;
	}
 
	return qr + qt >= n;
}
 
int main() {
	int n , k;
	vector <int> as;
	int s = 0;
	cin >> n >> k;
	as.resize(n);
	for(int i = 0; i < n; i++) {
		cin >> as[i];
		s += as[i];
	}
	int ans = 1;
	for(int x = 1; x * x <= s; x++) {
		int y = s / x;
		if(s % x == 0 && check(x , as , k)) {
			ans = max(ans , x);
		}
		if(s % y == 0 && check(y , as , k)) {
			ans = max(ans , y);
		}
	}
	cout << ans + 1;
	return 0;
}

Compiler output:
a.cc: In function 'bool check(int, std::vector<int>, int)':
a.cc:4:45: warning: no return statement in function returning non-void [-Wreturn-type]
    4 | bool check(int x , vector<int> as , int k) {}
      |                                             ^
a.cc: At global scope:
a.cc:6:9: error: 'bs' does not name a type
    6 |         bs = as;
      |         ^~
a.cc:7:23: error: 'as' was not declared in this scope; did you mean 'bs'?
    7 |         const int n = as.size();
      |                       ^~
      |                       bs
a.cc:8:9: error: expected unqualified-id before 'for'
    8 |         for(int i = 0; i < n; i++) {
      |         ^~~
a.cc:8:24: error: 'i' does not name a type
    8 |         for(int i = 0; i < n; i++) {
      |                        ^
a.cc:8:31: error: 'i' does not name a type
    8 |         for(int i = 0; i < n; i++) {
      |                               ^
a.cc:11:13: error: expected constructor, destructor, or type conversion before '(' token
   11 |         sort(bs.begin() , bs.end());
      |             ^
a.cc:12:18: error: 'k' was not declared in this scope
   12 |         int we = k, rt = k;
      |                  ^
a.cc:15:9: error: expected unqualified-id before 'while'
   15 |         while(qr < n) {
      |         ^~~~~
a.cc:24:9: error: expected unqualified-id before 'while'
   24 |         while(qt < n) {
      |         ^~~~~
a.cc:33:9: error: expected unqualified-id before 'return'
   33 |         return qr + qt >= n;
      |         ^~~~~~
a.cc:34:1: error: expected declaration before '}' token
   34 | }
      | ^
Language: C++

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

int main()
{
	int N;
	ll K;
	cin >> N >> K;
	vector<ll> A(N);
	ll S(0);
	for(int i(0);i<N;++i){
		cin >> A[i];
		S += A[i];
	}
	vector<ll> d;
	for(int i(1);i*i<=sum;++i){
		if(S % i == 0){
			d.push_back(i);
			d.push_back(S/i);
		}
	}
	int M = d.size();
	int target_d,d_max(0);
	vector<ll> a(N);
	ll a_sum,sum_left,sum_right,B;
	for(int i(0);i<M;++i){
		target_d = d[i];
		a_sum = 0;
		for(int j(0);j<N;++j){
			a[j] = A[j] % target_d;
			a_sum += a[j];
		}
		sort(a.begin(),a.end());
		sum_left = a_sum;
		sum_right = 0;
		B = 0;
		for(int j(N-1);j>=0;--j){
			sum_left -= a[j];
			sum_right += target_d-a[j];
			B += target_d-a[j];
			if(sum_left == sum_right){
				if(K >= B && d_max<target_d){
					d_max = target_d;
				}
				break;
			}
		}
	}
	cout << d_max << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:27: error: 'sum' was not declared in this scope
   17 |         for(int i(1);i*i<=sum;++i){
      |                           ^~~