#include "partition.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int NMAX=2e6+505;
int a[4*NMAX+505];
int b[4*NMAX+505];
long long sum[4*NMAX+505];
std::vector<int> solve(std::vector<int> A) {
    int n=A.size();
    vector <int> ras;
    for (int i=0;i<n;++i)
        a[i]=a[i+n]=a[i+2*n]=A[i];
    for (int i=0;i<n;++i)
        b[i]=b[i+n]=b[i+2*n]=i;
    sum[0]=a[0];
    for (int i=1;i<=2*n;++i)
    {
        sum[i]=sum[i-1]+a[i];
    }
    int ok=1;
    int m=(n+1)/2;
    for (int i=m;i<=m+n+1;++i)
    {
        if (sum[n-1]>2*(sum[i]-sum[i-m])) {ok=0;}
        else {
            if (ok==0)
            {
                for (int j=i-m+1;j<=i;++j)
                {
                    ras.push_back(b[j]);
                }
                for (int j=i+1;j<i-m+1+n;++j)
                    ras.push_back(b[j]);
                    return ras;
            }
        }
    }
    for (int j=0;j<n;++j)
        ras.push_back(j);
    return ras;

}