Handbags
The Lady Checked Her Luggage...
S.Ya.Marshak
Katya is preparing for a trip to an olympiad in the distant city of Peterhof. Naturally, she needs to bring n bags with her. To avoid extra luggage fees, Katya has cleverly nested some bags inside others.
After gathering all n bags she plans to take, Katya suddenly realizes that her favorite plush chipmunk might be in the wrong bag. Your task is to determine how many bags need to be opened to move it to the correct one.
Input
The first line of the input contains three integers n, a, and b - representing the number of bags, the current bag number where the chipmunk is located, and the target bag number where it should be placed (1 ≤ n ≤ 100, 1 ≤ a, b ≤ n).
The second line contains n numbers: for each bag, the number 0 if it is not inside any other bag, or the number of the bag it is inside. A bag can only be inside a bag with a smaller number.
Bags are numbered starting from one. Initially, all of them are closed.
Output
Output a single integer - the number of bags that need to be opened.