Letter most:
For each lowercase letter count number of its occurrences in $$$s$$$, maximum of this value for all letters is the answer. All can be done in $$$O(n)$$$.
Array modification:
Assume will be the maximum. it can be proven that all operation should be done in direction of $$$x$$$ ($$$j=i+1$$$ for all operation on its left and $$$j=i-1$$$ for all operations on its right).
Now consider $$$pref_x$$$ is maximum value of $$$a_x$$$ if all operations be done in direction of right for all $$$i=1, 2, ..., x$$$.
And consider $$$suf_x$$$ is maximum value of $$$a_x$$$ if all operations be done in direction of left for all $$$i=x, x+1, ..., n$$$.
It can bee seen that:
$$$pref_x = \frac{perf_{x-1}}{2} + a_x$$$.
$$$suf_x = \frac{suf_{x+1}}{2} + a_x$$$.
And so the answer is $$$max_{i=1}^{n}(pref_i + suf_i - a_i)$$$.
All can be done in $$$O(n)$$$.
Plan for nothing:
Consider an array $$$c_1, c_2, .., c_n$$$, for all intervals like $$$[l, r]$$$ do the following operation:
$$$c_l = c_l + 1$$$.
if $$$r < n$$$, $$$c_{r+1} = c_{r+1} - 1$$$.
Then consider $$$pref_i = c_1 + c_2 + ... c_i$$$. a day is good for date if and only if $$$pref_i = 0$$$.
So the answer will be minimum $$$i$$$ that $$$pref_i = 0$$$ and if it doesn't exist answer is $$$-1$$$.
Lonely M's array:
First reverse $$$a_1, a_2, .., a_n$$$.
Consider two following arrays:
$$$less_i, 1 \leq i \leq 3\times 10^5$$$: maximum length of all subsequence which ends with $$$... \leq i$$$.
$$$greater_i, 1 \leq i \leq 3\times 10^5$$$: maximum length of all subsequence which ends with $$$... \geq i$$$.
initially both are filled with zero.
Start sweep line form $$$1$$$ to $$$n$$$:
for each $$$a_i$$$ maximum length subsequence that ends with $$$... \leq a_i$$$ is $$$max_{j=1}^{a_i}(greater_j) + 1$$$ lets call it $$$X$$$.
for each $$$a_i$$$ maximum length subsequence that ends with $$$... \geq a_i$$$ is $$$max_{j=1}^{a_i}(less_j) + 1$$$ lets call it $$$Y$$$.
after calculating $$$X$$$ and $$$Y$$$, $$$less_{a_i}$$$ should be updated with $$$X$$$ and also greater_{a_i} should be updated with $$$Y$$$. The answer is $$$max_{i=1}^{3 \times 10^5}(less_i)$$$ because the subsequence should finish with $$$\leq$$$.
There are some RMQ(range maximum queries) and some single elements updates that all can be done using segment trees or fenwick trees (because queries are all either a prefix or suffix) in $$$log(3 \times 10^5)$$$.
So all can be done in $$$n \times log(3 \times 10^5)$$$.
Two papers I:
For an edge $$$E$$$, consider number of matchings that includes $$$E$$$. if this number is even $$$E$$$ can be ignored. So the answer is xor of all $$$E$$$'s weight which belongs to odd number of matching.
Consider the tree is rooted from vertex $$$1$$$ and:
$$$dpDown_{v, 0}$$$: parity of number of matchings for subtree of $$$v$$$ which using $$$v$$$ is forbidden for matchings.
$$$dpDown_{v, 1}$$$: parity of number of matchings for subtree of $$$v$$$ which using $$$v$$$ is allowed for matchings.
Both dps can be calculated easily by a dfs from root and updating parent's dps from childs.
For an edge from $$$v$$$ to $$$par_v$$$(parent of $$$v$$$), parity of number of matching which include this edge is:
$$$dpDown_{v, 0} \times \prod_{u\ is\ par_v's\ child\ except\ v} dpDown_{u, 1} \times X$$$, that $$$X$$$ is parity of number of matchings for all vertices else subtree of $$$par_v$$$. $$$X$$$ can be calculated and passed through dfs.
So for all of edges can seen that are they in odd number of edges or even by another dfs and passing and updating $$$X$$$ through dfs arguments.
All can be done in $$$O(n)$$$.