On consecutive sums in permutations
We study the number of values taken by the sums $\sum_{i=u}^{v-1} a_i$, where $a_1,a_2,\dots,a_n$ is a permutation of $1,2,\dots,n$ and $1 \leq u < v \leq n+1$. In particular, we show that for a random choice of a permutation, with high probability there are $(\frac{1+e^{-2}}{4} +o(1)) n^2$ such sums. This answers an old question of Erdős and Harzheim. We also obtain non-trivial bounds on the maximum possible number of distinct sums, ranging over all permutations of $1,2,\dots,n$. We close with some questions concerning the minimal possible number of distinct sums.
\section{Introduction}

 
For a sequence $a = (a_i)_{i=1}^n $ with $a_i \in \mathbb{Z}$, let $S(a)$ denote the set of all distinct sums $\sum_{i=u}^v a_i$ with $1 \leq u \leq v \leq n$. We shall mostly be interested in the size of $S(a)$, where $a_i$ is a permutation of the set $[n] := \{1,2,\dots,n\}$. A trivial upper bound $\abs{S(a)} \leq \binom {n+1}{2}$ follows from counting the number of choices of $u$ and $v$ (or, incidentally, from computing $\max S(a)$). 

The special case when $a_i = i$ for all $i$ was considered by Erd\H{o}s and Harzheim \cite{Erdos-1977-27}. It can be shown that for such $a$ one has $\abs{S(a)} = o(n^2)$. Because of the elementary formula 
$$\sum_{i=u}^v i = \frac{(v-u-1)(v+u)}{2},$$
we have $S(a) \subset [n] \cdot [2n] \subset [2n]\cdot [2n]$, where we use the notation $A \cdot B = \{ab \ : \ a \in A, b \in B\}$. Hence, obtaining good bounds on $\abs{S(a)}$ is essentially equivalent to obtaining good bounds on $\abs{[n]\cdot[n]}$. The latter question, known as the \emph{multiplication table problem}, has been extensively studied. 

The first proof that $\abs{[n] \cdot [n] } = o(n^2)$ is due to Erd\H{o}s \cite{Erdos-1955}, with further improvements  by the same author \cite{Erdos-1960}. The exact asymptotics were only recently obtained by Ford \cite{Ford-2008}, who shows that:
\begin{equation}
\abs{ [n] \cdot [n] } = \Theta\bra{ n^2 (\log n)^{-c} (\log \log n)^{-3/2}},
\end{equation}
	 where $c=1-\frac{1+\log \log 2}{\log 2}$.

This special case lead Erd\H{o}s to pose the following question \cite{Erdos-1977-27}:
\begin{question}\label{question:Erdos-Harheim}
	Is it true that for any $\varepsilon$ there exists $n_0$ such that for any $n \geq n_0$ and for any permutation $a_1,\dots,a_n$ of $[n]$ we have $\abs{S(a)} \leq \varepsilon n$?
\end{question}

The purpose of this note is to show that the answer to this question is an emphatic \emph{``no''}. Without further ado, we give the simplest example we are aware of where the conjecture fails.

\begin{proposition}\label{I:prop:cexple-basic}
	For any $n$ one can find a permutation $a$ of $[n]$ such that $\abs{S(a)} \geq \frac{1}{4}n^2. $
\end{proposition}
\begin{proof}
	Let $a$ be the permutation $1,n,2,n-1,3,n-2,\dots$, so that for each odd $i$ one has $a_i + a_{i+1} = n+1$. 
	
	Let $S_1 \subset S(a)$ be the set of the sums $s = \sum_{i=u}^v a_i$ with $u \equiv v \pmod{2}$.	If $v = u+2l$ then $s = (n+1)l + k$, where $k = a_v$ if $u,v$ are odd and $k = a_u$ otherwise. If $s$ has another representation $s = \sum_{i=u'}^{v'} a_i = (n+1)l' + k'$ like before, then it follows that $l'=l,\ k'=k$, hence $u,v \equiv u',v' \pmod{2}$ and finally $u'=u,\ v'=v$. Thus, all $ \ceil{ \frac{n+1}{2} }\cdot \floor{ \frac{n+1}{2} } \geq \frac{n^2}{2}$ sums in $S_1$ are distinct.
\end{proof}


The constant $\frac{1}{4}$ in the above Proposition \ref{I:prop:cexple-basic} can be improved slightly, using a randomised variant of the construction above.

\begin{proposition}\label{I:prop:cexple-improved}
	For any $n$ there exists a permutation $a$ of $[n]$ such that $\abs{S(a)} \geq (c_1+o(1)) n^2$, where $c_1 = \frac{3}{2}-\frac{2}{\sqrt{e}} = 0.286\dots$. 
\end{proposition}

In the other direction, we have the following slight improvement over the trivial bound $S(a) \leq (\frac{1}{2}+o(1))n^2$. 
\begin{proposition}\label{I:prop:upper-bound}
	For any permutation $a$ of $[n]$, we have $\abs{S(a)} \leq  (c_2+o(1)) n^2$ where $c_2 = \frac{1}{4} + \frac{\pi}{16} = 0.446\dots$.
\end{proposition}

These bounds are proven in Sections \ref{section:EXT-low} and \ref{section:EXT-up} respectively. It would be very surprising if either of these results were optimal. We expect that $\max_{a} S(a) = (c+o(1)) n^2$ for some constant $c$ with $c_1 < c < c_2$. It may be interesting to find the exact value of $c$.

While the above examples resolve the original question of Erd\H{o}s, they do not say what happens for a ``typical'' permutation. Our main result shows that the the answer to the Question \ref{question:Erdos-Harheim} is still negative ``on average'' in a rather strong sense.

\begin{proposition}\label{I:prop:exact}
	Let $a$ be a permutation of $[n]$ chosen uniformly at random.
	Then $\EE(\abs{S(a)}) = (c + o(1)) n^2$ where $c= \frac{1+e^{-2}}{4} = 0.283\dots$ as $n \to \infty$.
	Moreover,
	 for any $\delta >0$ we have $\mathbb{P}\bra{ \abs{ \frac{\abs{S(a)}}{n^2} - c } > \delta} \to 0$ as $n \to \infty$.
\end{proposition}

The proof of this proposition is carried out in Section \ref{section:EXC}, dealing with the expected value of $\abs{S(a)}$, and  Section \ref{section:HM}, dealing with the second moment.

