Magic squares implementation