Under construction

Still being built. Things may change

Trade

Time limit1.5sMemory limit1024 MB

Summary
Sum all pairwise shortest distances in a complete binary tree with upward edges and m ancestor-to-descendant edges, modulo 998244353.
Level

Hard8 of 10

Topics
Shortest path, Tree, Divide and conquer
Solved
No attempts yet

Problem

In recent years, commercial development in country A has been rapid, but domestic road construction has not kept up with it. This clearly restricts people's trade and worries the managers greatly.

Specifically, country A has 2n−12^n-1 cities, and city 11 is the capital. For every non-capital city ii, there is a single one-way road from city ii to city ⌊i2⌋\lfloor \frac{i}{2}\rfloor. These are called "first-class roads", and city ⌊i2⌋\lfloor \frac{i}{2}\rfloor is called the "superior city" of city ii.

In addition, there are mm directed roads. The ii-th road goes from city uiu_i to city viv_i. All of them have one special property: starting from city viv_i and repeatedly walking along first-class roads toward the superior city, one can always reach city uiu_i. These roads are called "second-class roads".

Each road has a length. For any two cities xx and yy, let dist(x,y)\mathrm{dist}(x, y) be the minimum total length of the roads on a path from xx to yy. Some pairs may be unreachable because of serious defects in the road construction. In that case dist(x,y)\mathrm{dist}(x, y) is defined as 00. A city needs no road to reach itself, so dist(x,x)\mathrm{dist}(x, x) is defined as 00.

The managers want to measure the convenience of trade through these dist(x,y)\mathrm{dist}(x, y) values. Listing every value takes too long, so they only want the sum ∑x=12n−1∑y=12n−1dist(x,y)\sum_{x=1}^{2^n-1}\sum_{y=1}^{2^n-1}\mathrm{dist}(x, y). Please help them compute it.

Since the answer may be very large, output it modulo 998244353998244353.

Input

The first line contains two positive integers nn and mm.

The second line contains 2n−22^n-2 positive integers. The ii-th integer aia_i is the length of the first-class road from city i+1i+1 to city ⌊i+12⌋\lfloor\frac{i+1}{2}\rfloor.

Then mm lines follow. Each line contains three positive integers uu, vv, and ww, which describe a second-class road from city uu to city vv with length ww.

Output

Output one line containing an integer, the answer modulo 998244353998244353.

Constraints

For all test data, 2≤n≤182 \leq n \leq 18, 1≤m≤2n1 \leq m \leq 2^n, 1≤u,v≤2n−11 \leq u, v \leq 2^n-1, and 1≤ai,w≤1091 \leq a_i, w \leq 10^9.

Examples1

  1. Example 1

    Input
    2 1
    2 1
    1 2 2
    
    Expected output
    8