ABC Street is a road made of N paving blocks in a row. The blocks are numbered 1 to N.
Junseo lives on block 1 and Hayun lives on block N. Junseo jumps from block to block to meet Hayun.
Every block has one letter on it, either A, B, or C. The letter on block 1 is always A.
Junseo moves only by jumping, and always toward larger numbers. If he stands on block i, he can jump to any block from i+1 to N. One jump of k blocks costs k2 energy.
Junseo chants A, B, C in that order as he goes. So the letters on the blocks he steps on, starting from the first one, must read A, B, C, A, B, C, and so on.
Write a program that computes the smallest amount of energy Junseo needs to meet Hayun.