Problems with big numbers taken modulo some small number discriminate Python. ©Some blue guy on Codeforces.
You are given a directed rooted tree. All edges are directed away from the root. Each edge has length which is a power of 2. The root of the tree has number 1.
Let's define two terms, which will depend on each other --- a trip from vertex v, and a journey to vertex v.
A journey to some vertex v always starts from its parent p (it means that a journey to the root of the tree may never occur) and consists of three steps:
A trip from vertex v is the following procedure:
Note that any trip or journey always starts and ends at the same vertex.
Length of the trip is the total length of all traversed edges with multiplicity during the trip.
What is the maximum length of a trip from the root? Calculate it modulo 998,244,353.
The first line of input contains a single integer n (2≤n≤105), the number of vertices in the tree.
Next n−1 lines describe the tree. i-th of these lines contains two integers p_i and c_i (1≤p_i≤i,0≤c_i≤1018) describing an edge between vertices p_i and i+1 with length 2c_i.
Output a single integer, the maximum length of a trip from the root modulo 998,244,353.