let N,K = stdin.ReadLine().Split() |> fun x -> int x.[0], int64 x.[1]
let lists = stdin.ReadLine().Split() |> Array.map int |> Array.zip <| (stdin.ReadLine().Split() |> Array.map int64)

let rec calcScore start score times =
    if times = 0L then score
    else 
        let p,_ = lists.[start]
        let _,c = lists.[p-1]
        calcScore (p-1) (score+c) (times-1L)

[for k in [1L..K] do for i in [0..N-1] do (calcScore i 0L k)] |> List.max |> stdout.WriteLine