To close this section, we remark that a somewhat similar problem was considered by Hegyv{\'a}ri in \cite{Hegyvari}. Instead of a permutation of $[n]$, \cite{Hegyvari} deals with a sequence $(a_i)_{i = 1}^k$ where $k \leq n$ and $a_i \in [n]$, and asks for which $k$ it is possible that \emph{all} sums $\sum_{i=u}^v a_i$ are distinct. This turns out to be possible for $k \geq (\frac{1}{3}-o(1)) n$, which gives an alternative proof of Proposition \ref{I:prop:cexple-basic} with a slightly worse constant $\frac{1}{18}$ in place of $\frac{1}{4}$. Conversely, our Proposition \ref{I:prop:exact} implies a non-trivial bound $k \leq \bra{\sqrt{\frac{\pi}{8} + \frac{1}{2}} + o(1)}n$.

\subsection*{Notation} 

We use a variety of asymptotic notation. We write $X = O(Y)$, or $X \ll Y$ if there exists a constant $C > 0$ such that $\abs{X} \leq C Y$. If the constant $C$ is allowed to depend on a parameter $M$, we occasionally write $X = O_M(Y)$. Likewise, we write $X = \Omega(Y)$ if there exists a constant $c > 0$ such that $X > c Y$. Throughout the paper, we work in the regime $n \to \infty$. We write $X = o(Y)$ if $Y > 0$ for $n$ large enough an $\frac XY \to 0$ as $n \to \infty$, and similarly $X = \omega(Y)$ if instead $\frac XY \to \infty$. Finally, if $X = O(Y)$ and $X = \Omega(Y)$ we write $X \sim Y$ or $X = \Theta(Y)$. Occasionally, we this notation with a different limit in mind, with the obvious modifications.

In particular, we freely use expressions such as $O(Y)$, $\Omega(Y)$, $o(Y)$, $\omega(Y)$, $\Theta(Y)$ to denote unspecified functions with the asymptotic behaviour as just described.



\subsection*{Acknowledgements} The author wishes to thank Ben Green to pointing out this problem, and for much advice during the work on it. The author is also grateful to Sean Eberhard, Freddie Manners,  Przemek Mazur, Rudi Mrazovi\'{c} and Aled Walker for many fruitful discussions. Finally, the author thanks Jozsef Solymosi and Norbert Hegyv\'{a}ri for helpful comments.

 








 \section{Expected value of $\abs{S(a)}$}\label{section:EXC}

\newcommand{{\mathrm{uni}}}{{\mathrm{uni}}}

In this section we study the asymptotic behaviour of $\EE\abs{S(a)}$. Our main goal is to prove the first part of Proposition \ref{I:prop:exact}, namely the asymptotic formula for $\EE\abs{S(a)}$. We will reuse much of our work here in the subsequent section to compute the second moment $\EE\abs{S(a)}^2$.

Throughout the argument, $n$ is a large integer, and $a$ is a permutation selected uniformly at random from the set of the permutations of $[n]$. 



One of our main tools is an inequality due to Hoeffding. We will mostly use the slightly less well-known variant of it, pertaining to random variables chosen from a finite set without replacement, such as the $a_i$.
 
\begin{theorem}[Hoeffding \cite{Hoeffding-1963}]
	Let $X_i$ ($i=1,\dots,m)$ be independent random variables with $\a \leq X_i \leq \b$ for some constants $\a,\b$ and $\mu =  \sum_{i=1}^k \EE X_i$. We then have for any $t > 0$
	\begin{equation}\label{EXP:eq:01}
	\mathbb{P}\bra{ \abs{{\sum_{i=1}^k} X_i - \mu } \geq t } \leq 2\exp\bra{- \frac{2 t^2}{k(\b-\a)^2}}.
	\end{equation}
	Moreover, the same inequality \eqref{EXP:eq:01} is satisfied if instead of independence we assume that $X_i$ are drawn without replacement from a finite (multi-)set. 
\end{theorem}

For any $\varepsilon > 0$, let $S_\varepsilon(a)$ denote the set of all the sums $s$ of the form $\sum_{i=u}^v a_i$ with $\varepsilon n \leq u \leq n - \frac{2s}{n} - \varepsilon n$. It would be sufficient to work with a concrete choice such as $\varepsilon = \frac{1}{\log n}$, but many other choices are equally valid.

We first reduce the problem of determining $\EE\abs{S(a)}$ to the dealing with a single (putative) sum in $S_\varepsilon(a)$

\begin{proposition}\label{EXC:prop:P-s-in-S}
	Fix a choice of $\varepsilon = \varepsilon(n)$ with $\varepsilon = o(1)$ and $\varepsilon = n^{-o(1)}$ as $n \to 0$. Let $s = \sigma \frac{n^2}{2}$ with $\varepsilon < \sigma < 1-\varepsilon$. Then 
	\begin{equation}\label{EXC:eq:P-s-in-S}
	\mathbb{P}(s \not\in S_{\varepsilon}(a)) = e^{-2+2\sigma} + o(1).
	\end{equation}
	Here, the error term is uniform with respect to $s$, but may depend on the implicit rates of convergence in the remaining usages of $o(1)$ notation.
\end{proposition}

\begin{proof}[Proof of Proposition \ref{I:prop:exact}, assuming \ref{EXC:prop:P-s-in-S}]
	Take, for instance, $\varepsilon(n) := \frac{1}{\log n}$. If the bound in equation \eqref{EXC:eq:P-s-in-S} holds for each $s$, then we have:
	\begin{align*}
		\EE\abs{S_{\varepsilon}(a)} &= \sum_{\varepsilon \frac{n^2}{2} < s < (1 - \varepsilon) \frac{n^2}{2} } \mathbb{P}(s \in S_\varepsilon(a)) + O(\varepsilon n^2) \\
		&= \frac{n^2}{2} \int_{\varepsilon}^{1-\varepsilon} (1-e^{-2+2\sigma}) d \sigma + o( n^2) 
		\\ &= n^2 \bra{ \frac{1+e^{-2}}{4} + o(1) }.
	\end{align*}
	Hoeffding's inequality implies that $\abs{S(a) \setminus S_{\varepsilon}(a) } = o(n^2)$ with probability $1-o(1)$. Indeed, if $s = \sum_{i=u}^v a_i \in S(a) \setminus S_\varepsilon(a)$ then one of the three possibilities holds. Either $u < \varepsilon n$ or $v > n-2\varepsilon n$ or $v-u \leq \frac{2s}{n}-\varepsilon n$. The first two cases account for $O(\varepsilon n^2)$ elements of $S(a) \setminus S_\varepsilon(a)$. For the third case, note that by Hoeffding's inequality and the union bound, we have:
$$	
	\mathbb{P}\bra{(\exists u,v) \ : \ \sum_{i=u}^v a_i > \frac{n}{2}(v-u) + \varepsilon n^2 } \ll
	{n^2 \exp\bra{-2\varepsilon^2 n}} = o(n^2).
$$
Of course, both sets $S(a), S_\varepsilon(a)$ have size $O(n^2)$. Hence,
	\begin{equation}
		{\EE\abs{S(a)}} = (1+o(1)){\EE\abs{S_\varepsilon(a)}} = (1+o(1)) \frac{1+e^{-2}}{4} n^2. 
		\qedhere
	\end{equation}
\end{proof}

We devote most of the remainder of this section to proving Proposition \ref{EXC:prop:P-s-in-S}. 

Given an index $u$, we define the set 
$$S_u(a) := \left\{ \sum_{i=u}^v a_i \ : \ u \leq v \leq n\right\}.$$ 
Clearly, $s \in S_\varepsilon(a)$ precisely when $s \in S_{u}(a)$ for some $\varepsilon n \leq u \leq (1 - \sigma - \varepsilon)n$ (where $\sigma = \frac{2s}{n}$).

Let $N$ be a large even integer. By the inclusion/exclusion formula, we have:
\begin{equation}\label{EXC:eq:39}
	\mathbb{P}( s \not \in S_\varepsilon(a)) \leq \sum_{\abs{U} \leq N} (-1)^{\abs{U}} \mathbb{P}\bra{ \bigwedge_{u \in U} s \in S_u(a)},
\end{equation}
where the sum is taken over all sets $U \subset [n]$ with $\min U \geq \varepsilon n$ and $\max U \leq (1 - \sigma - \varepsilon)n$. An analogous formula holds for odd $N$, except that the inequality sign is reversed. Hence, Proposition \ref{EXC:prop:P-s-in-S} will follow easily once a good estimate is found for each of the sums $\sum_{\abs{U} = M}\mathbb{P}\bra{ \bigwedge_{u \in U} s \in S_u(a)}$. 

We next prove a lemma which will allow us to eliminate a proportion of terms in such sums. The statement is slightly more general to accommodate latter applications to the second moment. We will only need it in the special case when $s_k$ take at most two distinct values, but this additional assumption does not simplify the argument.

\newcommand{\mathcal{S}}{\mathcal{S}}

\begin{lemma}\label{EXC:lem:kill-bad-U}
	Fix a choice of $\varepsilon = \varepsilon(n)$ with $\varepsilon = o(1)$ and $\varepsilon = n^{-o(1)}$ as $n \to 0$. Let $M$ be an integer, for $1 \leq k \leq M$ let $s_k = \sigma_k \frac{n^2}{2}$ with $\varepsilon < \sigma_k < 1-\varepsilon$ and let $u_k \in [n]$ be distinct. Then
	\begin{equation}\label{EXC:eq:40a}
		\mathbb{P}\bra{ \bigwedge_{k=1}^M s_k \in S_{u_k}(a)} = O \bra{ \frac{ {\frac{1}{\varepsilon}\log n} }{n}}^M ,
	\end{equation}
	where the implicit constant depends only on $M$.
\end{lemma}
\begin{proof}


	By Hoeffding's inequality, there is a constant $C_M$ such that with probability $1-O\bra{\frac{1}{n^M}}$ any interval $[u,v]$ of length $C_M \log n$ has $\sum_{i=u}^v a_i \geq n$. 
	
	Let us now select $a$ by selecting $a_i$ in the order of decreasing $i$. For each $k$, the event $s_k \in S_{u_k}(a)$ becomes determined at the time when $a_{u_k}$ is chosen. Either there are at most $C_M \log n$ choices of $a_{u_k}$ leading $s_k \in S_{u_k}(a)$, or there is an interval of length $C_M \log n$ and sum less than $ n$. Since the number of choices of $a_{u_k}$ is at least $\varepsilon n$ in each step, we obtain the sough bound by a standard inductive argument.
\end{proof}

	Our next goal is to obtain bounds on the probabilities in \eqref{EXC:eq:39} for ``generic'' $U$. The general strategy at this point is to select $a_i$ in several ``stages''. For each $u \in U$, we shall select $a_i$ with $u \leq i < u+m$ from a suitably constructed set $A_u$ of size $\abs{A_u} \sim \frac{1}{m} n$, where $m$ is an integer to be specified later. The rationale is that (assuming some genericity conditions on $A_u$) it should be relatively easy to understand the distribution of the sum $\sum_{i=u}^{u+m-1} a_i$, and conditioning on the choice of $A_u$, the sums $\sum_{i=u}^{u+m-1} a_i$ are independent. The main reason why this approach succeeds is contained in the following innocuous lemma.

Recall that for two functions $f,g \colon \mathbb{Z} \to \mathbb{R}$ with finite support, we define their convolution $f \ast g$ by $f \ast g (x) = \sum_{y \in \mathbb{Z}} f(x-y) g(y)$. We shall denote $\norm{f}_{\infty} := \max_{x \in \mathbb{Z}} \abs{f(x)}$. Also recall that we use $\omega(1)$ do denote an arbitrary function tending to $\infty$ as $n \to \infty$.

\begin{lemma}\label{EXC:lem:f-A,2=uni}
	Fix a choice of integer $m = m(n)$ with $m = n^{o(1)}$ and $m = \omega(\log n)$ as $n \to \infty$.

	Let $A \subset [n]$ be a randomly chosen set with $\abs{A} = \floor{n/m^2}$. Then the bound
	\begin{equation}
		\norm{\frac{1_{A}}{\abs{A}} \ast \frac{1_{A}}{\abs{A}} - \frac{1_{[n]}}{n} \ast \frac{1_{[n]}}{n} }_{\infty} \leq \frac{1}{n}\cdot \frac{m^5}{n^{1/2}}
	\label{EXC:eq:41}
	\end{equation}
	holds with probability $1-n^{-\omega(1)}$.
\end{lemma}

Again, we could work with a specific choice of $m$, such as $m \sim n^{\frac{1}{\log \log n}}$ or (with minor modifications) $m \sim n^{\frac{1}{100}}$. The slightly unnatural looking condition $\abs{A} = \floor{n/m^2}$ will simplify notation later on. 

\begin{proof}
	Take arbitrary $x \in [n]$. It will suffice to show that the inequality
	$$
		\abs{ 1_{A} * 1_{A}(x) - \frac{1}{m^4} 1_{[n]} * 1_{[n]}(x) } \leq \sqrt{n} m
	$$
	holds with probability $1-n^{-\omega(1)}$, and apply the union bound. We may assume without loss of generality that $x \leq n/2$. For ease of notation, we additionally assume that $x$ is odd. In this case, $1_{[n]} * 1_{[n]}(x) = x-1$.
	
	Define $A_1 = A\cap [1,x/2)$ and $A_2 = (x/2,x]$ so that we have $1_A * 1_A(x) = 2\abs{A_1 \cap (x-A_2)}$. An application of Hoeffding's inequality shows that the bounds:
	$$
		\abs{ \abs{A_1} - \frac{x-1}{2m} } \leq \sqrt{x m}, \qquad
		\abs{ \abs{A_2} - \frac{x-1}{2m} } \leq \sqrt{x m} 		
	$$
	hold with probability $\geq 1 - 2 \exp(-2m) = 1-n^{-\omega(1)}$. Similarly, the bound
	$$
		\abs{
			\abs{ A_1 \cap (x-A_2)} - \frac{\abs{A_1}\abs{A_2}}{x/2}
		} \leq \sqrt{ x m }
	$$
	holds with probability  $\geq 1 - 2 \exp(-2m) = 1-n^{-\omega(1)}$. Hence, by the union bound, we have with probability $1-n^{-\omega(1)}$ that
	\begin{align*}
		\abs{ 1_{A} * 1_{A}(x) - \frac{1}{m^4} 1_{[n]} * 1_{[n]}(x) } 
		 &= \abs{2 \abs{A_1 \cap (x-A_2)} - \frac{x-1}{m^4} } 
		\\& \leq  \abs{ \frac{4 \abs{A_1} \abs{A_2}}{x} - \frac{x-1}{m^4} } + \sqrt{n m} 
		\\& \leq 2 \abs{ \abs{A_1} - \frac{x}{2m} } + 2\abs{ \abs{A_1} - \frac{x}{2m} } + \sqrt{nm}
		\\& \leq 5 \sqrt{nm} < m \sqrt{n},		  
	\end{align*}
	as required.
\end{proof}

As the reader will have noticed, we make no serious attempt to optimize the dependence on $m$. The exponent $5$ does not play a role; we merely need it to be a constant

\newcommand{{r}}{{r}}
For a set $A \subset [n]$ and integer $k$, let us agree to denote by ${r}_{A,k}$ the distribution of $Y = X_1 + X_2 + \dots
X_k$, where $X_i$ are chosen uniformly without replacement, that is 
$${r}_{A,k}(x) = \mathbb{P}(Y = x) = \mathbb{P}\bra{\sum_{i=1}^k X_i = x}.$$ Also, let ${r}_{{\mathrm{uni}},k}$ denote the distribution of $V = U_1 + U_2 + \dots + U_k$ where $U_i \in [n]$ are chosen uniformly and independently, hence in particular ${r}_{{\mathrm{uni}},k} = {r}_{{\mathrm{uni}},1} * \cdots * {r}_{{\mathrm{uni}},1}$.

For instance, if $\abs{A} = \floor{n/m^2}$ then ${r}_{A,1} = \frac{1_A}{\abs{A} }$, and since we have the bound $\norm{ {r}_{A,1} \ast {r}_{A,1} - {r}_{A,2}}_\infty = O\bra{\frac{m^4}{n^2}}$, the above lemma says that with overwhelming probability $\norm{ {r}_{A,2} - {r}_{{\mathrm{uni}},2} }_{\infty} \ll \frac{1}{n} \frac{m^5}{n^{1/2}}$. More generally, we have the following.

\begin{corollary}\label{EXC:lem:f-A,m=uni}
	Fix $m$ with $m = n^{o(1)}$ and $m = \omega(\log n)$, even. Let $A \subset [n]$ be a randomly chosen set with $\abs{A} = m\floor{n/m^2}$. Then the bound
	\begin{equation}
		\norm{ {r}_{A,m} - {r}_{{\mathrm{uni}},m} }_{\infty} \leq \frac{1}{n} \cdot \frac{m^6}{n^{1/2}}
		\label{EXC:eq:42}
	\end{equation}
	holds with probability $1-n^{-\omega(1)}$.
\end{corollary}
\begin{proof}
	
	We consider a two-stage random process. First, we select disjoint sets $A_1,\dots,A_m \subset A$ with $\abs{A_i} = \floor{n/m^2}$ uniformly at random. Second, we select $b_{2j-1},b_{2j} \in A_j$ uniformly at random without replacement. It follows that
	\begin{equation}
	{r}_{A,m} = \EEbig_{A_1,\dots,A_{m/2}} {r}_{A_1,2} \ast {r}_{A_2,2} \ast \dots {r}_{A_{m/2},2}.
	\end{equation}
	where the expectation is taken over all partitions of $A$.
		
	It is a standard fact that if $f$ is a probability distribution then for any bounded $g$ one has $\norm{ f \ast g}_{\infty} \leq \norm{g}_\infty$. Hence, we obtain by a simple inductive argument
	\begin{equation}
		\norm{ {r}_{A_1,2} \ast {r}_{A_2,2} \ast \dots \ast {r}_{A_{m/2},2} - {r}_{{\mathrm{uni}},m} }_\infty \leq \sum_{j=1}^{m/2} \norm{{r}_{A_j,2} - {r}_{{\mathrm{uni}},2}}_\infty.
	\end{equation}
		
	Note that if $A$ is selected uniformly at random (subject to cardinality), then so is each of the sets $A_j$.
Using Lemma \ref{EXC:lem:f-A,2=uni} and the union bound, with probability $1
	-n^{-\omega(1)}$, the bound \eqref{EXC:eq:41} holds for each $A_j$. Hence, with probability $1-n^{-\omega(1)}$, also the bound \eqref{EXC:eq:42} holds.

\end{proof}


	We shall exploit the fact that the sums $\sum_{i=u}^v a_i$ tend to have roughly the correct magnitude if $v-u$ is larger than a power of $\log n$. To make this idea precise, we introduce the following piece of notation. Let $I \subset [n]$ be a (connected) interval, and let $b = (b_i)_{i \in I}$ be a $[n]$-valued sequence indexed by $I$. Then $\mathscr{R}(b)$ is the event that for any non-empty interval $J \subset I$ one has 
	\begin{equation} 
		\abs{ \sum_{j \in J}b_i - \abs{J} \frac{n}{2} } \leq \sqrt{\abs{J}} n \log n.
		\label{EXC:eq:R} 
	\end{equation}
It is an easy consequence of the Hoeffding inequality that for any $I$ we have
$$\mathbb{P}\brabig{\mathscr{R}(a|_{I})} = 1 - n^{-\omega(1)},$$ where we use the notation $a|_I$ to denote the restriction of $a$ to $I$. (In fact, we could replace $\log n$ in \eqref{EXC:eq:R} above with any function $= \omega(\sqrt{\log n})$). Slightly more generally, we have the following result.

\begin{lemma}\label{EXC:lem:P-R-uniform} Fix a choice of even integer $m$ with $m = n^{o(1)}$ and $m = \omega(\log n)$. 
	Let $A \subset [n]$ be a randomly chosen set with $\abs{A} = m \floor{n/m^2}$. Let $b = (b_1,\dots,b_m)$ be chosen uniformly at random without replacement from $A$. Then there is a function $h$ with $h(n) \to \infty$ as $n \to \infty$ such that
\begin{equation}\label{EXC:cond:R1}
		\mathbb{P}_{A}\bra{ \mathbb{P}_{b_i \in A}( \neg \mathscr{R}(b)) \geq  n^{-h(n)} } \leq n^{-h(n)}.
\end{equation}
\end{lemma}
\begin{proof}
	By Hoeffding's inequality, for each interval $J$ with $\abs{J} = l$ one has:
	$$
	\mathbb{P}_{b_i \in [n] }
	\bra{ \abs{ \sum_{j \in J} b_j - l \frac{n}{2} } \geq \sqrt{l} n \log n}
	\leq 2\exp\bra{ - 2 \log^2 n} 
	= n^{-\omega(1)},
	$$
	where $b_i$ are chosen from $[n]$ without replacement, uniformly at random. Hence, after an application of the union bound over $O(n^2)$ choices of $J$, we also know that $$\EEbig_{A}\brabig{ \mathbb{P}_{b_i \in A}( \neg \mathscr{R}(b)) } = \mathbb{P}_{b_i \in [n]} \bra{ \neg \mathscr{R}(b) } = n^{-\omega(1)}.$$ The claim now follows from the Chebyshev bound.
\end{proof}

The above lemma can be restated by saying that for a randomly selected $A$, the bound
\begin{equation}\label{EXC:cond:R2}
	\mathbb{P}_{b_i \in A}( \mathscr{R}(b)) \geq 1 - n^{-\omega(1)}
\end{equation}
holds with probability $1 - n^{-\omega(1)}$.

We are now ready to estimate the probabilities in \eqref{EXC:eq:39}. The only caveat is that we shall need to assume a certain genericity condition on $U$. Namely, we shall require that the set $U$ be well-separated:
\begin{equation}\label{EXC:cond:U-reg}
	(\forall u, v \in U) \ u = v \vee \abs{u-v} > m, 
\end{equation}
where $m$ is a parameter yet to be specified. Under this condition, we can now prove the needed bound. Again, we prove slightly more then necessary at the moment, since in this section we will only apply the following proposition with a constant sequence $s_k = s$. 

\begin{proposition}\label{EXC:prop:P-wedge-s-in-S}
	Fix a choice of $\varepsilon = \varepsilon(n)$ and even $m = m(n)$ such that $\varepsilon = o(1)$, $m = n^{o(1)}$ and $m = \bra{ \frac{1}{\varepsilon} \log n}^{\omega(1)}$ as $n \to 0$. 	Let $M$ be an integer. For $1 \leq k \leq M$ let $s_k = \sigma_k \frac{n^2}{2}$ with $\varepsilon < \sigma_k < 1-\varepsilon$ and let $u_k \in [n]$ be distinct, and such that $U := \{u_k\}_{k=1}^M$ satisfies the well-separatedness condition \eqref{EXC:cond:U-reg}. Then 
\begin{equation}
	\mathbb{P}\bra{ \bigwedge_{u \in U}^M \bra{ s_k \in S_{u_k}(a) } } = \bra{\frac{2}{n}}^M (1+ o(1)),
\end{equation}
where the implicit error term depends only on $M$.
\end{proposition}

\begin{proof}
Define intervals $I_k = [u_k,u_k+ m)$ for $k \in [M]$, and $I_{0} = [1, M m\floor{n/m^2} ]$, and finally $I_{\infty} = [n] \setminus \bigcup_{k=0}^M I_k$. Because of the well-separetedness \eqref{EXC:cond:U-reg}, these are disjoint.	

We can think of $a$ as being selected in two stages. Firstly, for each $1 \leq k \leq M$ we select a set $A_k$ of size $m\floor{n/m^2}$ uniformly at random, and put $A_{\infty} = [n] \setminus \bigcup A_k$. Next, for each $k \in [M] \cup \{\infty\}$ for $i \in I_{k}$, we select $a_i$ uniformly at random from $A_{k}$ without replacement. Finally, for $i \in I_0$, we select $a_i$ from $\bigcup_{k \in [M]} A_k$ (except for values which have already been used) uniformly at random. It is not hard to see that this procedure produces the uniform distribution of $a$.

By Lemmas \ref{EXC:lem:f-A,m=uni} and \ref{EXC:lem:P-R-uniform}, for each $k \in [M]$ the regularity
conditions \eqref{EXC:eq:42} and \eqref{EXC:cond:R2} hold for $A_k$ with probability $1-n^{-\omega(1)}$.  Hence, it will suffice to prove the bound 
\begin{equation}\label{EXC:eq:49}
	\mathbb{P}\bra{ \bigwedge_{k=1}^M (s_k \in S_{u_k}(a)) \middle|  a_{i} \in A_k  \text{ for all } k,\ i \in I_k } = \bra{\frac{2}{n}}^M \bra{1+ o(1)}
\end{equation}
where each of the sets $A_k$ satisfies \eqref{EXC:eq:42} and \eqref{EXC:cond:R2} (here, the error term does not depend on $s_k$).

Because for each fixed $k$ we have $\mathbb{P}(\neg \mathscr{R}( a|_{I_k} ) | \ a_{i} \in A_k \text{ for } i \in I_k) = n^{-\omega(1)}$ by \eqref{EXC:cond:R2}, we may replace each event $s_k \in S_{u_k}(a)$ in \eqref{EXC:eq:49} with the event $s_k \in S_{u_k}(a) \wedge \mathscr{R}(a|_{I_k})$ at the cost of introducing a negligible error term of the order $O(n^{-\omega(1)})$. 

The claim now follows by a standard inductive argument. It suffices to prove the following.

\begin{lemma*}
	Let $k \in [M]$. For $k < l \leq M$ and $l = \infty$, let $a^*_{I_l} = (a^*_j)_{j \in I_l}$ be $[n]$-valued sequences such that the well-distribution condition $\mathscr{R}(a^*_{I_l})$ defined in \eqref{EXC:eq:R} holds. Let $A \subset [n]$ be a set with $\abs{A} = m \floor{n/m^2}$ satisfying the well-separatedness condition \eqref{EXC:eq:42} and the well-distribution \eqref{EXC:cond:R2}. Then
	\begin{equation}\label{EXC:eq:50}
		\mathbb{P} \left( s_k \in S_{u_k}(a) \wedge \mathscr{R}(a_{I_k}) 
		\middle|
		 \begin{matrix}
		a_{i} \in A \text{ for } i \in I_k \text{ and } \\
		 a_{I_{l}} = a_{I_l}^* \text{ for } l = k+1,\dots,M, \infty
		 \end{matrix} 
		 \right)   = \frac{2+o(1)}{n},
	\end{equation}
	\end{lemma*}
where the error term does not depend on $s_k$. 
\begin{proof}
	Let $b_1,\dots,b_m$ be chosen uniformly at random without replacement from $A$. Then the probability in \eqref{EXC:eq:50} can be rewritten as
	\begin{equation}\label{EXC:eq:51}
		\mathbb{P}_{b_i \in A} \bra{ s_k - \sum_{i=1}^m b_i \in S_{u_k+m}(a^*) \wedge \mathscr{R}(b)}.
	\end{equation}

	Because of \eqref{EXC:cond:R2}, we have $\mathbb{P}_b(\mathscr{R}(b)) = 1 - n^{-\omega(1)}$. 	
	Putting $$R := s_k-S_{u_k+m}(a^*),$$ it will hence suffice to estimate $\mathbb{P}_{b} \bra{ \sum_{i=1}^m b_i \in R}$.
	
	The assumption \eqref{EXC:cond:R2} for $A_{k+1},A_{k+2},\dots,A_M$ implies that for interval any $J \subset \bigcup_{l =k+1}^M I_l \cup I_\infty$ with $\abs{J} \gg \frac{\log^2n}{\varepsilon^4}$ one has:
	\begin{equation}
		\sum_{i \in J} a^*_j = \frac{n}{2} \abs{J}(1+O(\varepsilon^2)).
	\end{equation}
	Note in particular that 
	$$\max S_{u_k+m}(a^*) = \frac{n}{2}(n-u_k-m)(1+O(\varepsilon^2)) \geq \frac{1}{2}n^2(\sigma_k+\varepsilon - O(\varepsilon^2)).$$ Thus, we have somewhat crude bounds $\min R < 0$ and $ \max R > \frac{1}{2} \varepsilon n^2 > mn$. (Recall that $\varepsilon > \frac{1}{\sqrt{n}} > \frac{m}{n}$.)
	
	If $K \subset [\min R, \max R]$ is an arbitrary interval of length at least $n \frac{\log^2n}{\varepsilon^4}$ then 
	\begin{equation}
	\abs{K \cap R} \geq \frac{n}{2} \abs{K} (1+ O(\varepsilon^2)).
	\label{EXC:eq:45}	
	\end{equation}
	Indeed, if $J$ denotes the set of $v$ such that $\sum_{i=u_k+m}^v a_i^* \in K$ then
	$$ \abs{K} + O(n) = \sum_{i \in J} a_{i}^* = \frac{n}{2} \abs{K\cap R}(1+O(\varepsilon^2)),$$
	which easily implies the claim.


Returning to the probability we wish to estimate, we clearly have 
\begin{equation}\label{EXC:eq:53}
\mathbb{P}_{b}\bra{ \sum_{i=1}^m b_i \in R} = \sum_{x } 1_R(x) {r}_{A,m}(x),
\end{equation}
where ${r}_{A,m}(x)$ is the distribution of $\sum_{i \in I_k} b_i$. The sum is formally taken over $\mathbb{Z}$ but ${r}_{A,m}$ is identically $0$ outside the interval $[m,mn]$.

It follows from Corollary \ref{EXC:lem:f-A,m=uni} that
\begin{align}\label{EXC:eq:55}
	\abs{
	\sum_{x } 1_R(x) \bra{ {r}_{A,m}(x) - {r}_{{\mathrm{uni}},m}(x) }
	} \leq mn \norm{{r}_{A,m} - {r}_{{\mathrm{uni}},m}}_\infty 
	= O\bra{  \frac{m^6}{n^{1/2}} } .
\end{align}

We note some basic properties of ${r}_{{\mathrm{uni}},m}$. Firstly, ${r}_{{\mathrm{uni}},m}$ takes its maximal value at a precisely one point, with respect to which it is symmetric. Indeed, this property holds for ${r}_{{\mathrm{uni}},2}$ and is preserved under convolution with ${r}_{{\mathrm{uni}},2}$.

Secondly, for any integer $x$ we claim that ${r}_{{\mathrm{uni}},m}(x) \ll \frac{1}{m^{1/2}n}$. For this purpose we introduce the exponential sum $\phi(t) := \frac{1}{n} \sum_{k=1}^n e( k t) = \frac{e(t)}{n} \frac{e(tn)-1}{e(t)-1}$ where $e(t) := e^{2 \pi i t}$, so that for each $x$ we have $${r}_{{\mathrm{uni}},m}(x) = \int_{0}^1 e(-xt) \phi(t)^m dt \leq \int_0^1 \abs{\phi(t)}^m dt.$$

We have the trivial bound $\abs{\phi(t)} \leq 1$ for each $t$. Slightly less trivially, $\abs{\phi(t)} = \abs{ \frac{\sin n t\pi}{n \sin t \pi}}$. Hence, for $\frac{1}{2n} \leq t \leq 1 - \frac{1}{2n}$ we find $\abs{\phi(t)} \leq \frac{1}{\pi/2 - o(1)} < \frac{2}{3}$ if $n$ is large enough, and hence 
$$\int_{1/2n}^{1-1/2n} \abs{\phi(t)}^m dt < \bra{\frac{2}{3}}^m \ll \frac{1}{m^{1/2}n}.$$ 
For $1 < t < \frac{1}{2n}$ we have $\abs{\phi(t)} = \abs{ \frac{\sin \pi n t}{ n\pi t(1 + O(1/n^2))}}$ and hence $\abs{\phi(t)}^m = \abs{ \frac{\sin \pi n t}{n \pi t}}^me^{O(m/n^2)}$. One can find a universal constant $c$ such that $\abs{ \frac{\sin u}{u}} \leq e^{-c u^2}$ for $0 < u < \pi/2$, and thus $\abs{ \phi(t) }^m \leq e^{-c t^2 n^2 m}$ (possibly with a different constant). Consequently, 
$$\int_{0}^{1/2n} \abs{ \phi(t) }^m dt < \int_{0}^\infty e^{-c t^2 n^2 m} dt < \frac{C}{m^{1/2}n}$$ 
for an absolute constant $C>0$. Applying the same argument to $1-\frac{1}{2n} < t < 1$, we conclude that ${r}_{{\mathrm{uni}},m}(x) \leq \frac{C}{m^{1/2}n}$, where $C$ is absolute.



We may now estimate  $\sum_{x } 1_R(x) {r}_{{\mathrm{uni}},m}(x)$. Let us separate the interval $[0, m n]$ into pieces $\dots,K_{-2},K_{-1},K_0,K_{1},K_{2},\dots$, arranged in this order, disjoint, each of length $(1+o(1)) n \frac{\log^2n}{\varepsilon^4}$, except for $K_0 := \{\frac{m(n+1)}{2}\}$ of length $1$. Consider the function $g_{-}$ defined by $g_{-}(x) = \frac{2}{n}(1-C \varepsilon^2)$ for $x \in {K_i}$ with $\abs{i} > 1$ and $g_{-}(x) = 0$ for $x \in K_{1},K_0,K_{-1}$. Similarly, consider $g_{+}$ defined by $g_{+}(x) = \frac{2}{n}(1+C \varepsilon^2)$ for $x \in {K_i}$ with $\abs{i} \neq 0$ and $g_{+}\bra{\frac{m(n+1)}{2}} = 2 \frac{\log^2n}{\varepsilon^4}$.

The density assumption \eqref{EXC:eq:45} and monotonicity of ${r}_{{\mathrm{uni}},m}$ imply that 
\begin{equation}
	\sum_{x} {r}_{{\mathrm{uni}},m}(x) g_{-}(x) \leq \sum_{x} {r}_{{\mathrm{uni}},m}(x) 1_{R}(x) \leq \sum_{x} {r}_{{\mathrm{uni}},m}(x) g_{+}(x),
\end{equation}
provided that $C$ is sufficiently large. Moreover, we have 
$$
\sum_{\substack{x \in K_i, \abs{i} \leq 1 }}
	{r}_{{\mathrm{uni}},m}(x) \ll \frac{\log^{2} n}{\varepsilon^2 m^{1/2}} \ll \varepsilon^2,
$$
and inserting this bound into the above inequality we find
\begin{equation}
	\sum_{x} {r}_{{\mathrm{uni}},m}(x) g_{-}(x) \geq \frac{2}{n}\bra{1-C \varepsilon^2}\bra{1 - O(\varepsilon^2)
	} =  \frac{2}{n}\bra{1-O(\varepsilon^2)}.
\end{equation}
By a similar argument, we have
\begin{equation}
	\sum_{x} {r}_{{\mathrm{uni}},m}(x) g_{+}(x) \leq \frac{2}{n}(1+C \varepsilon^2) +  {r}_{{\mathrm{uni}},m}\bra{\frac{m}{2n}} \cdot 2\frac{\log^2n}{\varepsilon^4} =  \frac{2}{n}(1+O(\varepsilon^2)).
\end{equation}
Hence, we obtain
\begin{equation}
\sum_{x} {r}_{{\mathrm{uni}},m}(x) 1_{R}(x) = \frac{2}{n}(1+O(\varepsilon^2)).
\end{equation}
Combined with \eqref{EXC:eq:53} and \eqref{EXC:eq:55}, this finishes the proof of the inductive step, and hence the entire proof.


\renewcommand{\qedsymbol}{}\end{proof}

\end{proof}

We are now in position to finish the proof of Proposition \ref{EXC:prop:P-s-in-S} (and hence also the first part of Proposition \ref{I:prop:exact}). 

\begin{proof}[Proof of  Proposition \ref{EXC:prop:P-s-in-S}]
	Let $N$ be a large even integer. From \eqref{EXC:eq:39} we have
	\begin{equation}
		\mathbb{P}(s \not\in S_\varepsilon(a)) \leq \sum_{M \leq N} (-1)^M \sum_{\abs{U} = M} \mathbb{P}\bra{ \bigwedge_{u \in U} s \in S_u(a) }. 
	\end{equation}
	The inner sum runs over $ \binom{ (1-\sigma + o(1))n}{M} = (1+o(1)) \frac{(1-\sigma)^M}{M!}n^M$ summands. The proportion of summands for which \eqref{EXC:cond:U-reg} fails is $O(\frac{m}{n})$, and by Lemma \ref{EXC:lem:kill-bad-U} each of them contributes at most $O\bra{\frac{\bra{ \frac{1}{\varepsilon}\log n}^M}{n^M}}$. Hence, their total contribution is $O\bra{ \frac{m \bra{ \frac{1}{\varepsilon}\log n}^M}{n}} = o(1)$.
	
	All remaining summands are by Proposition \ref{EXC:prop:P-wedge-s-in-S} equal to $\bra{\frac{2}{n}}^M(1+o(1))$. Thus, the inner sum can be estimated as
\begin{align*}
	\sum_{\abs{U} = M} \mathbb{P}\bra{ \bigwedge_{u \in U} s \in S_u(a) } &= \frac{(1-\sigma)^M}{M!}n^M \cdot \bra{\frac{2}{n}}^M(1+o(1)) + o(1)
	\\&= \frac{ (2-2\sigma)^M }{M!} + o(1).
\end{align*}

	This leads to the upper bound
\begin{align*}
\mathbb{P}(s \not \in S_\varepsilon(a)) &\leq \sum_{M=0}^N (-1)^M \frac{ (2-2\sigma )^M }{M!} + o(1) 
\leq e^{-2+2\sigma} + \frac{C}{N!} + o(1),
\end{align*}		
	 where the constant $C$ is absolute. Letting $N \to \infty$ slowly with $n$ we conclude that $\mathbb{P}(s \in S_\varepsilon(a)) \leq  e^{-2+2\sigma} + o(1)$.
	 
	 Running the same argument with $N$ odd we conclude the reversed bound $\mathbb{P}(s \in S_\varepsilon(a)) \geq  e^{-2+2\sigma} + o(1)$. Hence $\mathbb{P}(s \not\in S_\varepsilon(a)) = e^{-2+2\sigma}(1+o(1))$, where the error term is uniform with respect to $s$.
	 
\end{proof}

\section{Higher moments of $\abs{S(a)}$}\label{section:HM}

In this section, we (asymptotically) compute the second moment $\EE\abs{S(a)}^2$, where $a$ is a randomly selected permutation of $[n]$. Thus, we prove the concentration around the mean for $\abs{S(a)}$.

By a standard application of the second moment method, we have for any $\delta > 0$ that 
$$
	\mathbb{P}\bra{ \abs{\abs{S(a)}^{\phantom{|}\!\!\!} - \EE(\abs{S(a)}} > \delta n^2 } \leq \frac{\EE{\abs{S(a)}^2} - \EE(\abs{S(a)})^2}{\delta^2 n^4}.
$$

Hence, the concentration around the mean in Proposition \ref{I:prop:exact} will follow directly from the following result.

\begin{proposition}\label{HM:prop:E(S(a)^p)}
	The second moment of $\abs{S(a)}$ is given by $$\EE \abs{S(a)}^2 = (1+o(1))c^2 n^{4}$$ as $n \to \infty$, where $c = \frac{1+e^{-2}}{4}$. 
\end{proposition}

Because $\abs{S(a)}/n^2$ is bounded, the concentration around the mean, as stated in Proposition \ref{I:prop:exact}, implies the asymptotic formula for the higher moments $\EE \abs{S(a)}^p$ for all $p\geq 1$, namely $\EE \abs{S(a)}^p = (1+o(1)) c^p n^{2p}$. Similar formula also follows from a slight adaptation of the argument we give.




We will argue along the same lines as in Section \ref{section:EXC}. The only missing ingredient we need in order to compute the higher moments of $\abs{S(a)}$ is a strengthening of Lemma \ref{EXC:lem:kill-bad-U} where $u_k$ are not necessarily distinct. This task is less trivial than it might appear at first.

Consider an example where $u_1 = u_2$, $s_3 = s_1 - s_2$ (e.g. $s_3=s_2=\frac{1}{2} s_1$) and $\EE \sum_{i=u_1}^{u_3} a_i = s_2$. For the condition $\bigwedge_{k=1}^3 (s_k \in S_{u_k}(a))$ to hold, it suffices that $s_2 = \sum_{i=u_1}^{u_3-1} a_i $ and $s_3 \in S_{u_3}(a)$. One expects the probability of the latter event to be roughly $\frac{1}{n^{5/2}}$, at least when $s_k$ are not too small and $u_3$ is chosen to maximise $\mathbb{P}(s_2 = \sum_{i=u_1}^{u_3-1} a_i)$. This is significantly larger than the bound $\frac{1}{n^3}$ which one might expect by analogy to Lemma \ref{EXC:lem:kill-bad-U}. Hence, the direct generalisation of Lemma \ref{EXC:lem:kill-bad-U} is not possible; instead we prove an averaged version.

As before, we will only apply the following Lemma in the case when $s_k$ take at most two distinct values.

\newcommand{\mathcal{U}}{\mathcal{U}}
\newcommand{\operatorname{out-deg}}{\operatorname{out-deg}}
\newcommand{\operatorname{in-deg}}{\operatorname{in-deg}}

\begin{lemma}\label{EXC:lem:kill-bad-U-2}
	Fix a choice of $\varepsilon = \varepsilon(n)$ with $\varepsilon = o(1)$ and $\varepsilon = n^{-o(1)}$ as $n \to 0$. Let $M$ be an integer, for $1 \leq k \leq M$ let $s_k = \sigma_k \frac{n^2}{2}$ with $\varepsilon < \sigma_k < 1-\varepsilon$. Denote by $\mathcal{U}$ the  set of all sequences $u= (u_k)_{k=1}^M$ such that $\varepsilon n < u_k < (1-\sigma_k - \varepsilon)n$ for all $k$ and \emph{not} all $u_k$ are distinct. Then

	\begin{equation}\label{EXC:eq:71}
		\sum_{u \in \mathcal{U}} \mathbb{P}\bra{ \bigwedge_{k=1}^M s_k \in S_{u_k}(a)} = O\bra{ \frac{\bra{\frac{1}{\varepsilon} \log n}^M}{n}},
	\end{equation}
	where the implicit constant depends only on $M$.
\end{lemma}
\begin{proof}
	Throughout the argument, $M$ is fixed, and we allow all constructions to depend on $M$.
	
	We introduce a structure which we call ``type graph'', intended to record possible linear dependencies between different sums of the form $\sum_{i=u_k}^{v} a_{i}$ and target sums $s_k$. A type graph $G$ consists of the following data:
\begin{enumerate}
	\item An initial interval $K = [N]$ together with a partition $K = I \cup J$, $I \cap J = \emptyset$ and $\abs{I},\abs{J} \leq M$.
	\item A collection of $M$ edges $E \subset K \times K$, ordered so that if $\bra{i,j} \in E$ then $i < j$, such that $\operatorname{out-deg}(i) \geq 1$ for each $i \in I$ and $\operatorname{in-deg}(j) \geq 1$ for each $j \in J$.
	\item A collection of labels $s_{{i,j}}$ for each $\bra{i,j} \in E$, where each $s_{{i,j}}$ has the form $s_{{i,j}} = \sum_{k} q_k s_k$ with $q_k \in \mathbb{Z}$ and $\sum_{k} \abs{ q_k } \leq 2^{M^2 - L} $ where $L = \sum_{\bra{i,j} \in E} (j-i)$.
\end{enumerate}

The bound in the final condition is purely technical; it's significance will become clear in the course of the proof. Formally, $G$ is a 4-tuple consisting of $I,J,E$ and $(s_{{i,j}})_{\bra{i,j} \in E}$. Whenever we introduce a type graph $G$, we implicitly also introduce $I,J,K$, $E$ and $s_{{i,j}}$ appearing in the definition.

If $G$ is a type graph, and $(w_k)_{k \in K}$ is a (strictly) increasing sequence, then we define the condition $\mathscr{A}_G(a,w)$ to hold precisely when the system of equations:
\begin{equation}\label{EXC:eq:78}
	\sum_{i=w_k}^{w_l-1} a_i = s_{{k,l}}, \quad \bra{k,l} \in E
\end{equation}
is satisfied. 

We will say that two type graphs $G$ and $G'$ are equivalent if the events $\mathscr{A}_G(a,w)$ and $\mathscr{A}_{G'}(a,w)$ are equivalent (in particular, $K = K'$). We will call a type graph $G$ minimal if it minimises the ``total edge length'' (which also appears in the final condition defining graph types) 
\begin{align}\label{EXC::eq:def-L}
L = \sum_{\bra{k,l} \in E} (l-k)
\end{align}
 within equivalence class. Clearly, each equivalence class contains a minimal element.

\begin{observation*}
	If $G$ is a minimal type graph, then the underlying unlabelled graph $(K,E)$ is a union of disjoint paths.
\end{observation*}
\begin{proof}
First note that if $G$ is minimal, then there is no pair of edges $\bra{k,l}$, $\bra{m,l} \in E$ with equal endpoints.

Indeed, if there was such a pair, without loss of generality with $k < m$, then we can replace the edge $\bra{k,l}$ with $\bra{k,m}$ and put $s_{k,m} = s_{{k,l}} - s_{{l,m}}$. (Note that this decreases the total edge length $L$ from \eqref{EXC::eq:def-L} by at least $1$, and thus $s_{{k,l}} - s_{{l,m}}$ is a feasible label). Hence, if $G$ is minimal then for each $l$, $\operatorname{in-deg}(l) \leq 1$.

 By a similar argument, $\operatorname{out-deg}(k) \leq 1$ for each $k$. If follows that
$G$  (as an unlabelled graph) is a union of disjoint paths.
\end{proof}

\begin{observation*}
	If $(u_k)_{k=1}^M \in \mathcal{U}$ and if $a$ is a permutation such that $s_k \in S_{u_k}(a) $ for each $k$, then there exists a minimal type graph $G$ and an increasing sequence $(w_k)_{k \in K}$ such that $\{w_i\}_{i \in I} = \{u_k\}_{k=1}^M$, $\abs{I} < M$ and $\mathscr{A}_G(a,w)$ holds.
\end{observation*}
\begin{proof}
	By assumption, for each $k$ there is some $v_k$ such that $\sum_{i=u_k}^{v_k-1} a_i = s_{k}$. We may define an increasing sequence $(w_k)_{k=1}^N$ so that $\{w_k\}_{k=1}^N = \{u_k\}_{k=1}^M \cup \{v_k\}_{k=1}^M$ and put $K = [N]$. We next take $I = \{i \in K \ : \ (\exists k \in [M]) \ w_i = u_k \}$ and $J = K \setminus I$. Finally, we define $E$ by putting $\bra{i,j} \in E$ precisely when $(w_i,w_j) = (u_k,v_k)$ for some $k \in M$, and take $s_{{i,j}} := s_k$.
	
	Thus defined $G$ satisfies all of the imposed conditions, possibly except minimality. Replacing $G$ by a minimal type graph within the equivalence class, we obtain the claim.
\end{proof}

It follows from the above Observation that the sum in \eqref{EXC:eq:71} is at most:
	\begin{equation}\label{EXC:eq:75}
		\sum_{\substack{ G \text{ -- m.t.g.} \\ \abs{I} < M}}
		\sum_{\substack{ (w_k)_{k \in K} \\ w_k \geq \varepsilon n}}
		\mathbb{P}( \mathscr{A}_G(a, w))
	\end{equation}
	where the sum $\sum_G$ is taken over all minimal type graphs $G$ with $\abs{I} < M$, and sum $\sum_{w}$ is taken over all choices of $(w_k)_{k\in K}$ with $\varepsilon n \leq w_k$ for all $k$.

	Since there are $O_M(1)$ type graphs, to prove the proposition, it will suffice to show that for each minimal type graph $G$ with $\abs{I} < M$ we have
	\begin{equation}\label{EXC:eq:76}
		\sum_{\substack{ (w_k)_{k \in K} \\ w_k \geq \varepsilon n}}
		\mathbb{P}( \mathscr{A}_G(a, w))
		\leq C_M \frac{ \bra{ \frac{1}{\varepsilon} \log n}^M}{n},
	\end{equation}
	where the constant $C_M$ depends only on $M$.	

Let $K_0$ be the set of $k \in K$ such that $\operatorname{in-deg}(k) = 0$, and $K_1 = K \setminus K_0$. If $\{w_k \ : \ k \in K_0\}$ is specified then for any permutation $a$ there is at most one choice of $\{w_k \ : \ k \in K_1\}$ such that $\mathscr{A}_G(a,w)$ holds. Hence, we may rewrite the probability in \eqref{EXC:eq:76} as:
	\begin{equation}\label{EXC:eq:77}
		\sum_{\substack{ (w_k)_{k \in K} \\ w_k \geq \varepsilon n}}
		\mathbb{P}( \mathscr{A}_G(a, w)) = \sum_{\substack{(w_m)_{m \in K_0} \\ w_m \geq \varepsilon n }} \mathbb{P}( (\exists (w_m)_{m \in K_1}) \ : \ \mathscr{A}_G(a, w)).
	\end{equation}
	
	We will now select $a_i$ in the order of increasing $i$, starting at $i(0) = \floor{ \varepsilon n} $. Thus, at ``time'' $0 \leq t \leq n-i(0)$, we select $a_{i(t)}$, where $i(t) = i(0) + t$. We then select $a_{i}$ with $1 \leq i < i(0)$ at times $n - i(0) < t \leq n$, but these values will not play a significant role. To study time evolution, we let $\mathcal{F}_t$ be the $\sigma$-algebra generated by $a_{v(t')}$ with $0 \leq t' \leq t$. 
	
	At time $t = 0$, the values $w_m$ with $m \in K_0$ are specified, but not the values $w_m$ with $m \in K_1$. If $w_k$ has been specified and $\bra{k,l} \in E$ then as $t$ increases, so will $\sum_{i=w_k}^{i(t)} a_{i}$. As long as $\sum_{i=w_k}^{i(t)} a_{i} \neq s_{{k,l}}$ we consider $w_l$ to be unspecified, but as soon $\sum_{i=w_k}^{i(t)} a_{i} = s_{{k,l}}$ we put $w_l = i(t)+1$. If no such $t$ is found, then $w_l$ is unspecified indefinitely. Note hat whether or not $w_k$ is specified at $t$ is a $\mathcal{F}_t$-measurable event.
	
	At each time $t$, either there is a least value $l = l(t) \in K_1$ such that $w_{l}$ has not yet been specified, or else all $w_{l}$ have been specified, and we set $l(t) := \infty$. If $l(t) \neq \infty$, there is some $k = k(t)$, such that $\bra { {k(t)}, {l(t)}} \in E$ and hence $\mathscr{A}_G(a,w)$ imposes the condition $\sum_{i=w_{k(t)}}^{w_{l(t)}} a_i = s_{k(t),l(t)}$. If $l(t) = \infty$, set $k(t) = \infty$.

	We introduce random variables $X_t,Y_t$, adapted to the filtration $\mathcal{F}_t$. The variable $X_t$ counts equations required by $\mathscr{A}_G(a,w)$ which have been satisfied: 
	$$
	X_{t+1}=
	\begin{cases}
	1 & \text{ if $\sum_{i=w_{k(t)}}^{i(t+1)} a_i = s_{k(t),l(t)}$ ,} \\
	0 & \text{ otherwise (including $k(t) = \infty$) }.
	\end{cases} 
	$$	
	
Note that the event $\mathscr{A}_G(a,w)$ is equivalent to $\sum_{t} X_t = \abs{K_1}$. The variable $Y_t$ counts potential opportunities for $X_{t+1}$ to take value $1$: 
	$$
	Y_{t+1}=
	\begin{cases}
	1 & \text{ if $s_{k(t),l(t)}-\sum_{i=w_{k(t)}}^{i(t)} a_i \in [n]$,} \\
	0 & \text{ otherwise (including $k(t) = \infty$)}.
	\end{cases} 
	$$	
	Note that if $X_{t+1} = 1$ then $Y_t = 1$. More precisely, we have:
	$$
		\EE(X_{t+1} \ | \ \mathcal{F}_t) \leq \frac{Y_t}{\varepsilon n},
	$$
since at most one of more than $\varepsilon n$ possible values of $a_{i(t+1)}$ guarantees that $X_{t+1} = 1$. 

Let $C = C_M$ be a large constant. We always have the following bound:
\begin{align*}
	\mathbb{P}\bra{ \sum_t X_t = \abs{K_1} }
	&\leq \mathbb{P}\bra{ \sum_t X_t = \abs{K_1} \ \wedge \ \sum_t Y_t \leq C \log n }
	\\& + \mathbb{P}\bra{  \sum_t Y_t > C \log n }
\end{align*}  
(where the sums $\sum_t$ can be assumed to run over $0 \leq t \leq n-\varepsilon n$).

The first summand can estimated using a union bound on the choice of the set of $t$ with $X_t = 1$:
\begin{align*}
\mathbb{P}\bra{ \sum_t X_t = \abs{K_1} \ \wedge \ \sum_t Y_t \leq C \log n } &\leq \binom{C \log n}{\abs{K_1}}\bra{ \frac{1}{\varepsilon n} }^{\abs{K_1}} 
\\ &= O_M \bra{ { \frac{ \bra{ \frac{1}{\varepsilon}\log n}^{\abs{K_1}} }{n^{\abs{K_1}} }}}.
\end{align*}

For the second sum, if $C$ is sufficiently large (with respect to $M$) we have by a standard application of Hoeffding's inequality
$$
\mathbb{P}\bra{  \sum_t Y_t > C \log n } = O_M \bra{\frac{1}{n^{\abs{K_1}} } }.
$$

In total, the sum in \eqref{EXC:eq:77} is bounded from above by $O_M\bra{ \frac{\bra{ \frac{1}{\varepsilon}\log n}^{M}}{n^{\abs{K_1} - \abs{K_0}} }}$.

To finish the proof, it remains to verify that $\abs{K_1} > \abs{K_0}$. Recall that, being minimal, $G$ is a union of a certain number $P$ of paths of lengths $l_1,l_2,\dots,l_P \geq 2$ with startpoints in $I$ and endpoints in $J$. We have $\abs{K_0} = P \leq \abs{I}$ and $\abs{K_1} = \sum_{j=1}^P (l_j -1) = \abs{E} = M$. Since $M > \abs{I}$ by assumption, we are done.

	
\end{proof}

We now have all the tools necessary to compute the second moment of $\abs{S(a)}$. The argument is very similar to the one we used to compute $\EE \abs{S(a)}$. In places where the arguments are virtually identical, we give only the outline, and encourage the reader to look to Section \ref{section:EXC} for details. 

\begin{proof}[Proof of Proposition \ref{HM:prop:E(S(a)^p)}]

	Fix a choice of $\varepsilon$, for instance $\varepsilon(n) = \frac{1}{\log n}$. With the a Riemann integral approximation argument much as before, it will suffice to show that for any $s_1,s_2$ with $s_j = \sigma_j \frac{n^2}{2}$, $\varepsilon < \sigma_j < 1-\varepsilon$ one has
\begin{equation}\label{EXC:eq:61}
	\mathbb{P}\bra{  s_1,s_2 \not \in S_\varepsilon(a) } = (1+o(1)) \prod_{j=1}^2 e^{-2+2\sigma_j}.
\end{equation}
where the error term is uniform with respect to the choice of $s_1,s_2$. Once this is established, we also have 
$$\mathbb{P}\bra{ s_1,s_2 \in S_\varepsilon(a) } = (1+o(1)) \prod_{j=1}^2 (1-e^{-2+2\sigma_j}).$$
and hence 
\begin{align*}
	\EE\abs{S_\varepsilon(a)}^2 &= \sum_{s_1,s_2} \mathbb{P}\bra{ s_1,s_2 \in S_\varepsilon(a) } + o(n^4)
	\\ &= \sum_{s_1,s_2} \prod_{j=1}^2 (1-e^{-2+2 \frac{2s}{n^2}}) +  o(n^4) 
	\\ &= n^4 \int_{\varepsilon}^{1-\varepsilon} \prod_{j=1}^2 (1-e^{-2+2\sigma_j})d \sigma_1 d\sigma_2 + o(n^4) 
	= n^4(c^2 + o(1)),
\end{align*} 
where the sums run over $\varepsilon \frac{n^2}{2} < s_1,s_2 < (1- \varepsilon) \frac{n^2}{2}$, and $c = \frac{1 + e^{-2}}{4}$. Finally, we note that $\abs{S(a)} = (1+o(1))\abs{S_\varepsilon(a)}$, as we have already shown in Section \ref{section:EXC}. Hence, it remains to prove \eqref{EXC:eq:61}.

We may rewrite the probability in \eqref{EXC:eq:61} using inclusion/exclusion as:
\begin{equation}\label{EXC:eq:62}
	\sum_{M_1=0}^\infty (-1)^{M_1} \sum_{\abs{U_1} = M_1} \sum_{M_2=0}^\infty (-1)^{M_2} \sum_{\abs{U_p} = M_p} \mathbb{P}\bra{ \bigwedge_{j=1}^2 \bigwedge_{k=1}^{M_j} \bra{ s_j \in S_{u_{j,k}}(a) }},
\end{equation}
where the inner sums are taken over all choices of $U_{j} = \{u_{j,k}\}_{k=1}^{M_j} \subset [n]$ such that $\varepsilon n < u_{j,k} < (1-\varepsilon-\sigma_j) n$. 

Let $N$ be a large even integer, and put $N_1 = N$ and 
$$	
	N_2 = N_2(M_1) = 
	\begin{cases}
		N & \text{ if } M_1\equiv 0 \pmod{2} \\
		N+1 & \text{ if } M_1 \equiv 1 \pmod{2}.		
	\end{cases}
$$ 
Then the sum in \eqref{EXC:eq:62} is bounded from above by the truncated sum
\begin{equation}\label{EXC:eq:62a}
	\sum_{M_1=0}^{N_1} (-1)^{M_1}
	\sum_{M_2=0}^{N_2} (-1)^{M_2} 
	\sum_{\substack{ \abs{U_j} = M_j \\ j=1,\dots,p}}
	\mathbb{P}\bra{ \bigwedge_{j=1}^2 \bigwedge_{k=1}^{M_j} \bra{ s_j \in S_{u_{j,k}}(a) }}.
\end{equation}

With the same definitions, for odd values of $N$ the expression above gives a lower bound. Hence, to find asymptotics for the sum \eqref{EXC:eq:62}, it will suffice to find asymptotics for each of summands with  $M_1,M_2$ fixed.

We now consider the innermost sum. Let $U = U_{1} \cup U_2$. Using Lemmas \ref{EXC:lem:kill-bad-U} and \ref{EXC:lem:kill-bad-U-2}, we may disregard the contribution $O\bra{\frac{m \bra{ \frac{1}{\varepsilon} \log n}^M}{n}} =o(1)$ from $U$ with $U_1 \cap U_2 \neq \emptyset$, and from $U$ which do not satisfy the regularity condition \eqref{EXC:cond:U-reg} for a suitable choice of the parameter $m = m(n)$. For remaining $U$, we have from Proposition \ref{EXC:prop:P-wedge-s-in-S} (or more precisely, the internal Lemma in its proof) that 
\begin{equation}\label{EXC:eq:63}
		\sum_{\substack{ \abs{U_j} = M_j \\ j=1,2}}
	\mathbb{P}\bra{ \bigwedge_{j=1}^2 \bigwedge_{k=1}^{M_j} \bra{ s_j \in S_{u_{j,k}}(a) }}
 = (1+o(1))\bra{ \frac{2}{n} }^{M_1+M_2}.
\end{equation}

The number of choices of $(U_1,U_2)$ when $(M_1,M_2)$ are fixes is equal to  $(1+o(1)) \prod_{j=1}^2 \frac{(1-\sigma_j)^{M_j}}{M_j!}n^{M_j}$. Thus the inner sum is asymptotically equal to:
\begin{equation}\label{EXC:eq:64}
\bra{ \frac{2}{n} }^{M_1+M_2} \prod_{j=1}^2  \frac{(1-\sigma_j)^{M_j}}{M_j!}n^{M_j} 
= \prod_{j=1}^2   \frac{(2-2\sigma_j)^{M_j}}{M_j!}.
\end{equation}

Thus, for any large even integer $N$ the sum in \eqref{EXC:eq:62a} is bounded from above by:
\begin{equation}\label{EXC:eq:65}
	\sum_{\substack{ M_j=0 \\ j = 1,2}}^{\infty} (-1)^{M_1+M_2}
	\prod_{j=1}^2 \frac{(2-2\sigma_j)^{M_j}}{M_j!}
	+ \frac{C}{N!} + o(1),
\end{equation}
where $C$ is an absolute constant. The sum in \eqref{EXC:eq:65} is simply the Taylor expansion of $\prod_{j=1}^2 e^{-2+2\sigma_j}$. Letting $N \to \infty$ slowly with $n$, and repeating the same argument for $N$ odd, we conclude that \eqref{EXC:eq:61} holds.


\end{proof}
\section{Lower bound}\label{section:EXT-low}

We will presently prove a lower bound on $\max_{a} \abs{S\bra{a}}$ as $a$ runs over permutations of $[n]$, which is slightly better than $\max_{a} \abs{S\bra{a}} \geq \EE_a \abs{S\bra{a}} = \bra{ \frac{1+e^{-2}}{4} +o(1)} n^2 $ (which in turn is slightly better than $\max_{a} S(a) \geq (\frac{1}{4}+o(1))n^2$ from Proposition \ref{I:prop:cexple-basic}). 

Namely, we will show that $\max_{a} \abs{S\bra{a}} \geq (\frac{3}{2}-\frac{2}{\sqrt{e}} + o(1)) n^2$, thus proving Proposition \ref{I:prop:cexple-improved}. We accomplish this by introducing a randomised variant of the construction from Proposition \ref{I:prop:cexple-basic}.

We note that the numerical values of the two constants mentioned above are rather close: $\frac{3}{2}-\frac{2}{\sqrt{e}} = 0.286\dots$, while $\frac{1+e^{-2}}{4} = 0.283\dots$. Hence, the quality of the bound is hardly a reason for interest in the results of this section. Instead, we point out that our construction gives a fairly broad and explicit class of permutations with $\abs{S(a)}$ significantly above the expected value. In particular, the bound $\max_{a} \abs{S\bra{a}} \geq \EE_a \abs{S\bra{a}}$ is far from sharp.

\renewcommand{\l}{\lambda}
\begin{proof}[Proof of Proposition \ref{I:prop:cexple-improved}]\mbox{}\\
	Let $a$ be a permutation of $[n]$ selected uniformly at random, subject to the condition that $a_{i} + a_{i+1} = n+1$ for each odd $i$. We will show that $\EE \abs{S(a)} \geq (c+o(1)) n^2$ where $c = \frac{3}{2}-\frac{2}{\sqrt{e}}$.
	
	Let us fix a choice of $s = l\bra{n+1} + r$, where $l = \lambda \frac{n}{2}$ and $r = \rho n$ are integers and $0 \leq \lambda, \rho \leq 1$.
	
	Our first goal is to estimate $\mathbb{P}\bra{s \in S(a)}$, where we fix the value of $s$.
	 
It is clear that if $s = \sum_{i=u}^v a_i$ then $v-u+1 \in \{2l,2l+1,2l+2\}$. Let us enumerate all possible intervals of length $2l$, and let $\mathscr{A}_i$ be the event that $s$ is the sum of $a_j$ over the $i$-th interval, where $1 \leq i \leq n-2l = \bra{1-\l + o(1)}n$. Likewise, let $\mathscr{B}_j$ be the event that $s$ is the sum over the $j$-th interval of length $2l+2$, $1 \leq j \leq n-2l-2$. Finally, let $\mathscr{C}$ be the event that $s$ is the sum over some interval of length $2l+1$; there can be at most one such interval.

For each $i$ there are some $u,v$ (namely the endpoints of the relevant interval) such that $\mathscr{A}_i$ holds if and only if $r = a_u + a_v$. Hence $\mathbb{P}\bra{\mathscr{A}_i} = \frac{\rho}{n} + O\bra{\frac{1}{n^2}}$. Similarly, each $\mathscr{B}_j$ is equaivalent to $r + \bra{n+1} = a_v + a_u$ for some $u,v$, and $\mathbb{P}\bra{\mathscr{B}_j} = \frac{1-\rho}{n} + O\bra{\frac{1}{n^2}}$. Likewise, $\mathscr{C}$ holds if and only if $r = a_u$ where either $u$ is even and $\leq n-2l$ or $u$ is odd and $\geq 2l$, and thus $\mathbb{P}\bra{\mathscr{C}} = 1-\l + O\bra{\frac{1}{n}}$.

Moreover, we have the following asymptotic independence condition.
\begin{lemma*
Let $k,l$ be integers. Then
\begin{equation}\label{EXT:eq:11}
	\EEE_{\abs{I} = k} \EEE_{\abs{J}=l} \mathbb{P}\brabig{ \bigwedge_{i \in I} \mathscr{A}_i \wedge \bigwedge_{j \in J} \mathscr{B}_j } = \bra{\frac{\rho}{n}}^k \bra{\frac{1-\rho}{n}}^l + O\bra{\frac{1}{n^{k+l+1}}},
\end{equation}
where the expected values are taken over all possible choices of index sets of given size. 
Likewise, we have 
\begin{equation}\label{EXT:eq:12}
	\EEE_{\abs{I} = k} \EEE_{\abs{J}=l} \mathbb{P}\brabig{ \bigwedge_{i \in I} \mathscr{A}_i \wedge \bigwedge_{j \in J} \mathscr{B}_j \wedge \mathscr{C} } 
	= \bra{\frac{\rho}{n}}^k \bra{\frac{1-\rho}{n}}^l \bra{1-\l} + O\bra{\frac{1}{n^{k+l+1}}}.
\end{equation}
Here, the implicit constants may depend on $k,l$.
\end{lemma*} 
\begin{proof} 

We only give the argument for the former equality, the latter being analogous. For given $I,J$ with $\abs{I} = k,\ \abs{J} = l$, let $\mathscr{E} = \mathscr{E}_{I,J} = \bigwedge_{i \in I} \mathscr{A}_i \wedge \bigwedge_{j \in J} \mathscr{B}_j$. Also, let $m = k+l$.

Recall that each event $\mathscr{A}_i$ is equivalent to $a_{u_i} + a_{v_i} = r$, and likewise $\mathscr{B}_j$ is equivalent to $a_{u_j'} + a_{v_j'} = r+n+1$. Because of the restriction $a_{i}+a_{i+1} = n+1$ for odd $i$, the event $\mathscr{E}$ is equivalent to a system of $m$ linear equations of the form 
\begin{equation}\label{EXT:eq:01}
\sum_{j=1}^{2m} M_{ij} b_j = c_i \qquad  (i \in [m]),
\end{equation} 
 where $M_{ij} \in \{0,-1,+1\}$ with $M_{ij} \neq 0$ for precisely $2$ values of $j$ for a fixed $i$, $b_j = a_{w_j}$ for some odd $w_j \in [n]$ and $c_{i} \in \{r,r+(n+1),r-(n+1),r-2(n+1)\}$. We may write \eqref{EXT:eq:01} more briefly as $Mb = c$.
 
We will need a uniform bound on $\mathbb{P}(\mathscr{E}_{I,J})$, valid for all choices of $I,J$ with $\abs{I} = k,\abs{J} = l$. For this purpose, we introduce an (undirected) graph $G = G_{I,J}$ with vertex set $[2m]$ such that the edge $(j_1, j_2)$ is present precisely when there exists a row $i$ such that $M_{i,j_1}, M_{i,j_2} \neq 0$.

Note that if $\mathbb{P}(\mathscr{E}_{I,J}) \neq 0$ then for any pair $j_1,j_2$ there can be at most one $i$ such that $M_{i,j_1}, M_{i,j_2} \neq 0$; else one could find a pair of intervals with endpoints differing by $1$ and both sums equal to $s$, which is impossible. Hence, $G$ has precisely $m$ edges. Moreover, it follows from the construction that $G$ is acyclic. 
Hence, $G$ has $2m-m = m$ connected components (possibly some of which are singletons). 

For each connected component of $G$, one value of $b_j$ may be chosen freely, and then \eqref{EXT:eq:01} determines the remaining ones. Hence, 
$$\mathbb{P}(\mathscr{E}_{I,J}) = \mathbb{P}(Mb=c) = O\bra{\frac{1}{n^m}},$$ where the implicit constant depends at most on $m$.  

Having obtained the universal upper bound above, we will restrict to suitably generic $I,J$. If $I, J$ are chosen randomly from all subsets of $[n]$ of suitable sizes $\abs{I} = k,\ \abs{J} =l$, then with probability $1 - O\bra{\frac{1}{n}}$ the corresponding graph $G$ consist of $m$ disconnected intervals --- this happens precisely if no pair of indices $u_i,v_i,u'_j,v'_j$ introduced above is equal, nor is any pair of the form $w,w+1$ with $w$ odd.

Hence, at the cost of introducing an error term $O\bra{\frac{1}{n^{m+1}}}$, we may restrict our attention to $I,J$ such that the corresponding grahp $G$ is a union of $m$ connected, components as described above.

We now argue for a fixed choice of $I,J$. Suppose that $\mathscr{D}$ is one of the events $\mathscr{A}_i,\mathscr{B}_j$, and let $u,v$ be the relevant coordinates $u_i,v_i$ or $u'_j,v'_j$ accordingly. For an integer $N$ (bounded in terms of $k,l$), let $d_1,\dots,d_N \in [n]$ and $i_{1},\dots,i_{N} \in [n]$ be arbitrary.  Then 
\begin{equation}\label{EXT:eq:02a}
	\mathbb{P}\bra{\mathscr{D} \mid a_{i_1}=d_1,\dots,a_{i_N} = d_N} = \mathbb{P}\bra{\mathscr{D}} + O\bra{\frac{1}{n^2}},
\end{equation}
	where the implicit constant depends only on $N$, provided that the event we condition on above has non-zero probability and that $i_1,\dots,i_N$ differ from $u,v$ by at least $2$. By a standard argument, the above equality \eqref{EXT:eq:02a} implies that for any $I' \subset I,\ J' \subset J$ we have
\begin{equation}\label{EXT:eq:02b}
	\mathbb{P}\bra{\mathscr{D} \mid \bigwedge_{i \in I'} \mathscr{A}_i \wedge \bigwedge_{j \in J'} \mathscr{B}_j } = \mathbb{P}\bra{\mathscr{D}} + O\bra{\frac{1}{n^2}}.
\end{equation}
Ordering $\mathscr{A}_i,\mathscr{B}_j$ as $\mathscr{D}_i$ with $i \in K$, putting $\mathscr{E}_j' = \bigwedge_{i < j} \mathscr{D}_j$ and using $\mathbb{P}(\mathscr{D}_j) = O\bra{\frac 1n}$ we find
\begin{align*}\label{EXT:eq:02c}
	\mathbb{P}\bra{\mathscr{E} } &= \prod_{j \in K} \mathbb{P}\bra{\mathscr{D}_j \mid \mathscr{E}_j'} = \prod_{j \in K} \bra{ \mathbb{P}\bra{\mathscr{D}_j} + O\bra{\frac{1}{n^2}}}
	\\ &= \prod_{j \in K}  \mathbb{P}\bra{\mathscr{D}_j} + O\bra{\frac{1}{n^{m+1}}}.
\end{align*}

This is precisely the stated bound.
\end{proof}

We may now estimate $\mathbb{P}\bra{s \not \in S(a)}$ from inclusion-exclusion formula, truncated at level $N$, where $N$ is a large even integer:
\begin{align*}
	\mathbb{P}\bra{s \not \in S(a)} & 
	\leq \sum_{k+l\leq N}\sum_{\abs{I} = k}  \sum_{\abs{J} = l} \bra{-1}^{k+l} \mathbb{P}\bra{\bigwedge_{i \in I} A \wedge \bigwedge_{j \in J} \mathscr{B}_j} 
	\\& - 
	\sum_{k+l < N}\sum_{\abs{I} = k}  \sum_{\abs{J} = l} \bra{-1}^{k+l} \mathbb{P}\bra{\bigwedge_{i \in I} A  \wedge  \bigwedge_{j \in J} \mathscr{B}_j  \wedge  C}.
\end{align*}
Substituting bounds from the Lemma above we find:
\begin{align*}
\mathbb{P}\bra{s \not \in S(a)} &
\leq \sum_{k+l\leq N} \bra{-1}^{k+l} \bra{ \frac{\rho}{n}}^k
 \bra{ \frac{1-\rho}{n}}^l \frac{\bra{\frac{1-\lambda}{2}n}^{k+l} }{k! \ l!} 
 \\ &-\sum_{k+l < N} \bra{-1}^{k+l} \bra{ \frac{\rho}{n}}^k
 \bra{ \frac{1-\rho}{n}}^l \frac{\bra{\frac{1-\lambda}{2}n}^{k+l} }{k! \ l!} \bra{1-\lambda} + O_N\bra{\frac{1}{n}} 
 \\& = \sum_{m \leq N} \bra{-1}^{m} \frac{\bra{\frac{1-\lambda}{2}}^{m} }{ m!} \lambda
  + O\bra{\frac{1}{N!}} + O_N\bra{\frac{1}{n}} 
 \\& = e^{-\frac{1-\lambda}2}\lambda + O\bra{\frac{1}{N!}} + O_N\bra{\frac{1}{n}}, 
\end{align*}
where we use the notation $O_N\bra{\cdot}$ to signify that the implicit constant is allowed to depend on $N$. Letting $N \to \infty$ slowly with $n$, we conclude that:
$$
\mathbb{P}\bra{s \not \in S(a)} \leq e^{-\frac{1-\lambda}{2}}\lambda + o(1),
$$
with the error term uniform with respect to the choice of $s$. It follows that:
\begin{align*}
	\EE \abs{S(a)} 
	& \geq n^2\frac{1+o(1)}{2}\int_0^{1} \int_0^{1} \bra{1 - e^{-\frac{1-\lambda}{2}}\lambda} d\lambda d\rho 
	\\ &= n^2 \bra{\frac{3}{2}-\frac{2}{\sqrt{e}} - o\bra{1} }.
\end{align*}
A symmetric argument yields $\EE \abs{S(a)} \leq n^2 \bra{\frac{3}{2}-\frac{2}{\sqrt{e}} + o\bra{1} }$, which finishes the proof.
\end{proof}

\section{Upper bound}\label{section:EXT-up}

At this stage it seems that the distinct sums $\sum_{i=u}^v a_i$ tend to be rather numerous. The trivial upper bound on their quantity is $\binom{n+1}{2}$, which happens to be both the upper bound for any single sum and the number of distinct intervals.

It is natural to ask if this bound is sharp, and it turns out that it is not. In this section we obtain a slight improvement, namely
\begin{equation}
{S(a)} \leq \bra{\frac 14 + \frac{\pi}{16} + o(1)}{n^2},
\label{EXTup::eq:L-def}
\end{equation}
thus proving Proposition \ref{I:prop:upper-bound}.

We will consider the set of sums which are above average value. Define:
\begin{equation}
	L(a) := \bbra{ (u,v) \in [n]^2 \ : \ u \leq v, \ \sum_{i=u}^v a_i \geq \frac{1}{2} \binom{n+1}{2} }.
	\label{EXTup:eq:La-def}
\end{equation}
	
Our main idea is to show that $L(a)$ can never be too large. The following proposition easily implies Proposition \ref{I:prop:upper-bound}.
	
\begin{proposition}\label{EXTup:prop:L(a)-bound}
	Let $a$ be a permutation of $[n]$, and let $L(a)$ be defined as above. Then:
	$$
		L(a) \leq \bra{\frac{\pi}{16} + o(1)} n^2.
	$$
\end{proposition}

\begin{remark*}
	The constant $\frac{\pi}{16}$ cannot be improved, as shown by the ``tent map'' permutation:
	$$
		a_i = 
		\begin{cases}
		2 i,  & i \leq \frac{n}{2} \\
		2(n-i) + 1, & i > \frac{n}{2}.
		\end{cases}
	$$
	This is essentially the only possible example, as will become clear in the course of the proof. Note, however, that for this particular permutation we have $S(a) = o(n^2)$ for similar reasons as for the trivial permutation; see also Proposition \ref{LOW:prop:small-S}. We believe that the bound in \ref{I:prop:upper-bound} is not sharp.
\end{remark*}

\begin{proof}[Proof of Proposition \ref{I:prop:upper-bound} assuming Proposition \ref{EXTup:prop:L(a)-bound}]
	Partitioning $S(a)$ in two parts at $\frac{1}{2} \binom{n+1}{2}$ we easily find that:
\begin{equation*}
\abs{S(a)} \leq \frac{1}{2} \binom{n+1}{2} + \abs{L(a)} \leq\bra{ \frac{1}{4} + \frac{\pi}{16} + o(1)}n^2.
\end{equation*} 
This is precisely the sought bound.
\end{proof}

We will devote the remainder of this section to proving Proposition \ref{EXTup:prop:L(a)-bound}.

To begin with, we reduce the problem to the case when the permutation can be partitioned into two monotonous parts. This part of the argument restricts the sample space significantly, and will be crucial to ensure that the continuous version of the problem has enough compactness for the maximum to be realised.

\begin{observation}\label{EXTup:obs:perm-mono}
	Let $a$ be a permutation on $[n]$. Then there exists another permutation $a'$ such that $\abs{L(a)} \leq \abs{L(a')}$ and there exists $k$ such that $a_1',\dots,a_k'$ is increasing and $a_k',a_{k+1}',\dots, a_n'$ is decreasing.
\end{observation}
\begin{proof}
	Choose $k$ so that $\sum_{i=1}^{k} a_i \geq \frac{1}{2} \binom{n+1}{2}$ and $\sum_{i=k}^{n} a_i \geq \frac{1}{2} \binom{n+1}{2}$.

	Consider the permutation $a'$ obtained from $a$ by sorting $a_1,\dots,a_k$ in increasing order and $a_{k+1},\dots,a_n$ in the decreasing order. More precisely, let $a'$ be such that $\{ a_i' \ : \ 1 \leq i \leq k\} = \{ a_i \ : \ 1 \leq i \leq k\}$, $\{ a_i' \ : \ k < i \leq n\} = \{ a_i \ : \ k < i \leq n\}$, $a_1' < \dots < a_k'$ and $a_{k+1}' > \dots > a_n'$. Clearly, $a'$ has the required monotonicity property.
	
	We claim that $L(a) \subseteq L(a')$. Suppose that $(u,v) \in L(a)$. By the choice of $k$, we have $u \leq k \leq v$. Thus,
	$$ 
		\frac{1}{2} \binom{n+1}{2} \leq \sum_{i=u}^v a_i 
		= \sum_{i=u}^k a_i + \sum_{i=k+1}^v a_i
		\leq \sum_{i=u}^k a_i' + \sum_{i=k+1}^v a_i' = \sum_{i=u}^v a_i'. 
	$$	
	Thus, $(u,v) \in L(a')$, as desired.
\end{proof}

	We are now ready to introduce the continuous variant. The analogue of the space of all permutations of $[n]$ obeying the monotonicity condition in Observation \ref{EXTup:obs:perm-mono} is the family ${ \mathcal{F}_{\mathrm{mon}} }$ of measurable functions $f\colon [0,1] \to [0,1]$ obeying the following conditions:
\begin{enumerate}
	\item\label{EXTup:cond:01} for any measurable $E \subset [0,1]$, $\int_{E} f(x)dx \geq \frac{\abs{E}^2}{2}$, and $\int_0^1 f(x) dx = \frac{1}{2}$,
	\item\label{EXTup:cond:02} there exists $\kappa=\kappa_f$ such that $\int_{0}^\kappa f(x) dx = \int_{\kappa}^1 f(x) dx = \frac{1}{4}$, and moreover $f|_{[0,\kappa]}$ is increasing and $f|_{[\kappa,1]}$ is decreasing.
\end{enumerate}	
(Here and elsewhere, if $E \subset \mathbb{R}$ is measurable then $\abs{E}$ denotes the Lebesgue measure of $E$.) Note that for a permutation $a$ and any index set $I$ we have $\sum_{i \in I} a_i \geq \binom{\abs{I}+1}{2}$, in analogy to condition \eqref{EXTup:cond:01}.

We will also occasionally need to use the larger family $\mathcal{F}$ of functions $f\colon [0,1] \to [0,1]$ which only satisfy the condition \eqref{EXTup:cond:01} but not necessarily \eqref{EXTup:cond:02}. We note in passing that $\mathcal{F}$ is convex, and both ${ \mathcal{F}_{\mathrm{mon}} }$ and $\mathcal{F}$ are closed in the $L^1$ topology.

Another thing we are missing is an continuous analogue of $L(a)$ from \eqref{EXTup:eq:La-def}. For any $f \in \mathcal{F}$ we define:
\begin{align}
	L(f) &:= \bbra{(x,y) \in [0,1]^2 \ : \ x \leq y,\ \int_x^y f(t) dt \geq \frac{1}{4} }
\end{align}

The continuous analogue of Proposition \ref{EXTup:prop:L(a)-bound} is the following statement.

\begin{proposition}\label{EXTup:prop:L(f)-bound}
	Suppose that $f \in { \mathcal{F}_{\mathrm{mon}} }$. Then $\abs{L(f)} \leq \frac{\pi}{16}$.
\end{proposition}

This bound is sharp. The (unique) function $f$ with $\Lambda(f) = \frac{\pi}{16}$ will turn out to be the ``tent map'':
$$
		f(x) = 
		\begin{cases}
			2x &  \text{ if } x \leq \frac{1}{2}\\
			2(1-x) &  \text{ if } x \geq \frac{1}{2}.
		\end{cases}
$$

We defer the proof of  Proposition \ref{EXTup:prop:L(f)-bound}. Our immediate goal is to deduce Proposition \ref{EXTup:prop:L(a)-bound} from Proposition \ref{EXTup:prop:L(f)-bound}. Before we do that, we make some preliminary observations which will be useful in the course of the proof, as well as in the main body of the argument. For $f \in \mathcal{F}$, define 
\begin{align}
		v_f(u) & := \sup\left\{ v \in [0,1] \ : \ \int_{u}^v f(x) dx \leq \frac{1}{4} \right\}, \\
		u_f(u) & := \inf\left\{ u \in [0,1] \ : \ \int_{u}^v f(x) dx \leq \frac{1}{4} \right\}	, \\
		\Lambda(f) &:= \abs{L(f)}.
\end{align}

\begin{observation}\label{EXTup:obs:prelim}
	With the definitions as above, the following are true.
	\begin{enumerate}
	\item The maps $\mathcal{F} \ni f \mapsto v_f \in L^1([0,1])$ and $f \mapsto u_f$ are well defined and continuous, where on $\mathcal{F}$ we take the $L^1$ topology.
	\item For any $u_0,v_0$ with $\int_{u_0}^{v_0} f(x) dx = \frac{1}{4}$ we have
	$$ \Lambda(f) = \int_{0}^{u_0} (1-v_f(x)) dx + \int_{v_0}^1 u_f(x)dx- u_0 (1-v_0).$$
	\item In particular, we have the formulas $$\Lambda(f) = \int_{0}^1 (1-v_f(u))du = \int_{0}^1 u_f(v) dv.$$
	\item The map $\mathcal{F} \ni f \mapsto \Lambda(f) \in \mathbb{R}$ is continuous.
	\item If $f \in { \mathcal{F}_{\mathrm{mon}} }$, then the set $L(f)$ is convex.
	\end{enumerate}
\end{observation}	

\begin{proof}
	The integral formula for $\Lambda(f)$ follows from partitioning $L(f)$ into three parts: $ L_- = L(f) \cap \{ u < u_0,\ v< v_0 \}$, ${L}_+ = {L}(f) \cap \{ u > u_0,\ v > v_0 \}$ and ${L}_+ = {L}(f) \cap \{ u \leq u_0,\ v \leq v_0 \} = [0,u_0] \times [v_0,1]$.
	
	Continuity of $f \mapsto \Lambda(f)$ is clear once the previous points are established. It remains to prove continuity of $f \mapsto v_f$ (argument for $f \mapsto u_f$ is analogous).
	
	Take any $f,f_n \in \mathcal{F}$ with $f_n \to f$ in $L^1$. Fix $u$ and let $v = v_f(u)$. Let us suppose that $v < 1$, since the case $v = 1$ is easier. For any $\delta > 0$ we have
	$$
		\int_u^{v-\delta} f(x) dx + \frac{1}{4} \delta^2 < 
		\int_u^{v} f(x) dx = \frac{1}{4} < \int_u^{v+\delta} f(x) dx -  \frac{1}{4} \delta^2
	$$
	Thus, for $n > n_0(\delta)$ we have:	
	$$
		\int_u^{v-\delta} f_n(x) dx + \frac{1}{8} \delta^2 <   \frac{1}{4} < \int_u^{v+\delta} f_n(x) dx -  \frac{1}{8} \delta^2.
	$$
	Consequently, $v-\delta < v_{f_n}(u) < v + \delta$. Taking $\delta \to 0$ we conclude that $v_{f_n}(u) \to v$ as $n \to \infty$. Hence, $v_{f_n} \to v_f$ pointwise. Since all relevant functions are bounded, $v_{f_n} \to v_f$ in $L^1$.
	
	Finally, we prove convexity of $L(f)$. Suppose that $(u_1,v_1), (u_2,v_2) \in L(f)$ and $u = \frac{u_1+u_2}{2}, v= \frac{v_1+v_2}{2}$. We may without loss of generality assume that $u_1 < u_2 < \kappa_f < v_1 < v_2$, and that $\int_{u_1}^{v_1}f(x)dx = \int_{u_2}^{v_2}f(x)dx = \frac{1}{4}$. We then have 
	$$
		\int_{u_1}^{u_2}f(x)dx = \int_{v_1}^{v_2}f(x)dx =: I,
	$$
	and because of monotonicity $\int_{u_1}^{u}f(x)dx \leq \frac{1}{2} \leq \int_{u}^{u_2}f(x)dx$ and $\int_{v_1}^{v}f(x)dx \geq \frac{1}{2} \leq \int_{v}^{v_2}f(x)dx$. Hence,
	$$  \int_{u}^{v}f(x)dx =  \int_{u_1}^{v_1}f(x)dx -  \int_{u_1}^{u}f(x)dx +  \int_{v_1}^{v}f(x)dx \geq \frac{1}{4},$$
	and consequently $(u,v) \in L(f)$. Since $L(f)$ is closed, this proves convexity.
\end{proof}	


\begin{proof}[Proof of Proposition \ref{EXTup:prop:L(a)-bound} assuming Proposition \ref{EXTup:prop:L(f)-bound}]

	 For each $n$, let $a^{(n)}$ be a permutation of $[n]$ which maximizes $\abs{L(a^{(n)})}$.
	 We may assume without loss of generality that $a^{(n)}_i$ are increasing for $i=1,\dots,k^{(n)}$ and decreasing for $i = k^{(n)},\dots,n$. 
	
	To the permutation $a^{(n)}$ we may associate a function $f_n\colon[0,1] \to \mathbb{R}$ defined by
\begin{equation}
 	f_n\bra{\frac{i + t}{n}} = \frac{a_i^{(n)}}{n+1},\quad \text{ for } i \in [n],\ t \in [-1,0),
\end{equation} 	
(and for completeness, put $f(1) := \frac{a_n^{(n)}}{n+1}$). 
	 
	 We have the obvious bounds $0 \leq f_n(x) \leq 1$, as well as the formula $$\sum_{i=u+1}^{v} a_i^{(n)} = n(n+1) { \int_{u/n}^{v/n} f_n(x) dx}$$ for $u,v \in [n]$. In particular, $\int_0^1 f_n(x) dx = \frac{1}{2}$. It is not difficult to see that for any measurable $E$ with $\abs{E} = \frac{m + \mu}{n}$ with $m \in \mathbb{N}, \mu \in [0,1)$ we have 
	 $$\int_E f_n(x) dx \geq \frac{1 + 2 + \dots + m + (m+1)\mu }{n(n+1)} = \frac{(m+\mu)(m+1)}{2n(n+1)^2} \geq \frac{\abs{E}^2}{2},$$
where the last inequality can be checked with elementary methods. It is also clear from the construction that $f_n$ is monotonous on $[0,\frac{k}{n}]$ and on $[\frac{k-1}{n},1]$.

	Hence, $f_n \in { \mathcal{F}_{\mathrm{mon}} }$. By Proposition \ref{EXTup:prop:L(f)-bound}, $\Lambda(f_n) \leq \frac{\pi}{16}$. It remains to relate $\Lambda(f_n)$ to $\abs{L(a^{(n)})}$. For any $u,v$, if $(u,v) \in L(a^{(n)})$ then the square $[\frac{u}{n},\frac{u+1}{n}] \times [\frac{v}{n},\frac{v+1}{n}]$ is contained in ${L}(f_n)^c$, and conversely if $(u,v) \not\in L(a^{(n)})$ then square $[\frac{u+1}{n},\frac{u+2}{n}] \times [\frac{v-1}{n},\frac{v}{n}]$ is contained in ${L}(f_n)$. Together with the observation that $L(f)$ is convex,
	this shows that $\frac{\abs{L(a^{(n)})}}{n^2} - \Lambda(f_n) = O(\frac 1n)$.
	
	Thus, $\abs{L(a)} = (1+o(1)) \Lambda(f_n) n^2 \leq \frac{\pi}{16}n^2,$ which finishes the proof.
	
\end{proof}
	
	The rest of this section will be devoted to proving Proposition \ref{EXTup:prop:L(f)-bound}. Our first step in that direction is to show that the supremum $\sup_{g \in \mathcal{F}} \Lambda(g)$ is realised by some $f \in { \mathcal{F}_{\mathrm{mon}} }$, where it is convenient to allow $g$ to range over the larger family $\mathcal{F}$ to simplify perturbation arguments later.

	\begin{observation}

	There exists $f \in { \mathcal{F}_{\mathrm{mon}} }$ such that $\Lambda(f) = \sup_{g \in \mathcal{F}} \Lambda(g)$
\end{observation}
\begin{proof}
	For any $g \in \mathcal{F}$, there exists $\tilde g \in { \mathcal{F}_{\mathrm{mon}} }$ such that $\Lambda(\tilde g) \geq \Lambda(g)$. This follows from an argument essentially equivalent to the one in Observation \ref{EXTup:obs:perm-mono}.
	Hence, it will suffice to show that the supremum $\sup_{g \in { \mathcal{F}_{\mathrm{mon}} }} \Lambda(g)$ is realised by some $f$, which in turn will follow once we show that  ${ \mathcal{F}_{\mathrm{mon}} }$ is compact.

	Compactness of ${ \mathcal{F}_{\mathrm{mon}} }$ is direct consequence of the classical Helly's selection theorem, see e.g. \cite{Brunk-1956} for details.	 For a direct proof, consider any sequence $f_n \in { \mathcal{F}_{\mathrm{mon}} }$. Passing to a subsequence, we may assume that $f_n$ converges pointwise on $\mathbb{Q} \cap [0,1]$. By motonicity, $f_n$ converges pointwise a.e. to some function $f$. Thus, by the dominated convergence, $f_n$ converges in $L^1$. It is clear that $f \in { \mathcal{F}_{\mathrm{mon}} }$.
\end{proof}

Once we know that there is $f \in { \mathcal{F}_{\mathrm{mon}} }$ which maximises $\Lambda$, we may study such $f$ more closely. It comes as no surprise that the behaviour of $\Lambda(f)$ under small distortions is relevant.

\begin{lemma}\label{EXTup:lem:delta-Lambda}
	Let $f \in \mathcal{F}$, and suppose that $h \in L^\infty([0,1])$ is such that $f+\tau h \in \mathcal{F}$ for sufficiently small $\tau > 0$.
	 For $\tau > 0$, denote:
\begin{align}
	\Delta_\tau \Lambda(f) &:= \Lambda\bra{f+\tau h} - \Lambda\bra{f},\\
	\delta_h \Lambda(f) &:= \lim_{\tau \to 0} \frac{1}{\tau} \Delta_\tau \Lambda(f).
\end{align}

	We then have the formula:
	\begin{align*}
		\delta_h \Lambda(f) = \int_{0}^1 h(x) w(x) dx, \ \text{where } \ 
		w(x) := 
	\begin{cases} 
		\int_{0}^x \frac{du}{f(v(u))} & \text{ if } x \leq \kappa, \\
		\int_{x}^1 \frac{dv}{f(u(v))} & \text{ if } x \geq \kappa,
	\end{cases}
	\end{align*}	
	where $\kappa=\kappa_f$ is such that $\int_{0}^\kappa f(x) dx = \int_{\kappa}^1 f(x) dx = \frac{1}{4}$.
\end{lemma}

\begin{proof}
We may assume without loss of generality that $\norm{h}_\infty \leq 1$.
Following the convention suggested above, for $\tau > 0$ we denote:
\begin{align*}
	(\Delta_\tau u_f)(x) &:= u_{f+\tau h}(x) - u_{f}(x),\
	&(\Delta_\tau v_f)(x) &:= v_{f+\tau h}(x) - v_{f}(x),
	\\
	(\delta_h u_f)(x) &:= \lim_{\tau \to 0} \frac{1}{\tau} (\Delta_\tau u_f)(x), 	
	&(\delta_h v_f)(x) &:= \lim_{\tau \to 0} \frac{1}{\tau} (\Delta_\tau v_f)(x).
\end{align*}
Since $f$ is fixed, we will suppress dependence on $f$, writing $\Delta_\tau u$, $\Delta_\tau v$ and $\delta_h u$ and $\delta_h v$ whenever ambiguity does not arise.

We have a trivial estimate $\abs{\Delta_\tau v (u)} \leq 2 \sqrt{ \tau}$ for each $u$, which follows directly from the chain of inequalities
$$\tau  \norm{h}_{1} \geq \abs{
\int_{v(u)}^{v(u)+\Delta_\tau v(u)} (f-\tau h)(x) dx }
\geq \frac{(\Delta_\tau v(u))^2}{2} - \tau \norm{h}_{1}.
$$
(Here and elsewhere, we use the convention that $\int_a^b \equiv -\int_b^a$ if $a > b$).

In the same way, we have $\abs{\Delta_\tau u (v)} \leq 2 \sqrt{ \tau}$ for each $v$. 

Now, fix $\mu < \kappa$. If $\tau$ is small enough, then for $0 \leq u \leq \mu$ we have that $v(u) + \Delta_\tau v(u) < 1$. For $u < \mu$ we have, slightly more precisely than above:
\begin{align*}
	\frac{1}{2} &= \int_{u}^{v(u) + \Delta_\tau v(u)} (f + \tau h)(x) dx 
	\\ &=
	\frac{1}{2} + \tau \int_u^{v(u)} h(x) dx + 
	 \int_{v(u)}^{v(u) + \Delta_\tau v(u)} f(x) dx + O\bra{ \tau^{3/2}}.
\end{align*}
Hence
\begin{align*}
 \frac{1}{\Delta_\tau v(u)} \int_{v(u)}^{v(u) + \Delta_\tau v(u)} f(x) dx
 &= - \frac{\tau}{\Delta_\tau v(u)} \bra{
 \int_u^{v(u)} h(x) dx + O\bra{\sqrt{\tau}}
 }.
\end{align*}
	For a.e. $u$, the expression on the left hand side tends to $f(v(u))$ as $\tau \to 0$, by the Lebesgue density theorem. Hence, for a.e. $u$, $\delta_h v(u)$ is well defined and:
	\begin{align}
		\delta_h v(u) = \lim_{\tau \to 0}  \frac{\Delta_\tau v(u)}{\tau} = -\frac{\int_u^{v(u)} h(x) dx }{f(v(u))}. \label{EXTup:eq:54}
	\end{align}

By a symmetric argument, if we fix $\kappa < \nu \leq 1$ then for a.e. $v > \nu$ we have:
	\begin{align}
		\delta_h u(v) = \frac{\int_{u(v)}^{v} h(x) dx }{f(u(v))}. \label{EXTup:eq:55}
	\end{align}

Fix $0 < \mu < \kappa $ and put $\nu = v(\mu)$. Using Observation \ref{EXTup:obs:prelim} we have:
$$
	\Lambda(f) = \int_0^{\mu} (1-v(u)) du + \int_{\nu}^1 u(v) dv - \mu (1-\nu).
$$

Note that for any $\varepsilon > 0$ and any sufficiently small $\tau$ we have $\Delta_\tau u(v) \leq \frac{2\tau \norm{h}_1}{ f( \nu + \varepsilon)}$ for $u \leq \mu$, and hence $\frac{ \Delta_\tau v(u)}{\tau} $ is uniformly bounded. Likewise,  $\frac{ \Delta_\tau u(v)}{\tau} $ if uniformly bounded for $v \geq \nu$. We may now compute:
\begin{align*}
	\delta_h \Lambda(f) &= \lim_{\tau \to 0} \frac 1\tau \Delta_\tau \Lambda(f) 
	\\&= \lim_{\tau \to 0} 
	 \int_0^{\mu} - \frac{ \Delta_\tau v(u)}{\tau} du + \int_{\nu}^1 \frac{ \Delta_\tau u(v)}{\tau} dv + \mu \frac{ \Delta_\tau v(\mu) }{\tau} + O(\tau)
	\\&= -\int_0^{\mu} \delta_h v(u) du + \int_{\nu}^1 \delta_h u(v) dv + \mu \delta_h  v(\mu)


\end{align*}
where the last equality uses the dominated convergence theorem. Note that this holds for any $0 < \mu < \kappa$. Passing to the limit $\mu \to 0$ or $\mu \to \kappa$ we find simpler expressions:
\begin{align}
	\delta_h \Lambda(f) 
	&= -\int_0^{\kappa} \delta_h v(u) du = \int_{\kappa}^1 \delta_h u(v) dv  \label{EXTup:eq:56}
\end{align}

Inserting \eqref{EXTup:eq:54} into the first equation of \eqref{EXTup:eq:56} and exchanging the order of integration, we now find:
\begin{align*}
	\delta_h \Lambda(f) &= \int_0^\kappa \frac{\int_u^{v(u)} h(x) dx }{f(v(u))} du
	= \int_{0}^{1} h(x) \int_{u(x)}^{\min(x,\kappa)} \frac{du}{f(v(u))}dx.
\end{align*}
	Let $w(x)$ denote the value of the inner integral $\int_{u(x)}^x \frac{du}{f(v(u))}$. If $x \leq \kappa$ then $u(x) = 0$ so we obtain the sought formula $w(x) = \int_{0}^x \frac{du}{f(v(u))}$. Else, the formula follows from a change of variables $v = v( u)$ together with the observation that $\frac{dv}{du} = \frac{f(u)}{f(v)}$.


\end{proof}

	Using standard techniques, we can extract from the above Lemma strong structural information about the function $f$ minimising $\Lambda$. The proof is complicated by the fact that we need to account for a variety of pathological behaviour that $f$ may potentially exhibit. However, the key idea is simply to relate to each undesirable behaviour of $f$ a perturbation which increases $\Lambda(f)$.

\newcommand{\operatorname{sgn}}{\operatorname{sgn}}
	For $t \in \mathbb{R}$, we let $\operatorname{sgn} t$ denote the sign of $t$, with the convention that $\operatorname{sgn} t = +1$ for $t > 0$, $\operatorname{sgn} t = -1$ for $t < 0$ and $\operatorname{sgn} 0 = 0$. In particular, $f$ is continuous.

\begin{lemma}\label{EXTup:lem:constraints}
	Suppose that $f \in { \mathcal{F}_{\mathrm{mon}} }$ is such that $\Lambda(f) = \sup_{g \in \mathcal{F}} \Lambda(g)$, and let $x, y \in [0,1]$. Then:
	\begin{enumerate}
		\item\label{EXTup:cond:11mono@lem:cons} For each $x,y$ we have $\operatorname{sgn}( f(x) - f(y) ) = \operatorname{sgn} ( w(x) - w(y) )$.
		\item\label{EXTup:cond:12cont@lem:cons} The function $f$ is continuous (except perhaps at $\kappa_f$).
		\item\label{EXTup:cond:13meas@lem:cons} For each $E \subset [0,1]$, measurable, we have $\abs{f^{-1}(E)} = \abs{E}$.
	\end{enumerate}	 
\end{lemma}
\begin{proof}

	We separate the proof into several steps.
	
	\textit{Step 1.} If $f(x) > f(y)$ then $w(x) \geq w(y)$.
	
	Suppose otherwise, so that $w(x) < w(y)$. Since $w$ is continuous, there is some $\varepsilon > 0$ such that $w(x') < w(y')$ when $\abs{x'-x}, \abs{y'-y} < \varepsilon$. Suppose for concreteness that $x < \kappa_f < y$ (the remaining cases being fully analogous), so that $f$ is increasing in a neighbourhood of $x$ and decreasing in a neighbourhood of $y$.
	
	We wish to consider a function $\tilde f$ obtained by ``swapping'' the intervals $[x,x+\varepsilon]$ and $[y-\varepsilon,y]$. Hence, we define 
	\begin{align*}
		\tilde f(x + t) &= f(y-\varepsilon + t) & t \in [0,\varepsilon]& \\
		\tilde f(y-\varepsilon + t) &= f(x + t)  &t \in [0,\varepsilon]& \\
		\tilde f(x) &= f(x) \qquad & x \not \in [x,x+\varepsilon] \cup [y-\varepsilon,y]& 
	\end{align*}
	
	It is clear that $\tilde f \in \mathcal{F}$, since membership in $\mathcal{F}$ is ``invariant under rearrangement'', in the sense that the condition $g \in \mathcal{F}$ can be phrased purely in terms of the values $\abs{g^{-1}(E)}$ for $E \subset [0,1]$, measurable.
	
	Put $h = \tilde f - f$, so that $f + \tau h \in \mathcal{F}$ for $t \in [0,1]$ because of convexity. Using Lemma \ref{EXTup:lem:delta-Lambda} (and the notation therein) we have:
	\begin{align*}
	\delta_h \Lambda(f) &= \int_0^1 h(z)w(z) dz
	\\&= \int_0^\varepsilon (w(x + t) - w(y-\varepsilon+t)) ( f(y-\varepsilon+t) - f(x+t)) dt > 0.
	\end{align*}
	Hence, for sufficiently small $\tau$ we conclude that $\Lambda( f + \tau h) > \Lambda(f)$, contradicting the choice of $f$.
	
	\textit{Step 2.} There is no interval where $f$ is constant.
	
	Suppose otherwise, so that there exists some $t_0$ with $U := f^{-1}(\{t_0\})$ with positive measure. Then, we claim that for any test function $h$ such that $\operatorname{supp} h \subset U$, $\norm{h}_{\infty} \leq 1$, $\int_0^1 h(x) dx = 0 $, and for sufficiently small $\tau > 0$ we have $f + \tau h \in \mathcal{F}$. (Recall that $\operatorname{supp} h = \{ x \ : \ h(x) \neq 0 \}$.) The fact that $U$ will generally consist of two disjoint intervals contained in $[0,\kappa_f]$ and $[\kappa_f,1]$ respectively complicates the notation slightly. Instead, we argue a slightly simpler statement, and leave it to the interested reader to work out the details.
	
	\textit{Claim.} Pick two points $0 \leq x_0 < x_1 \leq 1$. Let $G(x) = \frac{x^2}{2}$ and let $F(x) = \frac{x_0+x_1}{2} x - \frac{x_0x_1}{2}$ (so that $F(x) = G(x)$ for $x = x_0,x_1$). Also, fix a differentialbe function $H$ with $\operatorname{supp} H \subset [x_0,x_1]$ and $\norm{H'}_{\infty} \leq 1$. Then, for sufficiently small $\tau$, for any $x \in [x_0,x_1]$ we have $F(x) + \tau H(x) \geq G(x)$.  
	
	\textit{Proof of Claim.} Taking $\tau$ sufficiently small, we may ensure that $F'(x) + \tau H'(x) > G'(x)$ for $x_0 \leq x \leq x_0 + \frac{x_1-x_0}{10}$ and  $F'(x) + \tau H'(x) < G'(x)$ for $ \leq x_1 - \frac{x_1-x_0}{10} \leq x \leq x_1$. Hence $F(x) + \tau H(x) \geq G(x)$ when $x$ is within $ \frac{x_1-x_0}{10} $ of $x_0,x_1$. Since $F(x) - G(x)$ is bounded away from $0$ on for $x_0 + \frac{x_1-x_0}{10} \leq x \leq  x_1 - \frac{x_1-x_0}{10}$ we can ensure $F(x) + \tau H(x) \geq G(x)$ for such $x$ by choosing sufficiently small $\tau$. 
	
	We are now ready to derive a contradiction. Since for any fixed $h$ as above we have $f \pm \tau h \in \mathcal{F}$, we conclude that $\delta_h \Lambda(f) = 0$. Hence, by Lemma \ref{EXTup:lem:delta-Lambda} we have $\int_U h(z)w(z) dz = 0$. However, this is only possible if $w$ is not constant on $U$, which it clearly is not. Thus, $f$ is not constant on any interval.
	  	
\textit{Step 3.} For any $t > 0$, we have $\inf_{\abs{E}=t} \int_{E} f(x) dx = \frac{t^2}{2}$.
				
	 Once this equality is proved, the condition \eqref{EXTup:cond:13meas@lem:cons} follows. (Both are easily seen to be equivalent to the statement that the increasing rearrangement of $f$ is the map $\tilde f(x) = x$.)
	 
	 Note that inequality in one direction follows directly from the fact that $f \in \mathcal{F}$. We just need to prove $\inf_{\abs{E}=t} \int_{E} f(x) dx \leq \frac{t^2}{2}$. 
	 
 	Suppose for the sake of contradiction that for some $t_0$ we have strict inequality $\int_{E_0} f(x) dx > \frac{1}{2}t_0^2$ where $E_0$ is chosen so that $\abs{E_0} = t_0$ and the integral is minimised. From monotonicity of $f$ it follows that $E_0$ takes the form $E_0 = [0,x_0] \cup [y_0,1]$ for some $0 \leq x_0 \leq \kappa_f \leq y_0 \leq 1$, and because $f$ is nowhere constant, the choice of $x_0,y_0$ is unique.
 	
 	Let $t_1 > t_0$ be such that $\int_{E_0} f(x) dx = \frac{1}{2}t_1^2$, and let $E_1 = [0,x_1] \cup [y_1,1]$ with $\abs{E_1} = t_1$ minimise $\int_{E_1} f(x) dx$. Take $F = E_1 \setminus E_0 = [x_0,x_1] \cup [y_1, y_0]$, and take a set $U$ such that $\operatorname{cl} U \subset \operatorname{int} F$ and $\abs{U} > 0$. Since for any $x \in U$ and $x' \in E_0$ we have $f(x) > f(x')$, it is not difficult to show that for any $h$ with $\operatorname{supp} h \subset U$, $\norm{h}_\infty \leq 1$, $\int_0^1 h(x)dx = 0$, for sufficiently small $\tau$ we have $f + \tau h \in \mathcal{F}$.
 	
 	By the same argument as in Step 2., this means that $\int_0^1 h(x) w(x)dx = 0$. Since $w$ is non-constant and $h$ is arbitrary, this is the sought contradiction.
 	
\textit{Step 4.} The function $f$ is continuous (expect possibly at $\kappa_f$).
	
	Note that the only way $f$ could be discontinuous is if it had a jump discontinuity at some point $x$. Suppose that this is the case, and assume for concreteness that $x < \kappa_f$ so that $f$ is increasing at $x$. Since by Step 3., the image of $f$ is dense in $[0, 1]$, we may find some $y$ where $f$ is continuous such that $\lim_{z \to x-} f(z) < f(y) < \lim_{z \to x+} f(z)$. Assumption that $x < \kappa_f$ forces $y > \kappa_f$, so for $y' < y$, sufficiently close, we have $w(y') > w(y)$. Hence, using Step 1. we have $w(x) \leq w(y) < w(y') \leq w(x)$, which is a contradiction.
	
\textit{Step 5.} If $f(x) = f(y)$ then $w(x) = w(y)$.

Assume for concreteness that $x < \kappa_f$. Using Steps 1. and 2. we have $w(x) = \lim_{z \to x} w(z) \leq w(y)$, and symmetrically $w(x) \geq w(y)$.

Steps 5. and 1. together imply condition \eqref{EXTup:cond:11mono@lem:cons}, hence the proof is complete.

\end{proof}

	Note that modifying a function $f \in \mathcal{F}$ at a single point does not affect $\Lambda(f)$. Hence, the above Lemma \ref{EXTup:lem:constraints} implies in particular that $\Lambda$ is maximised by a continuous, nowhere constant function $f \in { \mathcal{F}_{\mathrm{mon}} }$.

	For continuous $f \in { \mathcal{F}_{\mathrm{mon}} }$ which are not constant on any interval, we introduce local inverse functions $\alpha_f \colon [0,1] \to [0,\kappa_f]$ and $\beta_f\colon [0,1] \to [\kappa_f,1]$ so that 
	$$f(\a_f(t)) = f(\b_f(t)) = t.$$
	Whenever possible, we will suppress dependence on $f$, writing simply $\a$ and $\b$. We have the following, somewhat unexpected, relation.
\newcommand{\tilde}{\tilde}

\begin{lemma}\label{EXTup:obs:at+bt=cons}
	Suppose that $f \in { \mathcal{F}_{\mathrm{mon}} }$ is such that $\Lambda(f) = \sup_{g \in \mathcal{F}} \Lambda(g)$ and that $f$ is continuous. Then, for any $t \in [0,1]$ we have $v \circ \a(t) + u \circ \b(t) = 1$. In particular, $\kappa = \frac{1}{2}$.
	
\end{lemma}
\begin{proof}
	The claim is clearly true for $t = 1$, and the value of $\kappa$ follows from the remaining part of the statement by taking $t = 0$.
	
	It is a direct consequence of Lemma \ref{EXTup:lem:constraints} that $\a$ and $\b$ are Lipschitz continuous, with Lipschitz constant at most $1$. Moreover, $u$ and $v$ are Lipschitz continuous on $[0,1] \setminus (\k - \varepsilon,\k+\varepsilon)$ for any $\varepsilon > 0$ (with the Lipschitz constant dependent on $\varepsilon$). Thus, $v \circ \a + u \circ \b$ is Lipschitz continuous on $[0,1 -\varepsilon]$ for any $\varepsilon$. In particular, $v \circ \a + u \circ \b$ is absolutely continuous on $[0,1 -\varepsilon]$, and to prove that it is constant it will suffice to show that $(v \circ \a + u \circ \b)'(t)=0$ for almost all $t$. Passing to the limit $\varepsilon \to 0$ will then complete the proof.

	A simple computation yields:
	\begin{equation}
		(u \circ \b)'(t) = \b'(t) \frac{ f \circ \b(t) }{f \circ u \circ \b(t)} = \frac{t \b'(t) }{f \circ u \circ \b(t)}, \qquad
		(v \circ \a)'(t) = - \frac{t \a'(t) }{f\circ v \circ \a(t)} \label{EXTup:eq:43-a}
	\end{equation}
	almost everywhere (where $\a'(t)$ and $\b'(t)$ are defined).	
	
	Another application of Lemma \ref{EXTup:lem:constraints} implies that $w(\a(t)) = w(\b(t))$ (with $w$ defined as in Lemma \ref{EXTup:lem:delta-Lambda}). Differentiating this equality, we conclude that:
	\begin{equation}
		\frac{\b'(t)}{f \circ u \circ \b(t)} = \frac{\a'(t)}{f\circ v \circ \a(t)} = 0.
	\label{EXTup:eq:43-b}
	\end{equation}

	Combining \eqref{EXTup:eq:43-a} and \eqref{EXTup:eq:43-b} we conclude that indeed $(v \circ \a + u \circ \b)'(t)=0$ a.e., which finishes the proof.

\end{proof}

	We are now ready to prove the final bit of information we need about the function maximising $\Lambda$, namely the symmetry.
	
\begin{observation}\label{EXTup:obs:symmetry}
	Suppose that $f \in { \mathcal{F}_{\mathrm{mon}} }$, continuous, is such that $\Lambda(f) = \sup_{g \in \mathcal{F}} \Lambda(g)$. 

	Then any $s, t \in [0,1]$, if $\a(s) = {u \circ \b}(t)$ then also $\a(t) = {u \circ \b}(s)$. In particular, the function $f$ is symmetric: $f(x) = f(1-x)$ for all $x$. 
\end{observation}
\begin{proof}
		
	We begin by proving the symmetry of $f$, assuming the former part of the claim. It will be enough to show that for any $t$, $\a(t) + \b(t) = 1$. Take any $t$, and let $s$ be such that $\a(s) = {u \circ \b}(t)$. By assumption, $\a(t) = {u \circ \b}(s)$. We have ${v \circ \a}(s) = v \circ u \circ \b(t) = \b(t)$. Hence, $\a(t) + \b(t) = {u \circ \b}(s) + {v \circ \a}(s) = 1$.
	
	For the remaining part of the argument, it will be convenient to define a pair of transformations $T_\a$ and $T_\b$ on $[0,1]$ given by $T_\a = f \circ {u \circ \b}$ and $T_\b = f \circ {v \circ \a}$. We note several properties of these transformations.
	\begin{enumerate}
	\item\label{EXTup:cond:T1} $T_\a \circ T_\b (t) = t$ and $T_\b \circ T_\a (t) = t$  for any $t$;
	\item\label{EXTup:cond:T2} $\a(T_\a(t)) = {u \circ \b}(t)$ and $\b(t) = {v \circ \a}(T_\a(t))$  for any $t$;
	\item\label{EXTup:cond:T3} $\abs{ \a(T_\a^2(t)) - \a(T_\a^2(t')) } = \abs{ \b(t) - \b(t')}$  for any $t,t'$;
	\item\label{EXTup:cond:T4} $T_\a(t) > T_\a(t')$ and $T_\b(t) > T_\b(t')$ for any $t < t'$.
	\end{enumerate}
	Assertions \eqref{EXTup:cond:T1} and \eqref{EXTup:cond:T2} follow directly by substitution. For example, we have:
	$$
		T_\a \circ T_\b (t) = f \circ {u \circ \b} \circ f \circ {v \circ \a}(t)
		=  f \circ {u} \circ {v \circ \a}(t) =   f \circ{ \a} (t) = t,
	$$
	where we use that $u \circ v(x) = x$ and $\beta \circ f(x) = x$ in appropriate ranges of $x$. The remaining equalities follow along similar lines.
	
	Assertion \eqref{EXTup:cond:T4} follows from known monotonicity properties of $f$, $\a, \b$ and $u, v$. For instance, if $t < t'$ then $\b(t) > \b(t')$, hence $u \circ \beta(t) > u \circ \beta(t')$ and $f\circ u \circ \beta(t) > f \circ u \circ \beta(t')$ (note that $f$ is increasing in the relevant range).
	
	Assertion \eqref{EXTup:cond:T3} is the least obvious and the most crucial. Using Observation \ref{EXTup:obs:at+bt=cons} and previously established properties of $T_\a$ we have:
	\begin{align*}
	\abs{ \a(T_\a^2(t)) - \a(T_\a^2(t')) } &=
	\abs{ u \circ \b (T_\a(t)) - u \circ \b (T_\a(t')) } 
	\\ &= \abs{ v \circ \a (T_\a(t)) - v \circ \a (T_\a(t')) }
	 =  \abs{ \b (t) - \b(t') }.
	\end{align*}	
	
	Our main claim is equivalent to the statement that for each $t$, $T_\a^2(t) = t$, where we may restrict our attention to $t$ with $T_\a(t) < t$. For the sake of contradiction, suppose that for some $t_0$ we have $T_\a^2(t_0) \neq t_0$. For concreteness, we may suppose that $T_\a^2(t_0) > t_0$, the other case being fully analogous. 
	
	Let us consider the consecutive iterates $t_n := T_\a^n(t_0)$ for $n \in \mathbb{Z}$ (for $n < 0$ we use $T_\beta = T_\a^{-1}$). By \eqref{EXTup:cond:T4}, it is clear that $t_{2n}$ is monotonously increasing, while $t_{2n+1}$ is monotonously decreasing. Moreover, we may define:
	\begin{align*}
		I_n &:= { \int_{\a(t_n)}^{\a(t_{n+2})} f(x) dx } = { \int_{\b(t_{n-1})}^{\b(t_{n+1})} f(x) dx }\\
	\end{align*}
where the two integrals are equal because by \eqref{EXTup:cond:T2} we have
\begin{align*}
	0 &= \int_{\a(t_n)}^{v\circ \a(t_n)}f(x)dx - \int_{\a(t_{n+2})}^{v\circ \a(t_{n+2})} f(x)dx 
	\\&=  \int_{\a(t_n)}^{\a(t_{n+2})}f(x)dx - \int_{\b(t_{n-1})}^{\b(t_{n+1})}f(x)dx.
\end{align*}

In similar spirit, we may define
	\begin{align*}
		l_n &:= {\a(t_{n+2}) - \a(t_{n}) } =  {\b(t_{n-2}) - \b(t_{n}) }
	\end{align*}
where the two quantities are equal by a direct application of \eqref{EXTup:cond:T3}.

	Using monotonicity of $f$ and $t_n$, we find that for any $n \in \mathbb{Z}$ we have 
	\begin{align*}
	l_{2n} t_{2n+2}  &\geq I_{2n} \geq l_{2n} t_{2n},
	&l_{2n+1} t_{2n+3}  &\leq I_{2n+1} \leq l_{2n+1} t_{2n+1}, \\
	l_{2n+1} t_{2n-1}  &\geq I_{2n} \geq l_{2n+1} t_{2n+1},
	&l_{2n+2} t_{2n}  &\leq I_{2n+2} \leq l_{2n+2} t_{2n+2} .
	\end{align*}
	
	Combining the above inequalities, we find
	$$
		\frac{l_{2n}}{l_{2n+2}} 
		= \frac{l_{2n}}{l_{2n+1}} \cdot \frac{l_{2n+1}}{l_{2n+2}}
		\geq \frac{t_{2n+1}}{t_{2n+2}} 
			\cdot \frac{t_{2n}}{t_{2n+1}}
		= \frac{t_{2n}}{t_{2n+2}}.
	$$	
	
	Taking the product as $n$ ranges over $-N+1,\dots,0$ and letting $N \to \infty$ we conclude that 
	$$\liminf_{N\to \infty}  l_{-2N} \geq  \frac{ l_0}{t_0} \lim_{N\to \infty}  t_{-2N}. $$
	The limit on the right hand side is defined, because the sequence $t_{-2N}$ is decreasing. 

	We claim that $\lim_{N\to \infty}  t_{-2N} > 0$. Clearly, we have $T_\a(t_0) = t_1 < t_0$ and $T_\a(t_1) = t_2 > t_1$. Thus, there is some $t_1 < t_* < t_0$ such that $T_\a(t_*) = t_*$. By monotonicity of $T_\a$ we have that for any $t$ that $t > t_*$ if and only if $T_\a(t) < t_*$, which is further equivalent to $T_\a^2(t) > t_*$. Hence, $t_{2n} > t_*$ for all $n \in \mathbb{Z}$, and in particular $\lim_{N\to \infty}  t_{-2N} \geq t_* > 0$.
	
	It follows that $l_{-2N}$ converges to a non-zero limit as $N \to \infty$. On the other hand, by construction of $l_n$, the interval $[0,1]$ contains a disjoint union of intervals with lengths $l_n$, $n \in \mathbb{Z}$. In particular, $\sum_{n \in \mathbb{Z}} l_n < \infty$, contradicting the above statement.
\end{proof}

\begin{corollary}
	The unique (up to a.e. equality) function $f \in { \mathcal{F}_{\mathrm{mon}} }$ maximising $\Lambda$ is given by:
	$$
		f(x) = 
		\begin{cases}
			2x &  \text{ if } x \leq \frac{1}{2}\\
			2(1-x) &  \text{ if } x \geq \frac{1}{2}.
		\end{cases}
	$$
\end{corollary}

We are now in position to finish the proof of Proposition \ref{EXTup:prop:L(f)-bound}. Let $f$ be the function defined above. The region ${L}(f)$ can be described explicitly: 
$${L}(f) = \bbra{ (x, y) \in [0,1]^2 \ : \ x \leq y, \ x^2 + (1-y)^2 \leq \frac{1}{4} }.$$ 
This gives $\Lambda(f) = \frac{\pi}{16}$, which is precisely the needed bound.

\section{Closing remarks}\label{section:END}

In the previous sections, we have obtained a fairly satisfactory understanding the $\abs{S(a)}$ in for a random permutation, as well as in the ``best case scenario'' where $a$ is chosen to maximize $\abs{S(a)}$. It is natural to ask about the behaviour of $\abs{S(a)}$ in the ``worst case scenario'', when $a$ is chosen to minimize $\abs{S(a)}$. We now address this problem, but we ask more questions than we answer.

The best lower bound we are aware of can be obtained by an argument in \cite{Solymosi-2005} (also present in \cite{Balog-2014}), a variant of which we sketch below for the convenience of the reader.


\begin{proposition}
	For any permutation $a$ of $[n]$ we have $\abs{S(a)} \geq \frac{n^{3/2}}{4\sqrt{2}}$.
\end{proposition}

\begin{proof}
	For any integer $k$, consider the set $S_k(a)$ of the sums $s \in S(a)$ with $kn+1 \leq s \leq (k+1)n$. Clearly, $S(a) = \bigcup_{k \geq 0} S_k(a)$, and the union is disjoint.
	
	Take any $1 \leq k \leq \frac{n+1}{4}$. For any $u$, at least one of the sums $\sum_{i=u}^n a_i$ or $\sum_{i=1}^u a_i$ exceeds $ \frac{1}{2} \binom{n+1}{2} \geq k n $. For concreteness, suppose $\sum_{i=u}^n a_i > kn$ and let $v$ be the smallest integer such that $\sum_{i=u}^v a_i > k n$. 
	
	By the choice of $v$ we have $\sum_{i=u}^v a_i  \in S_{k-1}(a)$ and $\sum_{i=u+1}^v a_i  \in S_{k}(a)\cup S_{k-1}(a)$. Hence, $a_u \in S_k(a) - (S_k(a) \cup S_{k-1}(a))$. Since $u$ was chosen arbitrarily, we conclude that 
	$ S_k(a) - (S_k(a) \cup S_{k-1}(a)) \supset [n],$
	which implies that $$\abs{S_k(a)} + \abs{S_{k-1}(a)} \geq \sqrt{2n}.$$
	
	Summing over $1 \leq k \leq \frac{n+1}{4}$ and using $\abs{S_0(a)} = n \geq \sqrt{2n} $ we conclude that:
	$$\abs{S(a)} \geq \frac{1}{2} \sum_{k=0}^{\floor{\frac{n+1}4}} (\abs{S_k(a)} + \abs{S_{k-1}(a)})  \geq \frac{1}{2} \floor{\frac{n+5}{4}} \sqrt{2n} \geq \frac{n^{3/2}}{4\sqrt{2}}.$$
\end{proof}

This bound is rather far from what one would expect. The trivial permutation $a_i = i$ is essentially the only known example with $\abs{S(a)} = o(n^2)$. In this case, we have $\abs{S(a)} \sim n^{2-o(1)} $.

Slightly more generally, we have a similar result for permutations of ``bounded complexity''. Because the result is rather standard, we only sketch the argument.

\begin{example}\label{LOW:prop:small-S}
	Fix an integer $M$. Let $a$ be a permutation of $[n]$ of complexity at most $M$, by which we mean that there is a partition $[n] = \bigcup_{j=1}^{M} I_j$ into intervals such that for each $j \in [M]$, $i \in I_j$ we have $a_i = i b_j + c_j$, where $b_j,c_j$ are some constants and $\abs{b_j} \leq M$.
	
	Then $\abs{S(a)} = o(n^2)$ but for any $\delta > 0$ also $\abs{S(a)} = \Omega(n^{2-\delta})$ (the implicit rates of convergence are allowed to depend on $M$ and $\delta$).
\end{example}
\begin{proof}[Sketch of the proof]
	For the lower bound, it is enough to observe that one of the intervals $I_j$ has large length $\abs{I_j} \geq n/M$. For $u,v \in I_j$, $S(a)$ contains the sum
	$$  s = \sum_{i=u}^{v} a_i = (v-u+1)\bra{c_j + \frac{u+v}2 b_j}.$$ 
	There are at least $\binom{n/M}2$ choices of $u,v$, and each sum $s$ is represented in at most $d(s) \ll n^{\delta}$ possible ways. Hence, $\abs{S(a)} = \Omega(n^{2-\delta})$.
	
	For the upper bound, it suffices to show that for any $j,k \in [M]$ the number of sums $\sum_{i=u}^v a_i$ with $u \in I_j,\ v \in I_k$ is $o(n^2)$. If we fix $j,k$, and let  $u \in I_j,\ v \in I_k$ then
	 $$\sum_{i=u}^v a_i = Av^2 + Bu^2 + C x + D y + E,$$
where $A = \frac{b_k}{2}$, $B =  - \frac{b_j}{2}$. Hence, the problem reduces to showing that for the polynomial $P(u,v) = Av^2 + Bu^2 + C x + D y + E$ we have
$$
	\abs{\bbra{ P(u,v) \ : \ u,v \in [n] }} = o(n^2).
$$
It is not difficult to reduce to the case $C = D = E = 0$ and $\gcd(A,B) = 1$. There are not two cases to consider.

\textit{Case 1.} Suppose that $-AB$ is a square. Then $P(u,v)$ factors as $(A'u + B'v)(A'u -B'u)$ and the bound follows from the theorem of Erd\H{o}s cited in the introduction.

\textit{Case 2.} Suppose that $-AB$ is not a square. Then, by Chebotarev's density theorem, there is a family $\mathcal{P}$ of primes $p$ with positive relative density such that $-AB$ is not a square modulo $p$. For any $p \in \mathcal{P}$ we then have $$P(u,v) \not \equiv p,2p,\dots,(p-1) p \pmod{p^2},$$
and thus 
\begin{align*} \lim_{n \to \infty} \frac{ \abs{\bbra{ P(u,v) \ : \ u,v \in [n] }} }{ n^2 } \ll
 \prod_{\substack{ p \in \mathcal{P}}} \bra{1-\frac{p-1}{p^2}} = 0. & \qedhere
\end{align*}
\end{proof}

In the above example, we could equally well allow the ``complexity'' tend to $\infty$ with $n$, but do so sufficiently slowly.



Hence, both for random and highly structured permutations $a$, we have $\abs{S(a)} \sim n^{2-o(1)}$. In absence of plausible counterexamples, we pose the following question.

\begin{question}
	Is it the case that for any $\delta > 0$, there exists a constant $c_\delta > 0$ such that for any $n$, and for any permutation $a$ of $[n]$ one has $\abs{S(a)} \geq c_\delta n^{2-\delta}$?
\end{question}

In fact, all examples with $\abs{S(a)} = o(n^2)$ we are aware of exhibit some algebraic structure, much as in Proposition \ref{LOW:prop:small-S}. It is not quite the case that $\abs{S(a)}$ is minimised for the trivial permutation, but none of the known examples seems to be significantly worse. Hence, we may ask more boldly:

\begin{question}
	Does there exists an absolute constant $c$ such that for any $n$, and for any permutation $a$ of $[n]$ one has $\abs{S(a)} \geq c \abs{S(\mathrm{id}_n)}$?
	
	(Here, $\mathrm{id}_n$ denotes the trivial permutation on $[n]$).
\end{question}

In similar spirit, we may also ask if the only way for $S(a)$ to be small is if $a$ has some algebraic structure. To give an indication of just how much structure one may hope to find, we give the following examples.

\begin{example}
	Fix a constant $M$, and suppose that $M \mid n$. Consider the permutation 
	$$a = (1,\frac{n}{M}+1,\dots,(M-1)\frac{n}{M}+1, 2,\frac{n}{M}+2,\dots,(M-1)\frac{n}{M}+2,3,\dots),$$ that is $a_i = \ceil{\frac{i}{M}} + \frac{n}{M} (i-1 \mod M)$. Then $\abs{S(a)} = o(n^2)$ (where the decay rate may depend on $M$). 
	
\end{example}

Note, however, that a similar looking permutation of Proposition \ref{I:prop:cexple-basic} has $\Theta(n^2)$ sums.

\begin{example}
	Take any permutation $a$ with $\abs{S(a)} = o(n^2)$, and let $m = o(n)$. Consider a permutation $b$ obtained from $a$ by choosing $m$ pairs of consecutive indices $i,i+1$ and swapping $a_i$ with $a_{i+1}$. More precisely, pick a set $I$ with $\abs{I} = m$ and such that $i \in I$ implies $i+1 \not \in I$, and define:
$$
	b_i = 
	\begin{cases}
		a_{i+1} & \text{ if } i \in I,\\
		a_{i-1} & \text{ if } i+1 \in I,\\
		a_{i} & \text{ otherwise}.\\		
	\end{cases}
$$
Then $\abs{S(b)} = o(n^2)$.
\end{example}

In view of the above examples, one cannot hope to ensure that $a_i$ looks structured on any large structured piece of $[n]$, nor that it looks structured on an long interval. We can, however, hope that the following should have a positive answer.
 
\begin{question}
	Does there exists $\varepsilon > 0$ such that the following is true?
	
	Let $a$ be a permutation of $[n]$ with $\abs{S(a)} \leq \varepsilon n^2$. Then there exists an index set $I \subset [n]$ with $\abs{I} = \omega(1)$ as $n \to \infty$ and constants $b,c$ such that for $i \in I$ we have $a_i = b i + c$.
\end{question}


One may also ask a similar questions in a more general context. Let $a$ be a permutation of a set $A \subset \mathbb{N}$ of size $\abs{A} = n$, not necessarily equal to $[n]$. Let $S(a)$ be defined just as before, to be the set $\bbra{ \sum_{i=u}^v a_i \ : \ u,v \in [n]}$. How small can $\abs{S(a)}$ be?

It is perhaps more natural to phrase this question in different terms. For a set $B = \{b_i \ : \ i \in [m] \}$ with $b_1 < b_2 < \dots < b_m$, define (following the terminology of \cite{Solymosi-2005} and \cite{Balog-2014}) the set of gaps $D(B) = \{ b_{i+1} - b_{i} \ : \ i \in [m-1]\}$. Note that setting $B = \{ \sum_{i=1}^{v} a_i \ : \ v \in [n] \} \cup \{0\}$ we recover $S(a) = (B-B) \cap \mathbb{N}$ and $D(B) = \{a_i \ : \ i \in [n] \} = A$. 

\begin{question}
	Suppose that $B \subset \mathbb{N}$ with $\abs{B} = n$ is such that $\abs{D(B)} = n-1$. For which $\delta > 0$ does there exist $c_\delta > 0$ (independent of $B$) such that $\abs{B-B} \geq c_\delta n^{2-\delta}$?
\end{question}

This question is already alluded to in \cite{Solymosi-2005}, and resolved positively in the case $\delta  = \frac{1}{2}$. For $\delta \in (0,\frac{1}{2})$ to the best of our knowledge, the answer is not known. 





\nocite{Alon-Spencer,Rudin}
\bibliographystyle{plain}

2015-05-21T02:00:46.000
1504
1504.07156
en
https://arxiv.org/abs/1504.07156
We study the number of values taken by the sums $\sum_{i=u}^{v-1} a_i$, where $a_1,a_2,\dots,a_n$ is a permutation of $1,2,\dots,n$ and $1 \leq u < v \leq n+1$. In particular, we show that for a random choice of a permutation, with high probability there are $(\frac{1+e^{-2}}{4} +o(1)) n^2$ such sums. This answers an old question of Erdős and Harzheim. We also obtain non-trivial bounds on the maximum possible number of distinct sums, ranging over all permutations of $1,2,\dots,n$. We close with some questions concerning the minimal possible number of distinct sums.
Combinatorics (math.CO); Number Theory (math.NT)
On consecutive sums in permutations
Qwen/Qwen-72B
1. YES
2. YES