Each sequence alignment A can be assigned a cost c(A) in the following way: where Σ is the number of gaps in A, n is the number of rows and m the number of sequences.
we sum up the alignment cost for any two symbols from Σ that are aligned with each other, and add the gap cost for each gap.