#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9+7;
ll qpow(ll a,ll b) {
ll ans = 1;
while(b) {
if(b&1) ans=(ans*a)%mod;
a = (a*a)%mod;
b /= 2;
}
return ans;
}
int main()
{
ll n,m,a,b;
scanf("%lld %lld",&n,&m);
while(m--)
{
scanf("%lld %lld",&a,&b);
a--;
ll ans1=((3*(qpow(2,b)-1)%mod)%mod+mod-(2*b)%mod)%mod;
ll ans2=((3*(qpow(2,a)-1)%mod)%mod+mod-(2*a)%mod)%mod;
printf("%lld\n",(ans1-ans2+mod)%mod);
}
return 0;
}
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6+10;
struct node{
int x,y;}a[N];
ll n,p[N],q[N];
int main()
{
scanf("%lld",&n);
for(int i=1; i<=n; i++) {
cin >> a[i].x >> a[i].y;
p[a[i].x]++;
q[a[i].y]++;
}
ll ans = 0;
for(int i=1; i<=n; i++)
ans += 1ll*(p[a[i].x]-1)*(q[a[i].y]-1);
cout << ans << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
char a[maxn],b[maxn];
int n;
int main()
{
cin >> n;
for(int i=1; i<=n; i++) cin >> a[i];
int l=1 , r=n , cnt = 0;
while(r>=1) {
if(a[l]<a[r]) {
b[++cnt] = a[l]; l++;
}
else if(a[l]>a[r]) {
b[++cnt] = a[r]; r--;
}
else {
int flag = 0;
int ll = l+1 , rr=r-1;
while(rr>=ll) {
if(a[ll]<a[rr]) {
flag = 1; break;
}
if(a[ll]>a[rr]) {
flag = 0; break;
}
ll++;
rr--;
}
if(flag==0) {
b[++cnt] = a[r]; r--;
}
else {
b[++cnt] = a[l]; l++;
}
}
}
for(int i=1; i<=n; i++) cout<<b[i]<<" ";
return 0;
}
#include <bits/stdc++.h>
#include <queue>
#define ll long long
using namespace std;
const int maxn = 1e3+10;
int vis[maxn][maxn];
char a[maxn][maxn];
struct node {
int x,y,st;};
int dx[4] = {
0,0,1,-1};
int dy[4] = {
1,-1,0,0};
int n,sx,sy,ex,ey;
int bfs(int x,int y)
{
queue<node> q;
node no,nx;
no.x = x;
no.y = y;
no.st = 0;
q.push(no);
while(!q.empty())
{
no = q.front();
q.pop();
for(int i=0; i<4; i++)
{
nx.x = no.x + dx[i];
nx.y = no.y + dy[i];
nx.st = no.st+1;
if(nx.x<=0 || nx.y<=0 || nx.x>n || nx.y>n || a[nx.x][nx.y]=='1' || vis[nx.x][nx.y]==1) continue;
vis[nx.x][nx.y] = 1;
if(nx.x==ex && nx.y==ey)
return nx.st;
q.push(nx);
}
}
}
int main()
{
cin >> n;
for(int i=1; i<=n; i++)
scanf("%s",a[i]+1);
cin >> sx >> sy >> ex >> ey;
int t = bfs(sx,sy);
printf("%d\n",t);
return 0;
}