let () = Scanf.scanf "%d\n" @@ fun n ->
  let sts = Array.init n @@ fun _ -> Scanf.scanf "%s %d\n" @@ fun s t -> s, t in
  Scanf.scanf "%s\n" @@ fun x ->
    Printf.printf "%d\n" @@
    snd @@
    List.find (fun (s, _) -> s = x) @@
    snd @@
    Array.fold_right (fun (s, t) (sum, acc) ->
      (sum + t, (s, sum) :: acc)) sts (0, [])