How many contiguous sub-arrays can be formed from an array? I would like to learn the mathematical solution to finding the number of different contiguous subsets  that can be formed from an array.
For example, I understand the number of subsets (in general) possible from an array A={1...n} is 2^n.
But if only contiguous subsets were allowed from the array, how many different subsets can we form?
For example, A= {9,2,3,4}
Few contiguous subsets are : {9}, {9,2}, {9,2,3}, {2,3}
 A: If 
$$
S = \left\{a_1, \ldots , a_n \right\}
$$
for $1 \leq i \leq j \leq n$ we define
$$
S_{i,j} = \left\{a_i,a_{i+1},\ldots a_{j - 1}, a_j \right\}
$$
note that $|S_{i,j}| = j - i + 1$. For $1 \leq k \leq n$ we have
$$
S_{i,i+k-1} = \left\{a_i, \ldots, a_{i + k - 1}\right\}
$$
we have the bound $i \leq n - k + 1$, each set $S_{i,j}$ contains contiguous elements so I'd say
$$
N = \sum_{k=1}^{n} \sum_{i=1}^{n-k+1} |S_{i,i+k-1}| = \sum_{k=1}^{n} \sum_{i=1}^{n-k+1} k = \sum_{k=1}^{n} k(n-k)
$$
should give you the number of contiguous subsets.
A: Hints: 

Each nonempty contiguous sublist of $[1,...,n]$ has a least element $a$ and a greatest element $b$.

Thus, you want to count the number of pairs $(a,b)$ such that $1 \le a \le b \le n$.

For the case $a<b$, the count is the same as the number of two-element subsets of $\{1,...,n\}$, so the the count is ____ ?

For the case $a=b$, the count is ____ ?

Finally, if the empty list is regarded as contiguous, boost the count by $1$.
A: If we assume we want only non-empty subsets then:
for the set {a1, a2, a3, ..., an}
number of subsets with length 1 is n : {a1} , {a2} , ... , {an}
number of subsets with length 2 is n-1 : {a1,a2} , {a2,a3} , ... , {an-1, an}
...
number of subsets with length n is 1 : {a1, a2, a3, ..., an}
Therefore the sum is n+(n-1)+(n-2)+...+1 = n(n+1)/2
