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

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

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

    int a_sum = accumulate(a.begin, a.end(), 0);

    vector<int> divisor;
    for (int i = 1; i*i <= a_sum; i++)
    if (a_sum % i == 0)
    {
        divisor.push_back(i);
        divisor.push_back(a_sum/i);
    }
    sort(divisor.rbegin(), divisor.rend());

    int ans = 0;
    for (auto div: divisor)
    {
        vector<int> res(n);
        rep(j, 0, n) res[j] = a[j] % div;
        sort(res.begin(), res.end());

        vector<int> cumres(n + 1);
        cumres[0] = 0;
        rep(j, 0, n) cumres[j + 1] = cumres[j] + res[j];

        int c = cumres[n];
        rep(j, 1, n + 1)
        {
            int s1, s2;
            s1 = cumres[j];
            s2 = div * (n-j) - (cumres[n] - cumres[j]);
            c = min(c, max(s1, s2));
            // cout << div << ' ' << s1 << ' ' << s2 << endl;
        }
        // cout << div << ' ' << c << endl;
        if (c <= k)
        {
            ans = max(ans, div);
            break;
        }
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:27: error: no matching function for call to 'accumulate(<unresolved overloaded function type>, std::vector<int>::iterator, int)'
   14 |     int a_sum = accumulate(a.begin, a.end(), 0);
      |                 ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:58,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_numeric.h:134:5: note: candidate: '_Tp std::accumulate(_InputIterator, _InputIterator, _Tp) [with _InputIterator = __gnu_cxx::__normal_iterator<int*, vector<int> >; _Tp = int]'
  134 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
      |     ^~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:134:31: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >'
  134 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
      |                ~~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:161:5: note: candidate: 'template<class _InputIterator, class _Tp, class _BinaryOperation> _Tp std::accumulate(_InputIterator, _InputIterator, _Tp, _BinaryOperation)'
  161 |     accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
      |     ^~~~~~~~~~
/usr/include/c++/14/bits/stl_numeric.h:161:5: note:   candidate expects 4 arguments, 3 provided
Language: C++

#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll = long long;
using namespace std;
ll n,k,s=0,a[550],b[550],ans=0;
ll f(ll p){
    ll s2=0,s3=0;
    rep(i,0,n){b[i]=a[i]%p;s2+=b[i];}
    sort(b,b+n);
    rep(i,0,n-s2/p)s3+=b[i];
    return s3<=k?p:0;
}
int main(){
    cin>>n>>k;
    rep(i,0,n) {cin>>a[i];s+=a[i];}
    for(ll p=1;(p*p)<=s;p++) if(s%p==0){
        ans=max(ans,f(p));
        ans=max(ans,f(s/p));
    cout<<ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:2: error: expected '}' at end of input
   20 | }
      |  ^
a.cc:13:11: note: to match this '{'
   13 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll = long long;
using namespace std;
ll n,k,s=0,a[550],b[550],ans=0;
ll f(ll w){
    ll s2=0,s3=0;
    rep(i,0,n){b[i]=a[i]%w;s2+=b[i];}
    sort(b,b+n);
    rep(i,0,n-s2/w)s3+=b[i];
    return s3<=k?w:0;
}
int main(){
    cin>>n>>k;
    rep(i,0,n) {cin>>a[i];s+=a[i];}
    for(ll i=0,i*i<=s;i++) if(s%i==0){
        ans=max(ans,f(i));
    }
    cout<<ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:17: error: expected ';' before '*' token
   16 |     for(ll i=0,i*i<=s;i++) if(s%i==0){
      |                 ^
      |                 ;
a.cc:16:17: error: invalid type argument of unary '*' (have 'll' {aka 'long long int'})
   16 |     for(ll i=0,i*i<=s;i++) if(s%i==0){
      |                 ^~
Language: C++

/*In The Name of AintAH*/
#include <bits/stdc++.h>
#define inf 1000000000000007
#define mod	1000000007
#define MAX 505 
#define ll long long
#define fr first
#define sc second
#define endl '\n'
using namespace std;
set<int> s;
void get_div(int x){
	for(int i = 1; i*i <= x; i ++){
		if(x % i == 0){
			s.insert(i);
			s.insert(x/i);
		}
	}
}
int a[MAX];

int main(){ 
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,sum = 0,k;
	cin>>n>>k;
	for(int i = 0; i < n ;i ++)cin>>a[i],sum += a[i];
	get_div(sum);
	for(auto it = s.rbegin() ; it != s.rend() ; it++){
		int d = *it;
		memset(dp,0,sizeof dp);
		vector<int> v;
		for(int i = 0; i < n; i++) v.push_back(a[i]%d);
		
		sort(v.begin(), v.end());
		int right = v.size() - 1;
		int left = 0,sum = 0;
		while(left < right){
			if(v[left] == 0){left++;continue;}
			if(v[right] == d){right--;continue;}
			if(v[right] + v[left] >= d){
				v[left] -= d - v[right];
				sum += d - v[right];
				v[right] = d;
			}else{
				v[right] += v[left];
				sum += v[left];
				v[left] = 0;
			}
		}
		if(sum <= k )return cout<<d , 0;
		
	}
	return 0; 
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:24: error: 'dp' was not declared in this scope; did you mean 'd'?
   30 |                 memset(dp,0,sizeof dp);
      |                        ^~
      |                        d
Language: Java

import java.util.*;

public class Main {
    static final TreeMap<Long, Integer> factorization = new TreeMap<>();
    static final List<Long> factors = new ArrayList<>();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ln = n;
        long k = in.nextInt();
        long[] array = new long[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            array[i] = in.nextLong();
            sum += array[i];
        }
        long sumTemp = sum
        for (long p = 2; p < 22361; p++) {
            int power;
            for (power = 0; sumTemp % p == 0; sumTemp /= p, power++);
            if (power > 0) {
                factorization.put(p, power);
            }
        }
        if (sumTemp != 1L) {
            factorization.put(sumTemp, 1);
        }
        generateFactors(1);
        factors.sort(Comparator.reverseOrder());
        for (long f : factors) {
            Long[] residues = new Long[n];
            long residueSum = 0;
            for (int i = 0; i < n; i++) {
                residues[i] = array[i] % f;
                residueSum += residues[i];
            }
            Arrays.sort(residues);
            long req = 0;
            long li = 0;
            for (int i = 0; li < ln - (residueSum / f); i++, li++) {
                req += residues[i];
            }
            if (k >= req) {
                System.out.println(f);
                return;
            }
        }
    }

    static void generateFactors(long curr) {
        if (factorization.isEmpty()) {
            factors.add(curr);
        } else {
            long p = factorization.firstKey();
            int power = factorization.remove(p);
            for (int e = 0; e <= power; e++, curr *= p) {
                generateFactors(curr);
            }
            factorization.put(p, power);
        }
    }
}


Compiler output:
Main.java:18: error: ';' expected
        long sumTemp = sum
                          ^
1 error
Language: Java

import java.util.*;

public class MaxGCD {
    static final TreeMap<Long, Integer> factorization = new TreeMap<>();
    static final List<Long> factors = new ArrayList<>();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ln = n;
        long k = in.nextInt();
        long[] array = new long[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            array[i] = in.nextLong();
            sum += array[i];
        }
        long sumTemp = sum
        for (long p = 2; p < 22361; p++) {
            int power;
            for (power = 0; sumTemp % p == 0; sumTemp /= p, power++);
            if (power > 0) {
                factorization.put(p, power);
            }
        }
        if (sumTemp != 1L) {
            factorization.put(sumTemp, 1);
        }
        generateFactors(1);
        factors.sort(Comparator.reverseOrder());
        for (long f : factors) {
            Long[] residues = new Long[n];
            long residueSum = 0;
            for (int i = 0; i < n; i++) {
                residues[i] = array[i] % f;
                residueSum += residues[i];
            }
            Arrays.sort(residues);
            long req = 0;
            long li = 0;
            for (int i = 0; li < ln - (residueSum / f); i++, li++) {
                req += residues[i];
            }
            if (k >= req) {
                System.out.println(f);
                return;
            }
        }
    }

    static void generateFactors(long curr) {
        if (factorization.isEmpty()) {
            factors.add(curr);
        } else {
            long p = factorization.firstKey();
            int power = factorization.remove(p);
            for (int e = 0; e <= power; e++, curr *= p) {
                generateFactors(curr);
            }
            factorization.put(p, power);
        }
    }
}


Compiler output:
Main.java:18: error: ';' expected
        long sumTemp = sum
                          ^
1 error
Language: C++

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

vector<int> divisor(long long N) {
    vector<int> ret;
    long long i;
    for (i = 1; i*i < N; i++) {
        if (N % i != 0) continue;
        ret.push_back(i);
        ret.push_back(N/i);
    }
    if (i*i == N) ret.push_back(i);
    return ret;
}

bool check(int N, int K, vector<int> &A) {
    vector<int> mod(A.size());
    vector<long long> plus_sum(A.size() + 1);
    for (int i = 0; i < A.size(); i++) {
        mod[i] = A[i]%N;
    }
    sort(mod.begin(), mod.end());
    for (int i = mod.size()-1; i >= 0; i--) {
        int tmp = (mod[i] == 0 ? 0 : N - mod[i]);
        plus_sum[i] = plus_sum[i+1] + tmp;
    }
    long long sum = 0;
    for (int i = 0; i <= mod.size(); i++) {
        if (i == 0) {
            if (plus_sum[0] <= K) return true;
        } else {
        sum += mod[i-1];
            if (max(sum, plus_sum[i]) <= K) {
                return true;
            }
        }
    }
    return false;
}

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

    
    int ans = 1;
    for (auto &i : divs) {
        if (check(i, K, A)) ans = max(i, ans);
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:52:20: error: 'divs' was not declared in this scope; did you mean 'div'?
   52 |     for (auto &i : divs) {
      |                    ^~~~
      |                    div
Language: C++

/* JunsCoding325 */
#include <cstdio>
#include <vector>
using namespace std;

int N, K, num[500], sum, way[500];
vector<int> gcd;

void makeGcd (void)
{
    for (int i = sum; i >= 1; i--) 
        if ((sum % i) == 0)
            gcd.push_back(i);
}

int check (int pivot)
{
    //printf("\ncheck(%d)\n", pivot);
    if (pivot == 1)
        return true;

    int tmp = 0, ret = 0;
    for (int i = 0; i < N; i++) {
        way[i] = num[i] % pivot;
        tmp += way[i];
    }
    tmp /= pivot;
/*
    for (int i = 0; i < N; i++) {
        printf("%d: %d\n", i, way[i]);
    }
    */
    sort(way, way+N);
    for (int i = N-1; i >= N - tmp; i--) {
        ret += (pivot - way[i]);
    }
    //printf("ret = %d\n", ret);
    return ret;
}

int main (void)
{
    scanf("%d %d", &N, &K);
    sum = 0;
    for (int nn = 0; nn < N; nn++) {
        scanf("%d", &num[nn]);
        sum += num[nn];
    }
    
    makeGcd();
    /*
    for (int i = 0; i < gcd.size(); i++)
        printf("%d ", gcd[i]);
    printf("\n");
*/
    int ans;
    for (int i = 0; i < gcd.size(); i++) {
        if (check(gcd[i]) <= K) {
            ans = gcd[i];
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[30000];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

int N, K;
int A[500];
inline bool keisan(int k) {
	int a[500];
	int ouchaku = 0;
	rep(j, N) {
		a[j] = A[j] % k;
		ouchaku = max(ouchaku, min(a[j], (k - a[j]) % k));
		if (ouchaku > K) return false;
	}
	pakuri_sort(N, a);
	int x = 0, y = N - 1;
	int tmp = a[0] + a[N - 1] - k;
	int kazu = a[0] + k - a[N - 1];
	while (x + 1 < y) {
		if (tmp <= 0) {
			tmp += a[++x];
			kazu += a[x];
		}
		else {
			tmp += a[--y] - k;
			kazu += k - a[y];
		}
	}
	if (kazu / 2 <= K) {
		printf("%d", k);
		return true;
	}
	return false;
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	N = getint();
	K = getint();
	int goukei = 0;
	rep(i, N) {
		A[i] = getint();
		goukei += A[i];
	}

	int yakusuu[15000];
	int M = 0;
	int sq = sqrt(goukei);
	rep1(i, sq) {
		if (goukei % i == 0) {
			yakusuu[M++] = i;
			if (i * i != goukei) {
				if (keisan(goukei / i)) return 0;
			}
		}
	}

	for (int i = M - 1; i >= 0; i--) {
		if (keisan(yakusuu[i])) return 0;
	}

	Would you please return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:93:18: error: 'sqrt' was not declared in this scope; did you mean 'sq'?
   93 |         int sq = sqrt(goukei);
      |                  ^~~~
      |                  sq
Language: C++

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


int main() {
  //配列がn=2で7, 21だとするとsumは28
  //何回操作をしても和が28であることは不変
  //a, bのgcdは(a+b)%gdd==0となる
  int n, k, b;
  cin >> n >> k;
  vector<int> a;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> b;
    a.push_back(b);
    sum += b;
  }
  sort(a.begin(), a.end());
  set<long long> candidates;

  for (int i = 1; i*i <= sum; i++) {
    if (sum%i == 0) {
      candidates.insert(i);
      candidates.insert(sum/i);
    }
  }
  long long ans = 1;
  for (long long x : candidates) {
    long long need;
    {//calc need
      vector<long long > remainder;
      for (int i = 0; i < n; i++) {
        remainder[i] = a[i]%x;
      }
      sort(remainder.begin(), remainder.end());
      long long right_sum = 0;
      long long left_sum = 0;
      need = 1e18;
      for (int i = 0; i < n; i++) {
        left_sum -= x - remainder[i];
        right_sum += remainder[i];
        need = min(need, max(left_sum, right_sum));
      }
    }
    if (need <= k) {
      ans = max(ans, x);
    }
  }
  cout  << ans << endl;
  return 0;
}


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

#include <stdio.h>

#define N 501

int asc(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

int main(void)
{
	int n, k, a[N], s[N];

	scanf("%d %d", &n, &k);

	int i, j, tmp, sum = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		sum += a[i];
	}

	int rem, count;
	for (i = sum; i > 0; i--)
	{
		if (sum % i == 0)
		{
			for (j = 0; j < n; j++)
				s[j] = a[j] % i;
			qsort(s, n, sizeof(int), asc);
			count = j = 0;
			tmp = n - 1;
			while (j < tmp)
			{
				if (s[j] > (rem = i - s[tmp]))
				{
					s[j] -= rem;
					count += rem;
					tmp--;
				}
				else if (s[j] < rem)
				{
					s[tmp] += s[j];
					count += s[j];
					j++;
				}
				else
				{
					count += s[j];
					j++;
					tmp--;
				}
			}
			if (count <= k)
				break;
		}
	}
	printf("%d\n", i);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:25: error: 'qsort' was not declared in this scope
   30 |                         qsort(s, n, sizeof(int), asc);
      |                         ^~~~~
Language: C++

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
inline int read() {
	int x=0,f=-1;	char ch = getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x = (x<<3)+(x<<1)+(ch^48); ch=getchar(); }
	return x * f;
}
const int N = 507;
int n,k,s,ans;
int a[N];
inline bool check(int x) {
	int ss=0 ,sss=0;
	vector<int> v;
	for(int i=1;i<=n;++i) {
		v.push_back(a[i]%x);
		sss += a[i]-x % x;
	}
	sort(v.begin(),v.end());
	ss = v[0] ,sss -= x - v[0];
	for(int i=1;i<v.size();++i) {
		if(ss+v[i] > k) break;
		ss += v[i] ,sss -= x - v[i];
	}
	return ss<=k&&sss<=k;
}
int main()
{
	n = read() ,k = read();
	for(int i=1;i<=n;++i)
		a[i] = read() ,s += a[i];
	for(int i=1;;i*i<=s;++i) {
		if(s != (s/i)*i) continue;
		if(check((s/i))) ans = max(ans,ans,s/i);
		if(check(i)) ans = max(ans,i);
	}
	printf("%d\n",ans);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:28: error: expected ')' before ';' token
   36 |         for(int i=1;;i*i<=s;++i) {
      |            ~               ^
      |                            )
a.cc:36:31: error: 'i' was not declared in this scope
   36 |         for(int i=1;;i*i<=s;++i) {
      |                               ^
Language: C++

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;
using ll = long long;

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = 1;
	ll mx = accumulate(begin(a), end(a), 0);
	auto div = divisor(mx);
	for (auto d : div) {
		ll cnt = 0;
		vector<int> phase(n);
		for (int i = 0; i < n; i++) {
			phase[i] = a[i] % d;
			cnt += phase[i];
		}
		sort(begin(phase), end(phase));
		ll sum = accumulate(begin(phase), begin(phase) + n - cnt / d, 0LL);
		if (sum <= k) ans = max(ans, (ll)d);
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:17: error: 'accumulate' was not declared in this scope
   29 |         ll mx = accumulate(begin(a), end(a), 0);
      |                 ^~~~~~~~~~
Language: C++

#include <stdio.h>

#define N 501
int main(void)
{
	int n, k, a[N], s[N];

	scanf("%d %d", &n, &k);

	int i, j, tmp, sum = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &tmp);
		sum += tmp;
		a[i] = tmp;
		for (j = i; j > 0; j--)
		{
			if (a[j] < a[j - 1])
			{
				tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
			}
		}
	}

	int rem, count = 0;
	for (i = sum; i > 0; i--)
	{
		if (sum % i == 0)
		{
			j = 0;
			tmp = n - j - 1;
			while (j < tmp)
			{
				if (a[j] > (rem = sum - a[tmp]) {
					a[j] -= rem;
					count += rem;
					tmp--;
				}
				else if (a[j] < rem)
				{
					a[tmp] += a[j];
					count += a[j];
					j++;
				} else {
					count += a[j];
					j++;
					tmp--;
				}
			}
		}
	exit:
		printf("%d\n", i);
		return 0;
	}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:64: error: expected ')' before '{' token
   36 |                                 if (a[j] > (rem = sum - a[tmp]) {
      |                                    ~                           ^~
      |                                                                )
a.cc:51:25: error: expected primary-expression before '}' token
   51 |                         }
      |                         ^
a.cc:56:10: error: expected '}' at end of input
   56 |         }
      |          ^
a.cc:5:1: note: to match this '{'
    5 | {
      | ^
Language: C++

#include <algorithm>
#include <cstdio>
const int MAXN = 505;
int A[MAXN];
int B[MAXN];
int K, N;

bool check(int M) {
  for (int i = 0; i < N; ++i) {
    B[i] = A[i] % M;
  }
  std::sort(B, B+N);
  int lo = 0;
  int hi = N-1;
  int cost = 0;
  while (lo < hi) {
    int sum = B[lo] + B[hi];
    if (sum < M) {
      cost += B[lo];
      B[hi] += B[lo];
      B[lo] = 0;
      ++lo;
    } else {
      // (sum >= M)
      cost += M - B[hi];
      B[hi] = M;
      B[lo] = sum - M;
      if (!B[lo]) ++lo;
      --hi;
    }
  }
  return (B[lo] % M == 0) && (cost <= K);
}

int main() {
  scanf(" %d%d", &N, &K);
  int S = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
    S += A[i];
  }
  int ret = 1;
  int sqrtS = sqrt(S);
  for (int i = 1; i <= sqrtS; ++i) if ((S % i) == 0) {
    int j = S / i;
    if (check(i)) ret = std::max(i, ret);
    if (check(j)) ret = std::max(j, ret);
  }
  printf("%d\n", ret);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:15: error: 'sqrt' was not declared in this scope; did you mean 'sqrtS'?
   43 |   int sqrtS = sqrt(S);
      |               ^~~~
      |               sqrtS
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n,k;
    cin >> n >> k;

    vector<ll> v(n);
    ll mx = 0;
    REP(i,n) {
        cin >> v[i];
        mx = max(v[i],mx);
    }

    ll ans = 0;
    vector<ll> v2;
    for(auto i = 1; i < sqrt(mx*n) ; i++) {
        if (sum % i == 0) {
            v2.emplace_back(i);
            v2.emplace_back(mx*n / i);
        }
    }

    int pos = 0;
    while(ans == 0) {
        ll k2 = k*2;
        ll kp = 0;
        ll km = 0;

        vector<ll> ka(n);
        REP(i,n) ka[i] = v[i] % v2[pos];
        sort(ALL(ka));
        kp = accumulate(ALL(ka),0LL, [&](ll acc, ll i){return acc + v2[pos] - i;});
        // for (auto i : ka) {
        //    cerr << i << endl;
        // }
        REP(i,n) {
            kp -= v2[pos] - ka[i];
            km += ka[i];
            //cerr<< kp << " " << km << endl;
            if (kp < km) break;
            //cerr << (kp == km) << endl;
            if ((kp == km) && (kp + km <= k2) ){
                ans = v2[pos];
                break;
            }
        }
        pos++;
    }

    cout << ans << endl;


    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:13: error: 'sum' was not declared in this scope
   27 |         if (sum % i == 0) {
      |             ^~~
Language: C++

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

const int MAXN = 1.1e6;
int N;
int A[MAXN];
ll K;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];
  int s = 0; for (int i = 0; i < N; i++) s += A[i];
  for (int f = s; true; f--) {
    if (s % f != 0) continue;
    
    int v = 0;
    for (int i = 0; i < N; i++) {
      v += A[i] % f;
    }
    v /= f;
    sort(A, A+N, [&](int i, int j)->bool { return i%f < j%f; });
    int cost = 0;
    for (int i = 0; i < N; i++) {
      cost += (i < N-v) ? A[i] % f : (f - A[i] % f);
    }
    if (cost <= K) { cout << f << '\n'; exit(0); }
  }
}

Compiler output:
a.cc:7:1: error: 'll' does not name a type
    7 | ll K;
      | ^~
a.cc: In function 'int main()':
a.cc:11:15: error: 'K' was not declared in this scope
   11 |   cin >> N >> K;
      |               ^
Language: C++

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 500 + 10;

int n, k;
std::vector<int> factors;
vector<int> a;

void factorize(int n){
   for (int i = 1; i*i <= n; ++i)
   {
      if(n%i)continue;
      factors.pb(i);
      if(i != n/i){
         factors.pb(n/i);
      }
   }
   sort(factors.rbegin(), factors.rend());
}


int32_t main(){_

   cin>>n>>k;
   a.resize(n);
   int sum = 0;
   for (int i = 0; i < n; ++i)
   {
      cin>>a[i];
      sum += a[i];
   }

   factorize(sum);

   int ans = 1;
   for (int tt = 0; tt <= sz(factors)-1; ++tt)
   {
      int num = factors[tt];
      vector<int> b = a;
      for (int j = 0; j < n; ++j)
      {
         b[j] %= num;
      }

      sort(b.begin(), b.end());

      int ops = 0;
      for (int i = 0, j = n-1; i < j; )
      {
         int mi = min(b[i], num - b[j]);
         ops += mi;
         b[i] -= mi;
         b[i] += num;
         b[i] %= num;

         b[j] += mi;
         b[j] %= num;
         
         assert(b[i] == 0 or b[j] == 0);
         if(b[i] == 0){
            ++i;
         }
         else{
            --j;
         }
      }

      if (b[i] > 0 or b[j] > 0){
         continue;
      }

      if(ops <= k){
         smax(ans, num);
      }
   }

   cout<<ans;

   return 0;
}


Compiler output:
a.cc: In function 'int32_t main()':
a.cc:85:13: error: 'i' was not declared in this scope
   85 |       if (b[i] > 0 or b[j] > 0){
      |             ^
a.cc:85:25: error: 'j' was not declared in this scope
   85 |       if (b[i] > 0 or b[j] > 0){
      |                         ^
Language: C++

#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <set>

using namespace std;

void prime_factorization(set<int>& result, int x)
{
  for (int i = 1; i*i <= x; i++) {
    if (x % i == 0) {
      result.insert(i);
      result.insert(x/i);
    }
  }
}

bool verify(const vector<int>& a, int k, int block_size, int block_num)
{
  int diff = 0;
  block_num -= (int)a.size();
  for (int i = 1; i < a.size(); i++) {
    int x = a.at(i);
    int block = block_size;
    int max_block_num = x / block;
    block = block_size * min(block_num, max_block_num);
    diff += x - block;
  }
  return a.at(0) + diff == (block_size) * (block_num + 1) && diff == k;
}

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int sum = accumulate(a.begin(), a.end(), 0);
  map<int> s;
  prime_factorization(s, sum);
  auto it = m.lower_bound(n);
  int result = 0;
  for (; it != m.end(); it++) {
    int block_size = sum / *it;
    int block_num  = *it;
    if (verify(a, k, block_size, block_num)) {
      result = block_size;
      break;
    }
  }
  cout << block_size << '\n';
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:42:13: error: 'accumulate' was not declared in this scope
   42 |   int sum = accumulate(a.begin(), a.end(), 0);
      |             ^~~~~~~~~~
a.cc:43:3: error: 'map' was not declared in this scope
   43 |   map<int> s;
      |   ^~~
a.cc:7:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    6 | #include <set>
  +++ |+#include <map>
    7 | 
a.cc:43:7: error: expected primary-expression before 'int'
   43 |   map<int> s;
      |       ^~~
a.cc:44:23: error: 's' was not declared in this scope
   44 |   prime_factorization(s, sum);
      |                       ^
a.cc:45:13: error: 'm' was not declared in this scope
   45 |   auto it = m.lower_bound(n);
      |             ^
a.cc:55:11: error: 'block_size' was not declared in this scope
   55 |   cout << block_size << '\n';
      |           ^~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  
  int n;
  long long k;
  cin>>n>>k;
  long long a[n];
  REP(i,n){
    cin>>a[i];
  }
  long long l,r,m;
  l = 1;
  r = 1e9;
  r *= 2;
  long long cnti,cntj,cnt;
  long long temp;
  while(r-l>1){
    cnti = 0;
    cntj = 0;
    m = (l+r)/2;
    REP(i,n){
      temp = a[i]%m;
      if(temp>(m/2)){
        cnti++;
      }else if(temp==0){
        continue;
      }else{
        cntj++;
      }
    }
    cnti = min(cnti,cntj);
    cntj = max(cnti,cntj);
    temp = abs(cnti-cntj);
    if(temp)
  while
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:125:3: error: expected '(' before 'return'
  125 |   return 0;
      |   ^~~~~~
      |   (
a.cc:125:3: error: expected primary-expression before 'return'
  125 |   return 0;
      |   ^~~~~~
a.cc:124:8: error: expected ')' before 'return'
  124 |   while
      |        ^
      |        )
  125 |   return 0;
      |   ~~~~~~
a.cc:126:2: error: expected '}' at end of input
  126 | }
      |  ^
a.cc:91:11: note: to match this '{'
   91 | int main(){
      |           ^
Language: C++

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

using namespace std;

void prime_factorization(set<int>& result, int x)
{
  for (int i = 1; i*i <= x; i++) {
    if (x % i == 0) {
      result.insert(i);
      result.insert(x/i);
    }
  }
}

bool verify(const vector<int>& a, int k, int block_size, int block_num)
{
  int diff = 0;
  block_num -= (int)a.size();
  for (int i = 1; i < a.size(); i++) {
    int x = a.at(i);
    int block = block_size;
    int max_block_num = x / block;
    block = block_size * min(block_num, max_block_num);
    diff += x - block;
  }
  return a.at(0) + diff == (block_size) * (block_num + 1) && diff == k;
}

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int sum = accumulate(a.begin(), a.end(), 0);
  map<int> s;
  prime_factorization(s, sum);
  auto it = m.lower_bound(n);
  int result = 0;
  for (; it != m.end(); it++) {
    int block_size = sum / *it;
    int block_num  = *it;
    if (verify(a, k, block_size, block_num)) {
      result = block_size;
      break;
    }
  }
  cout << block_size << '\n';
  return 0;
}


Compiler output:
a.cc:9:6: error: variable or field 'prime_factorization' declared void
    9 | void prime_factorization(set<int>& result, int x)
      |      ^~~~~~~~~~~~~~~~~~~
a.cc:9:26: error: 'set' was not declared in this scope
    9 | void prime_factorization(set<int>& result, int x)
      |                          ^~~
a.cc:6:1: note: 'std::set' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
    5 | #include <unordered_map>
  +++ |+#include <set>
    6 | 
a.cc:9:30: error: expected primary-expression before 'int'
    9 | void prime_factorization(set<int>& result, int x)
      |                              ^~~
a.cc:9:44: error: expected primary-expression before 'int'
    9 | void prime_factorization(set<int>& result, int x)
      |                                            ^~~
a.cc: In function 'int main()':
a.cc:41:13: error: 'accumulate' was not declared in this scope
   41 |   int sum = accumulate(a.begin(), a.end(), 0);
      |             ^~~~~~~~~~
a.cc:42:3: error: 'map' was not declared in this scope
   42 |   map<int> s;
      |   ^~~
a.cc:6:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    5 | #include <unordered_map>
  +++ |+#include <map>
    6 | 
a.cc:42:7: error: expected primary-expression before 'int'
   42 |   map<int> s;
      |       ^~~
a.cc:43:23: error: 's' was not declared in this scope
   43 |   prime_factorization(s, sum);
      |                       ^
a.cc:43:3: error: 'prime_factorization' was not declared in this scope
   43 |   prime_factorization(s, sum);
      |   ^~~~~~~~~~~~~~~~~~~
a.cc:44:13: error: 'm' was not declared in this scope
   44 |   auto it = m.lower_bound(n);
      |             ^
a.cc:54:11: error: 'block_size' was not declared in this scope
   54 |   cout << block_size << '\n';
      |           ^~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010
vll a(mx,0);
ll f(vll &a,ll n,ll x,ll k){
	ll sum=0,b[n];
	rep(i,0,n){sum+=(a[i]%x);b[i]=-1*(a[i]%x);}
	sort(b,b+n);
	// rep(i,0,n)cout<<b[i]<<" ";cout<<"\n";
	if(sum%x==0){
		ll t=sum/x;
		rep(i,0,t)sum+=b[i];
		// cout<<sum<<"\n";
		if(sum<=k)return 1;
	}
	return 0;
}
int main(){
	IOS;
	ll n,k;cin>>n>>k;
	ll p=0;
    rep(i,0,n){ll d;cin>>d;a[i]=d;p+=d;}
	// rep(i,1,20)cout<<f(a,n,i,k)<<" ";cout<<"\n";
	vll f;
	for(ll i=2;i*i<=p;++i){
		if(p%i==0){
			if(i*i==p)f.pb(i);
			else {f.pb(i);f.pb(p/i);}
		}
	}
	all(f);
	ll m=-1;
	for(ll i=f.size()-1;i>=0;--i){
		if(f(a,n,i,k){cout<<i;break;}
	}
	
	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:13:25: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::begin() [with _Tp = long long int; _Alloc = std::allocator<long long int>; iterator = std::vector<long long int>::iterator]', declared with attribute 'nodiscard' [-Wunused-result]
   13 | #define all(v) (v).begin(),(v).end()
      |                ~~~~~~~~~^~
a.cc:45:9: note: in expansion of macro 'all'
   45 |         all(f);
      |         ^~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:873:7: note: declared here
  873 |       begin() _GLIBCXX_NOEXCEPT
      |       ^~~~~
a.cc:48:21: error: no match for call to '(std::vector<long long int>) (std::vector<long long int>&, long long int&, long long int&, long long int&)'
   48 |                 if(f(a,n,i,k){cout<<i;break;}
      |                    ~^~~~~~~~~
a.cc:48:30: error: expected ')' before '{' token
   48 |                 if(f(a,n,i,k){cout<<i;break;}
      |                   ~          ^
      |                              )
a.cc:49:9: error: expected primary-expression before '}' token
   49 |         }
      |         ^
Language: C++

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const 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(ret.begin(),ret.end());
  return (ret);
}


int main(){
    int N;
    ll K;
    ll sum=0;
    ll ans=0;
    cin>>N>>K
    vector<ll> d(N);
    for(int i=0;i<N;i++) {cin>>d.at(i); sum+=d.at(i);}

    vector<ll> R=divisor(sum);
    for(int i=R.size()-1;i>=0;i--){
        ll yaku=R.at(i);
        vector<ll> kari;
        ll sum=0;
        ll a=0;
        for(int j=0;j<N;j++){
            kari.push_back(d.at(j)%yaku);
            sum+=d.at(j)%yaku;
        }

        sort(kari.begin(),kari.end());
        for(int i=0;i<(sum/yaku);i++){a+=(yaku-kari.at(kari.size()-1-i));}

        if(a<=K) {ans=yaku; break;}



    }

    cout<<ans<<endl;


}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:14: error: expected ';' before 'vector'
   25 |     cin>>N>>K
      |              ^
      |              ;
   26 |     vector<ll> d(N);
      |     ~~~~~~    
a.cc:27:32: error: 'd' was not declared in this scope
   27 |     for(int i=0;i<N;i++) {cin>>d.at(i); sum+=d.at(i);}
      |                                ^
a.cc:36:28: error: 'd' was not declared in this scope
   36 |             kari.push_back(d.at(j)%yaku);
      |                            ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int N,K;cin>>N>>K;
	int A[N];int sum=0;
	rep(i,0,N){ cin>>A[i];sum+=A[i]; }
	int s=*max_element(A,A+N);
	int check,k;int B[N];
	for(int i=s;i>0;i--){
		if(sum%i!=0) continue;
		res=0;check=0;
		rep(j,0,N){
			k=A[j]%i;
			B[j]=-k;
            check+=k;
		}if(check%i==0){
            rep(k,0,N){
                sort(B,B+N);
                int temp=accumulate(B,B+(check/i),0);
                if(check+temp<=K){
                    cout<<i<<endl;
                    return 0;
                }
            }
        }
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:17: error: 'res' was not declared in this scope; did you mean 'rep'?
   19 |                 res=0;check=0;
      |                 ^~~
      |                 rep
Language: C++

#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
//AtCoderC++.cpp

using namespace std;


inline int ceileing(int a, int b) {
	return a % b == 0 ? a / b : a / b + 1;
}
vector<int> get_divider(int n) {
	auto root = sqrt(n);
	auto result = vector<int>();
	for (size_t i = root + 1; i > 0; --i) {
		if (n%i == 0) {
			result.push_back(i);
			if (i*i != n)result.push_back(n / i);
		}
	}
	return result;
}

bool acceptable(vector<int>& as, long long sum, int div, long long K) {
	auto ave = sum / as.size() + div;
	ave -= ave % div;
	auto dis_min = 0;
	auto dis_max = 0;
	for (auto a : as) {
		if (a < ave)dis_min += a - ave;
		else dis_max += a - ave;
	}
	if (dis_min==dis_max&&dis_max<K)return true;
	ave -= div; dis_min=dis_max = 0;
	for (auto a : as) {
		if (a < ave)dis_min += a - ave;
		else dis_max += a - ave;
	}
	if (dis_min == dis_max && dis_max < K)return true;
	return false;
}

int main() {
	int N, K; cin >> N >> K;
	auto as = vector<int>(N);
	long long sum = 0;
	int max_a = 0;
	for (size_t i = 0; i < N; i++) {
		cin >> as[i];
		max_a = max(as[i], max_a);
		sum += as[i];
	}
	if (sum - max_a <= K) {
		cout << sum << endl;
		return 0;
	}
	//sumの約数が候補になる。
	auto divs = get_divider(sum);
	sort(divs.begin(), divs.end(), greater<int>());
	divs.erase(divs.begin());
	auto mod_sum = 0;
	for (auto div : divs) {
		if (acceptable(as, div, K)) {
			cout << div << endl;
			return 0;
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:73:31: error: too few arguments to function 'bool acceptable(std::vector<int>&, long long int, int, long long int)'
   73 |                 if (acceptable(as, div, K)) {
      |                     ~~~~~~~~~~^~~~~~~~~~~~
a.cc:34:6: note: declared here
   34 | bool acceptable(vector<int>& as, long long sum, int div, long long K) {
      |      ^~~~~~~~~~
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
using namespace std;

long int main()
{
	long int n, k;

	cin >> n >> k;

	vector<long int> a(n);

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

	vector<long int> div;

	for (long int i = 1; i <= sqrt(total); i++) {
		if (i == sqrt(total))
			div.push_back(i);
		else if (total % i == 0) {
			div.push_back(i);
			div.push_back(total / i);
		}
	}

	sort(div.begin(), div.end());

	long int temptotal, temptotal2;
	long int amari;
	long int flag = 0;
	for (long int i = div.size() - 1; i >= 0; i--) {
		temptotal = 0;
		temptotal2 = 0;
		for (long int j = 0; j < n; j++) {
			amari = a[j] % div[i];
			temptotal += amari;
			if (div[i] % 2 == 0 && amari == div[i] / 2) {
				if (flag == 0)
					flag = 1;
				else {
					flag = 0;
					temptotal2 += amari;
				}
			}else if((div[i] % 2 == 0 && amari < div[i] / 2) || (div[i] % 2 == 1 && amari < (div[i] + 1) / 2))
				temptotal2 += amari;
		}
		if (temptotal % div[i] == 0 && temptotal2 <= k) {
			cout << div[i] << endl;
			break;
		}
	}

	return 0;
}


Compiler output:
a.cc:9:6: error: '::main' must return 'int'
    9 | long int main()
      |      ^~~
Language: C++

#include<bits/stdc++.h>
#include<random>
#include <chrono>
#define lowbit(i) (i&(-i))
using namespace std;

namespace _ {
	bool rEOF = 1;//为0表示文件结尾
	inline char nc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return p1 == p2 && rEOF && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? (rEOF = 0, EOF) : *p1++;
	}
	template<class _T>
	inline bool read(_T &num) {
		char c = nc(), f = 1; num = 0;
		while (c<'0' || c>'9')c == '-' && (f = -1), c = nc();
		while (c >= '0'&&c <= '9')num = num * 10 + c - '0', c = nc();
		return (bool)(num *= f);
	}
	inline bool need(char &c) { return c >= 'A'&&c <= 'z' || c >= '0'&&c <= '9' || c >= 'A'&&c <= 'Z'; }//读入的字符范围
	inline bool read_str(char *a) {
		while ((*a = nc()) && need(*a) && rEOF)++a;
		*a = '\0'; return rEOF;
	}
}using namespace _;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

long long n, k;
long long sum = 0;
long long a[505 + 5];
vector<long long>que;


bool check(long long g)
{
	long long res = 0;
	long long b1 = 0, b2 = 0, sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (vis[i])continue;
		long long L = a[i] / g * g;
		long long R = (a[i] + g - 1) / g * g;
		if (R - a[i] <= k && a[i] - L > k)
			b1 += (R - a[i]);
		else if (R - a[i] > k && a[i] - L <= k)
			b2 += (a[i] - L);
		else if (R - a[i] <= k && a[i] - L <= k)
		{
			if (b1 + R - a[i] <= b2+ a[i] - L)
				b1 += (R - a[i]);
			else
				b2 += (a[i] - L);
		}
		else
			return 0;
	}

	return b1==b2&&max(b1, b2) <= k;
}

int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> a[i], sum += a[i];
	sort(a + 1, a + 1 + n);
	for (long long i = 1; i*i <= sum; i++)
	{
		if (sum%i == 0)
		{
			que.push_back(i);
			if (i != sum / i)que.push_back(sum / i);
		}
	}
	sort(que.begin(), que.end(), [](long long a, long long b) {return a > b; });
	for (int i = 0; i < que.size(); i++)
	{
		if (check(que[i]))
		{
			printf("%lld\n", que[i]);
			break;
		}
	}
	return 0;
}


Compiler output:
a.cc: In function 'bool check(long long int)':
a.cc:48:21: error: 'vis' was not declared in this scope
   48 |                 if (vis[i])continue;
      |                     ^~~
Language: C++

#include "pch.h"
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

void e()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}
	// sumの約数が答えとなりうる

	priority_queue<int> cds;
	for (int i = 1; i < sqrt(sum); i++) {
		if (sum %i == 0) {
			cds.push(i);
			cds.push(sum / i);
		}
	}

	while (! cds.empty()) {
		//cout << cds.top() << " ";
		int target = cds.top();
		cds.pop();

		// 必要な計算回数を調査
		vector<int> t(n);
		for (int i = 0; i < n; i++) {
			t[i] = a[i] % target;
		}
		sort(t.begin(), t.end());
		//for (int i = 0; i < n; i++) {
		//	cout << t[i] << " ";
		//}

		int left = 0;
		int right = n - 1;
		int count = 0;
		while (left < right) {
			if (t[left] == 0) {
				left++;
			}
			if (t[right] >= target) {
				t[right - 1] += (t[right] - target);
				t[right] = target;
				right--;
			}
			t[right] += t[left];
			count += t[left];
			t[left] = 0;
			left++;
		}

		if (count < k) {
			cout << target << endl;
			break;
		}
	}
}

int main()
{
	e();

	return 0;
}


Compiler output:
a.cc:1:10: fatal error: pch.h: No such file or directory
    1 | #include "pch.h"
      |          ^~~~~~~
compilation terminated.