Subtract invalid triplets
for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( ( 2 * j - i ) < n and s [ j ] != s [ i ] and s [ j * 2 - i ] != s [ j ] and s [ 2 * j - i ] != s [ i ] ) : NEW_LINE INDENT Total_triplet -= 1 NEW_LINE DEDENT DEDENT DEDENT print ( Total_triplet ) NEW_LINE