You are given gates arranged in a line. A binary signal passes through the gates from left to right and can be in state or .
Gate has a digit d_i and two rewards w_{i,0} and w_{i,1}. Its effect on the signal depends on d_i \bmod 4:
If d_i \bmod 4 = 0, the state changes from to and from to .
If d_i \bmod 4 = 1, the state does not change.
If d_i \bmod 4 = 2, the state becomes .
If d_i \bmod 4 = 3, the state becomes .
After processing gate , if the resulting state is , you receive reward w_{i,s}.
You need to process operations of two types:
1 i d — set d_i=d.
2 l r — consider only the gates from to . Before gate , the signal is in state .
For this query, you may either leave all gates unchanged or choose one non-empty segment such that
and replace
for every from to .
Find the maximum possible total reward obtained while processing the gates from to .
The replacement d_i \leftarrow 9-d_i is temporary and affects only the current query. It does not change the rewards w_{i,0} and w_{i,1}.
The first line contains two integers and (1 \le n \le 10^5, 1 \le q \le 8 \cdot 10^4).
The next lines each contain three integers d_i, w_{i,0}, and w_{i,1} (0 \le d_i \le 9, -10^9 \le w_{i,0},w_{i,1} \le 10^9).
The next lines describe the operations:
1 i d (1 \le i \le n, 0 \le d \le 9);
2 l r (1 \le l \le r \le n).
For every operation of type , print one integer — the maximum possible total reward.
Example 1
Initially,
For the first query, choose the segment . Then d_4 temporarily changes from to .
The rewards obtained from gates through are
so the total reward is .
Then the update changes d_2 from to .
For the second query, again choose the segment . The obtained rewards are
so the maximum total reward is .
Subtask ( points): n \le 20 and q \le 20.
Subtask ( points): every digit in the initial array and in every update satisfies d \bmod 4 \in \{2,3\}.
Subtask ( points): there are no operations of type .
Subtask ( points): every operation of type has l=1 and r=n.
Subtask ( points): n \le 5000 and q \le 5000.
Subtask ( points): every digit in the initial array and in every update satisfies d \bmod 4 \in \{0,1\}.
Subtask ( points): No additional constraints.