Language: C++

using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);
        string[] As = Console.ReadLine().Split(' ');
        int[] A = new int[N];
        for (var i = 0; i < N; i++)
        {
            A[i] = int.Parse(As[i]);
        }
        int sum = 0;
        for (var i = 0; i < N; i++)
        {
            sum += A[i];
        }
        int ans = 1;
        for (var d = sum; d >= 1; d--)
        {
            if (sum % d == 0)
            {
                int[] ct_mod = new int[d];
                for (var i = 0; i < N; i++)
                {
                    ct_mod[A[i] % d]++;
                }
                int diff_sum_p = 0;
                int diff_sum_m = 0;
                for (var i = 1; i <= (d-1)/2; i++)
                {
                    diff_sum_m += ct_mod[i] * i;
                    diff_sum_p += ct_mod[d-i] * i;
                }
                if (d % 2 == 0)
                {
                    var i = d / 2;
                    diff_sum_m += ct_mod[i] * i;
                }
                int dc = (diff_sum_p-diff_sum_m)/d;
                if (dc < 0)
                {
                    for (var i = d/2; i > 0 && dc != 0; i--)
                    {
                        int mov = Math.Min(-dc, ct_mod[i]);
                        diff_sum_m -= i*mov;
                        diff_sum_p += (d-i)*mov;
                        dc += mov;
                    }
                }
                if (dc > 0)
                {
                    for (var i = (d-1)/2; i > 0 && dc != 0; i--)
                    {
                        int mov = Math.Min(dc, ct_mod[d-i]);
                        diff_sum_p -= i * mov;
                        diff_sum_m += (d - i) * mov;
                        dc -= mov;
                    }
                }
                if (dc == 0 && diff_sum_p <= K)
                {
                    ans = d;
                    break;
                }
            }
        }
        Console.WriteLine(ans);
    }
}


Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:4:22: error: 'string' has not been declared
    4 |     static void Main(string[] args)
      |                      ^~~~~~
a.cc:4:31: error: expected ',' or '...' before 'args'
    4 |     static void Main(string[] args)
      |                               ^~~~
a.cc:72:2: error: expected ';' after class definition
   72 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Program::Main(int*)':
a.cc:6:9: error: 'string' was not declared in this scope
    6 |         string[] input = Console.ReadLine().Split(' ');
      |         ^~~~~~
a.cc:6:16: error: expected primary-expression before ']' token
    6 |         string[] input = Console.ReadLine().Split(' ');
      |                ^
a.cc:7:17: error: expected primary-expression before 'int'
    7 |         int N = int.Parse(input[0]);
      |                 ^~~
a.cc:8:17: error: expected primary-expression before 'int'
    8 |         int K = int.Parse(input[1]);
      |                 ^~~
a.cc:9:16: error: expected primary-expression before ']' token
    9 |         string[] As = Console.ReadLine().Split(' ');
      |                ^
a.cc:10:12: error: structured binding declaration cannot have type 'int'
   10 |         int[] A = new int[N];
      |            ^~
a.cc:10:12: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:10:12: error: empty structured binding declaration
a.cc:10:15: error: expected initializer before 'A'
   10 |         int[] A = new int[N];
      |               ^
a.cc:11:14: error: 'var' was not declared in this scope
   11 |         for (var i = 0; i < N; i++)
      |              ^~~
a.cc:11:25: error: 'i' was not declared in this scope
   11 |         for (var i = 0; i < N; i++)
      |                         ^
a.cc:13:13: error: 'A' was not declared in this scope
   13 |             A[i] = int.Parse(As[i]);
      |             ^
a.cc:13:20: error: expected primary-expression before 'int'
   13 |             A[i] = int.Parse(As[i]);
      |                    ^~~
a.cc:16:14: error: 'var' was not declared in this scope
   16 |         for (var i = 0; i < N; i++)
      |              ^~~
a.cc:16:25: error: 'i' was not declared in this scope
   16 |         for (var i = 0; i < N; i++)
      |                         ^
a.cc:18:20: error: 'A' was not declared in this scope
   18 |             sum += A[i];
      |                    ^
a.cc:21:14: error: 'var' was not declared in this scope
   21 |         for (var d = sum; d >= 1; d--)
      |              ^~~
a.cc:21:27: error: 'd' was not declared in this scope
   21 |         for (var d = sum; d >= 1; d--)
      |                           ^
a.cc:25:20: error: structured binding declaration cannot have type 'int'
   25 |                 int[] ct_mod = new int[d];
      |                    ^~
a.cc:25:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:25:20: error: empty structured binding declaration
a.cc:25:23: error: expected initializer before 'ct_mod'
   25 |                 int[] ct_mod = new int[d];
      |                       ^~~~~~
a.cc:26:26: error: expected ';' before 'i'
   26 |                 for (var i = 0; i < N; i++)
      |                          ^
a.cc:26:33: error: 'i' was not declared in this scope
   26 |                 for (var i = 0; i < N; i++)
      |                                 ^
a.cc:28:21: error: 'ct_mod' was not declared in this scope
   28 |                     ct_mod[A[i] % d]++;
      |                     ^~~~~~
a.cc:28:28: error: 'A' was not declared in this scope
   28 |                     ct_mod[A[i] % d]++;
      |                            ^
a.cc:32:26: error: expected ';' before 'i'
   32 |                 for (var i = 1; i <= (d-1)/2; i++)
      |                          ^
a.cc:32:33: error: 'i' was not declared in this scope
   32 |                 for (var i = 1; i <= (d-1)/2; i++)
      |                                 ^
a.cc:34:35: error: 'ct_mod' was not declared in this scope
   34 |                     diff_sum_m += ct_mod[i] * i;
      |                                   ^~~~~~
a.cc:39:25: error: expected ';' before 'i'
   39 |                     var i = d / 2;
      |                         ^
a.cc:40:35: error: 'ct_mod' was not declared in this scope
   40 |                     diff_sum_m += ct_mod[i] * i;
      |                                   ^~~~~~
a.cc:40:42: error: 'i' was not declared in this scope
   40 |                     diff_sum_m += ct_mod[i] * i;
      |                                          ^
a.cc:45:30: error: expected ';' before 'i'
   45 |                     for (var i = d/2; i > 0 && dc != 0; i--)
      |                              ^
a.cc:45:39: error: 'i' was not declared in this scope
   45 |                     for (var i = d/2; i > 0 && dc != 0; i--)
      |                                       ^
a.cc:47:35: error: 'Math' was not declared in this scope
   47 |                         int mov = Math.Min(-dc, ct_mod[i]);
      |                                   ^~~~
a.cc:47:49: error: 'ct_mod' was not declared in this scope
   47 |                         int mov = Math.Min(-dc, ct_mod[i]);
      |                                                 ^~~~~~
a.cc:55:30: error: expected ';' before 'i'
   55 |                     for (var i = (d-1)/2; i > 0 && dc != 0; i--)
      |                              ^
a.cc:55:43: error: 'i' was not declared in this scope
   55 |                     for (var i = (d-1)/2; i > 0 && dc != 0; i--)
      |                                           ^
a.cc:57:35: error: 'Math' was not declared in this scope
   57 |                         int mov = Math.Min(dc, ct_mod[d-i]);
      |                                   ^~~~
a.cc:57:48: error: 'ct_mod' was not declared in this scope
   57 |                         int mov = Math.Min(dc, ct_mod[d-i]);
      |                                                ^~~~~~
a.cc:70:9: error: 'Console' was not declared in this scope
   70 |         Console.WriteLine(ans);
      |         ^~~~~~~