Language: C++

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    vi c(26);
    rep(i, 26) cin >> c[i];
    vvi s(D, vi(26));
    rep(i, D) rep(j, 26) {
        cin >> s[i][j];
    }

    vi t(D);
    vi last(26);
    rep(d, D) {
        int ma = INT_MIN, nn = 23;
        rep(i, 26) {
            int ggh = 0;
            ggh += s[d][i];
            rep(j, 26) {
                if(i == j) continue;
                ggh -= c[j]*(d+1-last[j]);
            }
            if(chmax(ma, ggh)) {
                nn = i;
            }
        }
        last[nn] = d+1;
        t[d] = nn;
    }
    last.assign(26, 0);
    vector<set<int> > se(26);
    rep(i, 26) {
        se[i].insert(D);
    }
    ll gh = 0;
    rep(d, D) {
        se[t[d]].insert(d);
        gh += s[d][t[d]];
        last[t[d]] = d+1;
        rep(j, 26) {
            gh -= c[j]*(d+1-last[j]);
        }
    }

    vvi bits(26, vi(D+1));
    auto add = [&](int al, int d, int x) {
        while(d <= D) {
            bits[al][d] += x;
            d += d&-d;
        }
    };
    auto sum = [&](int al, int d) {
        if(d == 0) return 0;
        int res = 0;
        while(d) {
            res += bits[al][d];
            d &= d-1;
        }
        return res;
    };


    rep(i, D) {
        rep(j, 26) {
            add(j, i+1, 1);
        }
    }

    rep(i, D) {
        int now = sum(t[i], i+1);
        add(t[i], i+1, -now);
    }

    int X = 1000;
    while(X--) {
        int nn = X%D, ma = INT_MIN, dd = X%26;
        rep(i, 26) {
            int mma = INT_MIN;
            int di;
            if(se[i].size() > 1) {
                for(auto itr = se[i].begin(); itr != prev(se[i].end()); itr = next(itr)) {
                    if(chmax(mma, *next(itr)-*itr)) {
                        di = (*next(itr)+*itr)/2;
                    }
                }
            }
            if(chmax(ma, mma*c[i])) {
                dd = i;
                nn = di;
            }
        }
        int mi = INT_MAX;
        int nnn = nn;
        for(int j = max(0, nn-5), j < min(D, nn+5); j++) {
            auto itr = se[t[j]].upper_bound(j);
            if(chmin(mi, (*itr-j)*(sum(t[j], j)+1) * c[t[j]])) {
                nnn = j;
            }
        }
        nn = nnn;
        int nowd = nn;
        int nowal = dd;
        if(t[nowd] == nowal) continue;
        ll nowgh = gh;
        nowgh += s[nowd][nowal]-s[nowd][t[nowd]];
        auto itr = se[nowal].lower_bound(nowd);
        nowgh += (*itr - nowd)*sum(nowal, nowd+1) * c[nowd];
        itr = se[t[nowd]].upper_bound(nowd);
        nowgh -= (*itr-nowd)*(sum(t[nowd], nowd)+1) * c[t[nowd]];
        if(nowgh > gh) {
            add(t[nowd], nowd+1, sum(t[nowd], nowd)+1);
            add(nowal, nowd+1, -sum(nowal, nowd+1));
            se[t[nowd]].erase(nowd);
            se[nowal].insert(nowd);
            t[nowd] = nowal;
            gh = nowgh;
        }
    }

    rep(i, D) {
        cout << t[i]+1 << endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:122:36: error: expected ';' before '<' token
  122 |         for(int j = max(0, nn-5), j < min(D, nn+5); j++) {
      |                                    ^~
      |                                    ;
a.cc:122:37: error: expected primary-expression before '<' token
  122 |         for(int j = max(0, nn-5), j < min(D, nn+5); j++) {
      |                                     ^