ILP representation of the number of maximal 1 sequences in a row
I think this can be done with $9n$ variables, instead of $n^2$.  Define the following integer variables for use in your linear program:


$a_i = 1$ if index $i$ is within an event
$s_i = 1$ if an event starts at index $i$
$e_i = 1$ if an event ends at index $i$
$c_i = $ the number of positions until the end of this event (so that index $i+c_i-1$ is the end of the event containing $i$), if $i$ is in an event, or $0$ if $i$ is not in an event
$d_i = $ is how many positions since the start of the event (so that index $i-d_i+1$ is the start of the event containing $i$), if $i$ is in an event, or $0$ if $i$ is not in an event
$\ell^1_i = $ the length of the event containing $i$, if $i$ is the end of an event, or $0$ if $i$ is not the end of an event
$\ell^2_i = $ the length of the event containing $i$, if $i$ is the start of an event, or $0$ if $i$ is not the start of an event
$o^1_i = $ the amount index $i$ is shifted when copying to the new array, for the first copy of that element
$o^2_i = $ the amount index $i$ is shifted when copying to the new array, for the second copy of that element


These can be enforced with the following equations:


$s_i = a_i \land \neg a_{i-1}$ (see Express boolean logic operations in zero-one integer linear programming (ILP) for how to enforce this)
$e_i = a_i \land \neg a_{i+1}$
$c_i \ge c_{i+1} + 1 - n s_{i-1}$, $c_i \le c_{i+1} + 1$, $c_i \le n a_i$, $c_i \ge e_i$, $c_i \ge 0$
$d_i \ge d_{i-1} + 1 - n e_{i-1}$, $d_i \le d_{i-1} + 1$, $d_i \le n a_i$, $d_i \ge s_i$, $d_i \ge 0$
$\ell^1_i \le n e_i$, $\ell^1_i \ge d_i - n(1-e_i)$, $\ell^1_i \ge 0$
$\ell^2_i \le n s_i$, $\ell^2_i \ge c_i - n (1-s_i)$, $\ell^2_i \ge 0$
$o^1_i = o^1_{i-1} + \ell^1_{i-1}$, $o^1_0 = 0$
$o^2_i = o^2_{i-1} + \ell^2_i$, $o^2_0 = 0$


Then the total number of events is $s_1+\dots+s_n$, and you can model shifting as follows: index $i$ in the original array is shifted to indices $i+o^1_i$ and $i+o^2_i$ in the new array.

Do check my work carefully. There could easily be off-by-one errors or other mistakes in the above.