def f(n): res = 0 cont_op = 0 for i in range(1, n*n+1, 2): for j in range(i//2, 2*i+1, i//2+1): k = j+1 while k <= n+j: res += abs(j - i) cont_op += 1 k += k//2+1 return cont_op