open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let Read3Int () = ReadNextInt (), ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

    let ReadList n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop (ReadNext () :: acc) (c-1)
        loop [] n

open InputUtility

module ARC083 =
    let private Mod = 1000000007L

    let private BichromeTree () =
        let curOO = System.Int32.MaxValue / 2
        let n = ReadNextInt ()
        let p =
            let lst = List.init n (fun _ -> new System.Collections.Generic.List<_> ())
            let rec loop i =
                if i >= n then lst
                else
                    let p = ReadNextInt ()
                    lst.[p - 1].Add i
                    loop (i + 1)
            loop 1
        let x = ReadListOf int n
        let gf, uf =
            let len = 5120
            let inner = Array.init 2 (fun _ -> Array.zeroCreate len)
            let mutable d = 0
            let getArr u =
                let r = inner.[d]
                d <- 1 - d
                for i in [0..u] do r.[i] <- curOO
                r
            let updateArr (a: _ array) u i d =
                if i <= u then a.[i] <- min a.[i] d
            getArr, updateArr
        let rec check c =
            let cs = p.[c]
            let cr = cs |> Seq.map check |> Seq.cache
            if cr |> Seq.forall Option.isSome then
                let u = x.[c]
                let mutable f = gf u
                f.[0] <- 0
                //printfn "init %A: %A" (c + 1) f
                for (y, z) in cr |> Seq.map Option.get do
                    let g = gf u
                    for i in [u .. -1 .. 0] do
                        uf g u (i + y) (f.[i] + z)
                        uf g u (i + z) (f.[i] + y)
                    //printfn "after %A: %A" (y, z) g
                    f <- g
                let r = if u = 0 then 0 else f |> Seq.take (u + 1) |> Seq.min
                //printfn "%d: %A" (c + 1) (Some (x.[c], r))
                if r < curOO then Some (x.[c], r) else None
            else None
        let r = check 0
        if Option.isSome r then "POSSIBLE" else "IMPOSSIBLE"
        |> printfn "%s"

    let Entry = BichromeTree

ARC083.Entry ()

Measured memory_bytes: 37908