Multiplying with n to avoid floating point arithmetic .
p . first *= n ; p . second *= n ; for ( int i = 0 ; i < n ; i ++ ) { mid . first += a [ i ] . first ; mid . second += a [ i ] . second ; a [ i ] . first *= n ; a [ i ] . second *= n ; }