Big Numbers

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

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 vv, and a journey to vertex vv.

A journey to some vertex vv always starts from its parent pp (it means that a journey to the root of the tree may never occur) and consists of three steps:

  1. Traverse pp-vv edge (the edge from pp to vv).
  2. Make a trip from vv.
  3. Teleport from vertex vv to vertex pp without traversing any edges.

A trip from vertex vv is the following procedure:

  1. Make a journey to all of the children of vv (if any).
  2. If vv has at least one child, make a journey to some child of vv one more time.

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,353998\\,244\\,353.

입력

The first line of input contains a single integer nn (2n1052 \leq n \leq 10^5), the number of vertices in the tree.

Next n1n - 1 lines describe the tree. ii-th of these lines contains two integers p_ip\_i and c_ic\_i (1p_ii,0c_i10181 \leq p\_i \leq i, 0 \leq c\_i \leq 10^{18}) describing an edge between vertices p_ip\_i and i+1i+1 with length 2c_i2^{c\_i}.

출력

Output a single integer, the maximum length of a trip from the root modulo 998,244,353998\\,244\\,353.