mod = 1000000007; int a = (b * c)%mod; // It might overflow even we did mod; int a = (int)((1LL * b * c)%mod); // its correct