Scanf.scanf "%d" (fun d ->
    let c = Array.init 26 (fun _ -> Scanf.scanf " %d" (fun c -> c)) in
    let s = Array.init d (fun _ ->
        Array.init 26 (fun _ ->
            Scanf.scanf " %d" (fun s -> s)))
    in
    let last = Array.make 26 (-1) in
    let t = Array.make d 0 in
    for i = 0 to d - 1 do
        let rec loop j mi mx =
            if j = 26 then (last.(mi) <- i; t.(i) <- mi) else
                if s.(i).(j) + c.(j) * (i - last.(j)) > mx then loop (j + 1) j (s.(i).(j) + c.(j) * (i - last.(j)))
                                                           else loop (j + 1) mi mx
        in
        loop 0 0 0
    done;
    let basicsat =
        let rec loop i acc =
            if i = d then acc else loop (i + 1) (acc + s.(i).(t.(i)))
        in
        loop 0 0
    in
    let module S = Set.Make (struct type t = int let compare = compare end) in
    let last = Array.make 26 (S.add d @@ S.singleton (-1)) in
    Array.iteri (fun i t -> last.(t) <- S.add i last.(t)) t;

    let f a = a * (a - 1) / 2 in

    let reducesat =
        let calc set =
            let rec loop prev acc = function
            | [] -> acc
            | hd :: tl -> loop hd (acc + f (hd - prev)) tl
            in
            match S.elements set with
            | hd :: tl -> loop hd 0 tl
            | [] -> 0
        in
        let rec loop i acc =
            if i = 26 then acc else loop (i + 1) (acc + c.(i) * calc last.(i))
        in
        loop 0 0
    in

    let trycalc a b =
        let pre = t.(a) in
        if pre = b then 0 else
        let p1, _, p2 = S.split a last.(pre) in
        let p1m = S.max_elt p1 in
        let p2m = S.min_elt p2 in
        let delta = c.(pre)* f (a - p1m) + f (p2m - a) - f (p2m - p1m) - s.(a).(pre) in

        let p1, _, p2 = S.split a last.(b) in
        let p1m = S.max_elt p1 in
        let p2m = S.min_elt p2 in
        let delta = c.(b) * (- f (a - p1m) - f (p2m - a) + f (p2m - p1m)) + s.(a).(b) in
        delta
    in
    let apply a b =
        let pre = t.(a) in
        last.(pre) <- S.remove a last.(pre);
        last.(b)   <- S.add    a last.(b);
        t.(a) <- b
    in
    for i = 1 to 10 do
        let rec loop_a a acc =
            let rec loop_b b ((ma, mb, md) as acc) =
                if b = 26 then acc else
                    let d = trycalc a b in
                    if d > md then loop_b (b + 1) (a, b, d)
                              else loop_b (b + 1) acc
            in
            if a = d then acc else loop_a (a + 1) (loop_b 0 acc)
        in
        let a, b, d = loop_a 0 (0, 0, min_int) in

        apply a b;
    done;
    Array.iter (fun c -> Printf.printf "%d\n" (c + 1)) t
)