The permutation σ consisting of four words A,B,C,D has fAB(σ), the sum of the number of B placed rightside of every A. We can define fBC(σ),fCD(σ),fDA(σ) as the same way too.
For example, σ=ACBDBACDCBAD, fAB(σ)=3+1+0=4, fBC(σ)=4,fCD(σ)=6, fDA(σ)=3
Find the maximal value of fAB(σ)+fBC(σ)+fCD(σ)+fDA(σ), when σ consists of 2020 letters for each A,B,C,D