use long instead of int to avoid overflow