public static final long mul(long x, long y) {       
        long moflo = (1L<<31);  // multiply without overflow if operands < moflo
        if (x >= 0 && x < moflo && y >= 0 && y < moflo) return (x * y) % p;
        long res = 0;
        while (x != 0) {
            if ((x & 1) == 1) res = (res + y) % p;
            x >>= 1;
            y = (y << 1) % p;
        }
        return res;
    }