use proconio::input;
use rand::prelude::*;
use rand::{Rng, SeedableRng};
use std::collections::BTreeSet;

fn eval_lasts(days: i64, cs: &Vec<i64>, schedule: &Vec<BTreeSet<i64>>) -> i64 {
    let mut score = 0;

    for i in 0..cs.len() {
        let mut last = -1;

        for d in schedule[i].iter() {
            let x = d - last;
            let n = (x * (x - 1)) / 2;
            score -= cs[i] * n;
            last = *d;
        }
        let x = days - last;
        let n = (x * (x - 1)) / 2;
        score -= cs[i] * n;
    }

    score
}

fn eval(
    days: u64,
    cs: &Vec<i64>,
    sats: &Vec<Vec<i64>>,
    ts: &Vec<u64>,
) -> (i64, Vec<BTreeSet<i64>>) {
    let mut score = 0;

    let mut schedule = vec![BTreeSet::<i64>::new(); 26];

    for day in 0usize..(days as usize) {
        let contest = ts[day as usize] as usize;
        score += sats[day][contest] as i64;
        schedule[contest].insert(day as i64);
    }

    (score, schedule)
}

//fn swap_state(&mut schedule: Vec<BTreeSet<i64>>, day_a: usize, day_b: usize)swap_state(&mut schedule: Vec<BTreeSet<i64>>, day_a: usize, day_b: usize) {}

fn main() {
    input! { days: u64 };
    let mut cs = vec![0; 26];

    for i in 0..26 {
        input! {
            x: i64
        };

        cs[i] = x;
    }

    let mut sats = vec![vec![0; 26]; days as usize];
    for d in 0..days {
        for i in 0..26 {
            input! {
                s: i64
            };

            sats[d as usize][i as usize] = s;
        }
    }

    let mut ts = vec![0u64; days as usize];
    for i in 0..ts.len() {
        ts[i] = (i as u64) % 26;
    }

    let (mut base_score, mut schedule) = eval(days, &cs, &sats, &ts);

    let mut cur_score = base_score + eval_lasts(days as i64, &cs, &schedule);

    let seed = [1u8; 32];
    let mut rng: StdRng = SeedableRng::from_seed(seed);

    let s2 = eval_lasts(days as i64, &cs, &schedule);
    eprintln!("INIT: base_score: {}, s2: {}", base_score, s2);
    eprintln!("INIT: total: {}", base_score + s2);

    for _ in 0..300000 {
        // Swap `day_a` and `day_b`
        let day_a = rng.gen::<usize>() % (days - 1) as usize;
        let day_b = day_a + ((rng.gen::<usize>() % 8) - 4);
        if day_b >= days as usize {
            continue;
        }

        let prev_contest_a = ts[day_a as usize] as usize;
        let prev_contest_b = ts[day_b as usize] as usize;

        let mut next_score = base_score;
        next_score -= sats[day_a][prev_contest_a];
        next_score -= sats[day_b][prev_contest_b];
        schedule[prev_contest_a].remove(&(day_a as i64));
        schedule[prev_contest_b].remove(&(day_b as i64));

        next_score += sats[day_a][prev_contest_b];
        next_score += sats[day_b][prev_contest_a];
        schedule[prev_contest_a].insert(day_b as i64);
        schedule[prev_contest_b].insert(day_a as i64);

        let s2 = eval_lasts(days as i64, &cs, &schedule);

        if next_score + s2 > cur_score {
            base_score = next_score;
            cur_score = next_score + s2;
            ts[day_a as usize] = prev_contest_b as u64;
            ts[day_b as usize] = prev_contest_a as u64;
        } else {
            schedule[prev_contest_a].remove(&(day_b as i64));
            schedule[prev_contest_b].remove(&(day_a as i64));

            schedule[prev_contest_a].insert(day_a as i64);
            schedule[prev_contest_b].insert(day_b as i64);
        }
    }
    let s2 = eval_lasts(days as i64, &cs, &schedule);

    eprintln!("base_score: {}, s2: {}", base_score, s2);
    eprintln!("total: {}", base_score + s2);

    for t in ts {
        println!("{}", t + 1);
    }
}


Measured memory_bytes: 2344