#include using namespace std; long long n,c,d,ans; const int MOD=1e9+7; int main(){ cin>>n; for(int i=0;i>c>>d; c=(c+1)/2%MOD; d%=MOD; ans=(ans+c*d%MOD)%MOD; } cout<