We describe the algorithm for the ADP statistic, which selects partitions on the grid { 1 . 5 , . . . , N − 0 . 5 } 2 on ranked data. The main modifications for the DDP statistic are provided in Appendix E. The count of samples inside a cell with rank ranges r ∈ [ r$_{l}$, r$_{h}$ ] and s ∈ [ s$_{l}$, s$_{h}$ ] can be computed in O (1) operations via the inclusion- exclusion principle: Therefore, for each cell C the contribution of the cell t$_{C}$ can be computed in O (1) time. Because the score per partition is a sum of contributions of individual cells, we may write S ADP m × m as follows: where C ( w, l ) is the collection of cells of width w and length l and n ( w, l, m, C ) is the number of partitions that include C . As in the algorithm for the K -sample problem, n ( w, l, m, C ) depends only on w , l , m , and whether the cell is an internal cell or an edge cell. For simplification, we discuss only the computation of the contribution of internal cells to the sum statistic, and non-internal cells can be handled similarly (as discussed in the algorithm for the K -sample problem). Therefore, our aim is to compute: where T ( w, l ) = ∑ C ∈C ( w,l $_{)}$t$_{C}$ and n ( w, l, m ) is the number of partitions that include an internal cell of width w and length l when the partition size is m and C ( w, l ) is relabelled to be the collection of internal cells of width w and length l . The algorithm proceeds as follows. First in a preprocessing phase we perform two computations: 1) calculate and store T ( w, l ) for all pairs ( w, l ) ∈ { 1 ...N − 2 } $^{2}$. Since 24 o$_{C}$ = A ( r$_{h}$, s$_{h}$ ) − A ( r$_{l}$ − 1 , s$_{h}$ ) − A ( r$_{h}$, s$_{l}$ − 1) + A ( r$_{l}$ − 1 , s$_{l}$ − 1) . ∑ I∈ Π ADP m T I = ∑ C ∈C t$_{C}$ ∑ I∈ Π ADP m I [ C ∈ C ( I )] = N − 2 ∑ w =1 N − 2 ∑ l =1 ∑ C ∈C ( w,l ) t$_{C}$n ( w, l, m, C ) , (3.4) N − 2 ∑ w =1 N − 2 ∑ l =1 n ( w, l, m ) T ( w, l ) , (3.5)