#![allow(non_snake_case)]

use std::io::Read;

use rand::prelude::*;
use rand_pcg::Pcg64Mcg;

const ALPHA_SIZE: usize = 26;
const TIME_LIMIT: f64 = 1.8;

pub trait SetMinMax {
    fn set_min(&mut self, v: Self) -> bool;
    fn set_max(&mut self, v: Self) -> bool;
}

impl<T> SetMinMax for T where T: PartialOrd {
    fn set_min(&mut self, v: Self) -> bool {
        *self > v && {
            *self = v;
            true
        }
    }

    fn set_max(&mut self, v: Self) -> bool {
        *self < v && {
            *self = v;
            true
        }
    }
}

struct Timer {
    start_time: f64
}

fn get_time_sec() -> f64 {
    let t = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap();
    t.as_secs() as f64 + t.subsec_nanos() as f64 * 1e-9
}

impl Timer {
    fn new() -> Timer {
        Timer {
            start_time: get_time_sec()
        }
    }

    fn get_elapsed_time_sec(self: &Self) -> f64 {
        get_time_sec() - self.start_time
    }
}


#[derive(Clone)]
struct State<'a> {
    D: usize,
    C: &'a Vec<i32>,
    S: &'a Vec<Vec<i32>>,
    actions: Vec<usize>,
}


impl<'a> State<'a> {
    fn create(D: usize, C: &'a Vec<i32>, S: &'a Vec<Vec<i32>>, actions: Vec<usize>) -> State<'a> {
        assert_eq!(actions.len(), D);
        assert_eq!(S[0].len(), ALPHA_SIZE);
        return State { D, C, S, actions };
    }

    fn score(self: &Self) -> i32 {
        let mut score = 0;
        let mut last: Vec<i32> = vec![-1; ALPHA_SIZE];
        for d in 0..self.actions.len() {
            let diff = d as i32 - last[self.actions[d]];
            score += self.S[d][self.actions[d]];
            score -= diff * (diff - 1) / 2 * self.C[self.actions[d]];
            last[self.actions[d]] = d as i32;
        }
        for c in 0..ALPHA_SIZE {
            let diff = self.actions.len() as i32 - last[c];
            score -= diff * (diff - 1) / 2 * self.C[c]
        }
        score
    }


    fn change_action(self: &mut Self, date: usize, action: usize) {
        self.actions[date] = action
    }

    fn swap_actions(self: &mut Self, d1: usize, d2: usize) {
        let action = self.actions[d1];
        self.change_action(d1, self.actions[d2]);
        self.change_action(d2, action);
    }
}

struct Solver {
    D: usize,
    C: Vec<i32>,
    S: Vec<Vec<i32>>,
    timer: Timer,
}

impl Solver {
    fn create() -> Solver {
        let mut buffer = String::new();
        std::io::stdin().read_to_string(&mut buffer).unwrap();
        let mut iter = buffer.split_whitespace();
        let D = iter.next().unwrap().parse::<usize>().unwrap();

        let C: Vec<i32> = (0..ALPHA_SIZE)
            .map(|_| iter.next().unwrap().parse::<i32>().unwrap())
            .collect();
        let S: Vec<Vec<i32>> = (0..D)
            .map(|_| {
                (0..ALPHA_SIZE)
                    .map(|_| iter.next().unwrap().parse::<i32>().unwrap())
                    .collect()
            })
            .collect();
        Solver { D, C, S, timer: Timer::new() }
    }

    fn hill_climbing(self: &Self, start_state: Vec<usize>) -> Vec<usize> {
        let mut state = State::create(self.D, &self.C, &self.S, start_state);
        let mut update_count = 0;
        let mut best_score = state.score();
        while self.timer.get_elapsed_time_sec() < TIME_LIMIT {
            for d in 0..self.D {
                for a in 0..ALPHA_SIZE {
                    let curr_actoin = state.actions[d];
                    state.change_action(d, a);
                    let new_score = state.score();
                    if best_score.set_max(new_score) {
                        eprintln!("[{}: Modify] Change the best score to {} (time = {})",
                                  update_count, best_score, self.timer.get_elapsed_time_sec());
                        update_count += 1;
                    } else {
                        state.change_action(d, curr_actoin)
                    }
                }
            }

            for d in 0..self.D - 1 {
                state.swap_actions(d, d + 1);
                let new_score = state.score();
                if best_score.set_max(new_score) {
                    eprintln!("[{}: Swap] Change the best score to {} (time = {})",
                              update_count, best_score, self.timer.get_elapsed_time_sec());
                    update_count += 1;
                } else {
                    state.swap_actions(d, d + 1)
                }
            }
        }
        state.actions
    }

    fn annealing_update(old_score: i32, new_score: i32, temperature: f64, rng: &mut Pcg64Mcg) -> bool {
        let diff = new_score - old_score;
        diff > 0 || rng.gen_bool(f64::exp(diff as f64 / temperature))
    }

    fn annealing(self: &Self, initial_actions: Vec<usize>) -> Vec<usize> {
        const T_MAX: f64 = 2000.;
        const T_MIN: f64 = 600.;
        let mut temperature = T_MAX;
        let mut rng = rand_pcg::Pcg64Mcg::new(1);
        let mut state = State::create(self.D, &self.C, &self.S, initial_actions.clone());
        let mut loop_count = 0;
        let mut update_count = 0;
        let mut best_score = state.score();
        let mut curr_score = best_score;
        let mut best_actions = initial_actions;
        let swap_prob = 0.5;
        let swap_max_offset = 16;

        loop {
            loop_count += 1;
            if loop_count % 100 == 0 {
                let t = self.timer.get_elapsed_time_sec() / TIME_LIMIT;
                if t >= 1. {
                    break;
                } else {
                    temperature = T_MAX.powf(1.0 - t) * T_MIN.powf(t);
                }
            }

            if rng.gen_bool(swap_prob) {
                let d1 = rng.gen_range(0, self.D - 1);
                let d2 = rng.gen_range(d1 + 1, (d1 + swap_max_offset).min(self.D));
                state.swap_actions(d1, d2);
                let new_score = state.score();
                if Solver::annealing_update(curr_score, new_score, temperature, &mut rng) {
                    curr_score = new_score;
                } else {
                    state.swap_actions(d1, d2);
                }
            } else {
                let d = rng.gen_range(0, self.D);
                let a = rng.gen_range(0, ALPHA_SIZE);
                let curr_action = state.actions[d];
                state.change_action(d, a);
                let new_score = state.score();
                if Solver::annealing_update(curr_score, new_score, temperature, &mut rng) {
                    curr_score = new_score;
                } else {
                    state.change_action(d, curr_action)
                }
            }

            if best_score.set_max(curr_score) {
                eprintln!("[{}] Change the best score to {} (time = {})",
                          update_count, best_score, self.timer.get_elapsed_time_sec());
                best_score = curr_score;
                best_actions = state.actions.clone();
                update_count += 1;
            }
        }
        best_actions
    }

    pub fn solve(self: &Self) -> Vec<usize> {
        let mut rng = rand_pcg::Pcg64Mcg::new(1);
        let start_actions = (0..self.D).map(|_| rng.gen_range(0, ALPHA_SIZE)).collect();
        self.annealing(start_actions)
    }
}

fn main() {
    let solver = Solver::create();
    for action in solver.solve() {
        println!("{}", action + 1);
    }
}


Measured memory_bytes: 3276