stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<string>

#include<cstring>

using namespace std;

int main(){

    string a;

    int seq[500005], n, x=-1;

    long long final=0;

    cin >> a;

    n=a.size();

    seq[0]=0;

    memset(seq, 0, sizeof(seq));

    for(int i=0; i<n; i++){

        if(a[i]=='<'){

            seq[i+1]=seq[i]+1;

        }

    }

    

    for(int i=n-1; i>=0; i--){

        if(a[i]=='>'){

            if(seq[i]<=seq[i+1]){

                seq[i]=seq[i+1]+1;

            }

        }

    }

    for(int i=0; i<=n; i++){

        final+=seq[i];

    }

    cout << final << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.9023417865390457x):
#include<iostream>

#include<string>



using namespace std;

int main(){

    string a;

    int seq[500005], n, x=-1;

    long long final =0;

    cin >> a;

    n=a.size();

    seq[0]=0;

    for(int i=0; i<n; i++){

        if(a[i]=='<'){

            if(x==1){

                seq[i+1]=1;  

                x=0;

            }

            else{

                seq[i+1]=seq[i]+1;

                x=0;

            }

        }

        else{

            if(x==0){

                seq[i+1]=0;

                x=1;

            }

            else{

                seq[i+1]=0;

            }

        }

    }

    

    for(int i=n-1; i>=0; i--){

        if(a[i]=='>'){

            if(seq[i]<=seq[i+1]){

                seq[i]=seq[i+1]+1;

            }

        }

    }

    for(int i=0; i<=n; i++){

        final+=seq[i];

    }

    cout << final << endl;

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string>

#include<cstring>

using namespace std;

int main(){

    string a;

    int seq[500005], n, x=-1;

    long long final=0;

    cin >> a;

    n=a.size();

    seq[0]=0;

    memset(seq, 0, sizeof(seq));

    for(int i=0; i<n; i++){

        if(a[i]=='<'){

            seq[i+1]=seq[i]+1;

        }

    }

    

    for(int i=n-1; i>=0; i--){

        if(a[i]=='>'){

            if(seq[i]<=seq[i+1]){

                seq[i]=seq[i+1]+1;

            }

        }

    }

    for(int i=0; i<=n; i++){

        final+=seq[i];

    }

    cout << final << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.0352367529666076x):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    int n;

    string s;

    cin>>s;

    n=s.size();

    int pos=0;

    long long int ans=0;

    while(pos<n)

    {

        int coun1=0;

        while(s[pos]=='<' && pos<n){

            ++pos;

            coun1++;

        }

        int coun2=0;



        while(s[pos]=='>' && pos<n)

        {

            coun2++;

            ++pos;

        }

       // cout<<coun1<<endl;

        //cout<<coun2<<endl;

        int x=min(coun1,coun2);

        int y=max(coun1,coun2);

        ans+= x * (long) (x-1)/2;

        ans+= y * (long)(y+1)/2;



    }

    cout<<ans<<endl;

}
// Slower C++ solution:
#include <iostream>

#define ll long long

#include <cstring>

using namespace std;



int arr[500005];

int main() {

  string s;

  cin >> s;



  memset(arr, 0, sizeof(arr));



  ll ans = 0;

  int cntr = 0;

  for (int i = 0; i < s.length(); i++){

    if (s[i] == '<'){

      arr[i+1] = arr[i]+1;

    }

  }



  for (int i = s.length()-1; i >= 0; i--){

    if (s[i] == '>'){

      if (arr[i] < arr[i+1] + 1)

        arr[i] = arr[i+1] + 1; 

    }

    ans = ans + arr[i];

  }





  cout << ans + arr[s.length()] << endl;

}

// Faster C++ solution for the same problem (measured speedup: 3.0110950310497526x):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    int n;

    string s;

    cin>>s;

    n=s.size();

    int pos=0;

    long long int ans=0;

    while(pos<n)

    {

        int coun1=0;

        while(s[pos]=='<' && pos<n){

            ++pos;

            coun1++;

        }

        int coun2=0;



        while(s[pos]=='>' && pos<n)

        {

            coun2++;

            ++pos;

        }

       // cout<<coun1<<endl;

        //cout<<coun2<<endl;

        int x=min(coun1,coun2);

        int y=max(coun1,coun2);

        ans+= x * (long) (x-1)/2;

        ans+= y * (long)(y+1)/2;



    }

    cout<<ans<<endl;

}
// Slower C++ solution:
#include<iostream>

#include<string>

#include<cstring>

using namespace std;

int main(){

    string a;

    int seq[500005], n, x=-1;

    long long final=0;

    cin >> a;

    n=a.size();

    seq[0]=0;

    memset(seq, 0, sizeof(seq));

    for(int i=0; i<n; i++){

        if(a[i]=='<'){

            seq[i+1]=seq[i]+1;

        }

    }

    

    for(int i=n-1; i>=0; i--){

        if(a[i]=='>'){

            if(seq[i]<=seq[i+1]){

                seq[i]=seq[i+1]+1;

            }

        }

    }

    for(int i=0; i<=n; i++){

        final+=seq[i];

    }

    cout << final << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.0452700886700974x):
#include <bits/stdc++.h>

using namespace std;

string s;

long long ans;

int main()

{

    cin>>s;

    int len=s.length();

    for(int i=0;i<len;i++){

        long long l=0;

        long long r=0;

        while(i<len&&s[i]=='<'){

            l++;

            i++;

        }

        while(i<len&&s[i]=='>'){

            r++;

            i++;

        }

        i--;

        if(l>=r){

            ans+=((l+1)*l)/2;

            r--;

            ans+=((r+1)*r)/2;

        }else{

            ans+=((r+1)*r)/2;

            l--;

            ans+=((l+1)*l)/2;

        }

    }

    printf("%lld",ans);

    return 0;

}
// Slower C++ solution:
#include <iostream>

#define ll long long

#include <cstring>

using namespace std;



int arr[500005];

int main() {

  string s;

  cin >> s;



  memset(arr, 0, sizeof(arr));



  ll ans = 0;

  int cntr = 0;

  for (int i = 0; i < s.length(); i++){

    if (s[i] == '<'){

      arr[i+1] = arr[i]+1;

    }

  }



  for (int i = s.length()-1; i >= 0; i--){

    if (s[i] == '>'){

      if (arr[i] < arr[i+1] + 1)

        arr[i] = arr[i+1] + 1; 

    }

    ans = ans + arr[i];

  }





  cout << ans + arr[s.length()] << endl;

}

// Faster C++ solution for the same problem (measured speedup: 3.0210485634231676x):
#include <bits/stdc++.h>

using namespace std;

string s;

long long ans;

int main()

{

    cin>>s;

    int len=s.length();

    for(int i=0;i<len;i++){

        long long l=0;

        long long r=0;

        while(i<len&&s[i]=='<'){

            l++;

            i++;

        }

        while(i<len&&s[i]=='>'){

            r++;

            i++;

        }

        i--;

        if(l>=r){

            ans+=((l+1)*l)/2;

            r--;

            ans+=((r+1)*r)/2;

        }else{

            ans+=((r+1)*r)/2;

            l--;

            ans+=((l+1)*l)/2;

        }

    }

    printf("%lld",ans);

    return 0;

}
// Slower C++ solution:
#include <vector>

#include <list>

#include <map>

#include <set>

#include <deque>

#include <stack>

#include <bitset>

#include <algorithm>

#include <functional>

#include <numeric>

#include <utility>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cctype>

#include <string>

#include <cstring>

#include <ctime>

using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)

#define repe(i,n) for(int i = 0; i <= (int)(n); i++)

typedef vector<int> VI; typedef vector<VI> VVI;

typedef vector<string> VS; typedef vector<VS> VVS;

typedef pair<int, int> PII;

typedef long long LL;





int main(){

  LL sum = 0;

  VI num(1000000, 0);

  int i = 0;

  string s;

  cin >> s;



  while (i != (s.size())) {

    int a = 0, b = 0, j = 0;



    if (s[i] == '<')  { 

      while (s[i] == '<') { a++; i++; }

      for (j = (i-a); j <= i; j++) num[j] += j - (i-a);

    } else  { 

      while (s[i] == '>') { b++; i++; } 

      for (j = i; j >= (i-b); j--) {

        num[j] = (i - j);

      }

      j++;

      if (j != 0 && num[j] <= num[j-1]) num[j] = (num[j-1] + 1);

    }

  }



  //cout << num[0];

  //rep(i, s.size()) {

  //  cout << " " << s[i] << " " << num[i+1];

  //}

  //cout << endl;



  rep(i,s.size()+1) {

    sum += num[i];

  }

  cout << sum << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.0132302784796625x):
#include <bits/stdc++.h>

using namespace std;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  

  string S;

  cin >> S;



  int size = S.length();

  vector<int> vi(size + 1);

  for (int i = 0; i < size; i++) {

    if (S[i] == '<') {

      vi[i + 1] = vi[i] + 1;

    }

  }



  reverse(vi.begin(), vi.end());

  for (int i = 0; i < size; i++) {

    if (S[size - (i + 1)] == '>') {

      if (vi[i] >= vi[i + 1]) {

        vi[i + 1] = vi[i] + 1;

      }

    }

  }



  long long res = 0;

  for (int i = 0; i < vi.size(); i++) {

    res += vi[i];

  }

  cout << res << '\n';

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <vector>

#include <set>

#include <bitset>



const int MOD = 1e9 + 7;



using namespace std;



long long si = 0;



long long inq(long long a, long long b)

{

    if (b == 0) return 1;

    long long l = inq(a, b / 2);

    if (b % 2) return l * l % MOD * a % MOD;

    return l * l % MOD;

}



const int K = 10000;

vector<long long> dp(K);



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int n, k;

    cin >> n >> k;

    for (int i = 0; i < n; i++)

    {

        for (int j = 0; j <= k; j++)

        {

            si = (si + j * inq(k + 1, n - 1)) % MOD;

        }

    }

    dp[0] = 1;

    for (int i = n; i >= 1; i--)

    {

        vector<long long> dp2(K);

        for (int a = 0; a <= k; a++)

        {

            for (int hv = 0; hv < K; hv++)

            {

                if (dp[hv] != 0)

                {

                    if (a <= i) dp2[hv + (hv + a) / i] = (dp2[hv + (hv + a) / i] + dp[hv]) % MOD;

                    else dp2[hv] = (dp2[hv] + dp[hv]) % MOD;

                }

            }

        }

        dp = dp2;

    }

    long long si2 = 0;

    for (int i = 0; i < K; i++) si2 = (si2 + dp[i] * i) % MOD;

    cout << (si + MOD - si2) % MOD;

}


// Faster C++ solution for the same problem (measured speedup: 2.038052195332705x):
#include <iostream>

#include <algorithm>

#include <vector>

#include <set>

#include <bitset>



const int MOD = 1e9 + 7;



using namespace std;



long long si = 0;



long long inq(long long a, long long b)

{

    if (b == 0) return 1;

    long long l = inq(a, b / 2);

    if (b % 2) return l * l % MOD * a % MOD;

    return l * l % MOD;

}



const int K = 4000;

vector<long long> dp(K);



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int n, k;

    cin >> n >> k;

    for (int i = 0; i < n; i++)

    {

        for (int j = 0; j <= k; j++)

        {

            si = (si + j * inq(k + 1, n - 1)) % MOD;

        }

    }

    dp[0] = 1;

    for (int i = n; i >= 1; i--)

    {

        vector<long long> dp2(K);

        for (int a = 0; a <= k; a++)

        {

            for (int hv = 0; hv < K; hv++)

            {

                if (dp[hv] != 0)

                {

                    if (a <= i) dp2[hv + (hv + a) / i] = (dp2[hv + (hv + a) / i] + dp[hv]) % MOD;

                    else dp2[hv] = (dp2[hv] + dp[hv]) % MOD;

                }

            }

        }

        dp = dp2;

    }

    long long si2 = 0;

    for (int i = 0; i < K; i++) si2 = (si2 + dp[i] * i) % MOD;

    cout << (si + MOD - si2) % MOD;

}
// Slower C++ solution:
/*********************

*  Author: xuziyuan  * 

*********************/



#include <bits/stdc++.h>



#define rt0 return 0

#define rep(i,n) for(int i=0;i<n;i++)

#define repn(i,n) for(int i=1;i<=n;i++)

#define replet(c) for(char c='a';c<='z';c++) 

#define LL long long

#define pii pair <int,int>

#define pb push_back

#define fi first

#define se second

#define mpr make_pair

#define sqr(a) ((a)*(a))



using namespace std;



const LL MOD=1e9+7;



LL n,t,dp[110][10010],all=1,ans=0;



int main()

{

	cin>>n>>t;

	rep(i,n-1) all=all*(t+1)%MOD;

	all=all*(t+1)*t/2*n%MOD;

	dp[n][0]=1;

	for(int i=n;i>0;i--)

	{

		rep(j,10005)

		{

			rep(k,t+1)

			{

				if(dp[i][j]==0) continue;

				if(k<=i) dp[i-1][j+(j+k)/i]=(dp[i-1][j+(j+k)/i]+dp[i][j])%MOD;

				else dp[i-1][j]=(dp[i-1][j]+dp[i][j])%MOD;

			}

		}

	}

	repn(i,10003) ans=(ans+i*dp[0][i])%MOD;

	cout<<(all-ans+MOD)%MOD<<endl;

	rt0;

}

// Faster C++ solution for the same problem (measured speedup: 2.335575726685662x):
/*********************

*  Author: xuziyuan  * 

*********************/



#include <bits/stdc++.h>



#define rt0 return 0

#define rep(i,n) for(int i=0;i<n;i++)

#define repn(i,n) for(int i=1;i<=n;i++)

#define replet(c) for(char c='a';c<='z';c++) 

#define LL long long

#define pii pair <int,int>

#define pb push_back

#define fi first

#define se second

#define mpr make_pair

#define sqr(a) ((a)*(a))



using namespace std;



const LL MOD=1e9+7;



LL n,t,dp[110][10010],all=1,ans=0;



int main()

{

	cin>>n>>t;

	rep(i,n-1) all=all*(t+1)%MOD;

	all=all*(t+1)*t/2*n%MOD;

	if(n==t)

	{

		dp[n-1][1]=1;

		dp[n-1][0]=t;

	}

	else dp[n-1][0]=t+1;

	for(int i=n-1;i>0;i--)

	{

		rep(j,10005)

		{

			if(dp[i][j]==0) continue;

			rep(k,t+1)

			{

				if(k<=i) dp[i-1][j+(j+k)/i]=(dp[i-1][j+(j+k)/i]+dp[i][j])%MOD;

				else dp[i-1][j]=(dp[i-1][j]+dp[i][j])%MOD;

			}

		}

	}

	repn(i,10003) ans=(ans+i*dp[0][i])%MOD;

	cout<<(all-ans+MOD)%MOD<<endl;

	rt0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define REP(i,p,n) for(ll i=p;i<ll(n);++i)

#define rep(i,n) REP(i,0,n)



using ll = long long;

using pll = pair<ll, ll>;



const ll MAXN = 1002;

ll C[MAXN][MAXN];



int main()

{

    ll H, W;

    cin >> H >> W;



    ll CH, CW, DH, DW;

    cin >> CH >> CW >> DH >> DW;

    --CH;

    --CW;

    --DH;

    --DW;



    vector<string> S(H);

    rep (i, H) { cin >> S[i]; }



    rep (x, MAXN) rep (y, MAXN) { C[x][y] = MAXN * MAXN; }



    using Node = tuple<ll, ll, ll>;

    priority_queue<Node, vector<Node>, greater<Node> > Q;



    const auto insert = [&](ll xx, ll yy, ll newCost)

    {

        if (xx < 0 || W <= xx) { return; }

        if (yy < 0 || H <= yy) { return; }

        if (S[yy][xx] == '#') { return; }

        if (C[yy][xx] <= newCost) { return; }



        C[yy][xx] = newCost;

        Q.emplace(newCost, xx, yy);

    };



    insert(CW, CH, 0);



    ll ans = -1;



    while (!Q.empty())

    {

        const auto node = Q.top();

        Q.pop();



        const auto cost = get<0>(node);

        const auto cx = get<1>(node);

        const auto cy = get<2>(node);



        if (cx == DW && cy == DH) { ans = cost; break; }



        insert(cx - 1, cy, cost);

        insert(cx + 1, cy, cost);

        insert(cx, cy - 1, cost);

        insert(cx, cy + 1, cost);



        for (ll dx=-2;dx<=2;++dx)

        for (ll dy=-2;dy<=2;++dy)

        {

            insert(cx + dx, cy + dy, cost + 1);

        }

    }

    cout << ans << endl;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 9.307560581695082x):
#include <bits/stdc++.h>

using namespace std;



int main()

{

    int H, W, CH, CW, DH, DW;

    cin >> H >> W >> CH >> CW >> DH >> DW;

    --CH;

    --CW;

    --DH;

    --DW;



    vector<string> S(H);

    for (int i=0;i<H;++i) { cin >> S[i]; }



    vector<int> Cost(H * W, 1000001);

    deque< pair<int, int> > Q;



    const auto insert = [&](int x, int y, int cost, int extraCost)

    {

        if (x < 0 || W <= x || y < 0 || H <= y) { return; }

        if (S[y][x] == '#') { return; }



        const auto newCost = cost + extraCost;

        if (Cost[x + y * W] <= newCost) { return; }

        Cost[x + y * W] = newCost;



        if (extraCost == 0) { Q.emplace_front(x, y); }

        else                { Q.emplace_back(x, y); }

    };



    insert(CW, CH, 0, 0);



    int ans = -1;



    while (!Q.empty())

    {

        const auto x = Q.front().first;

        const auto y = Q.front().second;

        Q.pop_front();



        const auto cost = Cost[x + y * W];

        if (x == DW && y == DH) { ans = cost; break; }



        insert(x - 1, y, cost, 0);

        insert(x + 1, y, cost, 0);

        insert(x, y - 1, cost, 0);

        insert(x, y + 1, cost, 0);



        for (int dx=-2;dx<=2;++dx)

        for (int dy=-2;dy<=2;++dy)

        {

            insert(x + dx, y + dy, cost, 1);

        }

    }



    cout << ans << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>



int main() {

    using namespace std;

    constexpr unsigned long maxN = 200010;

    unsigned long N;

    scanf("%lu", &N);

    array<unsigned long, maxN> perm;

    {

        array<pair<long, long>, maxN> p;

        for(unsigned long i = 0; i < N; ++i)scanf("%lu%lu", &p[i].first, &p[i].second);

        sort(p.begin(), p.begin() + N);

        for(unsigned long i = 0; i < N; ++i)p[i] = {p[i].second, i + 1};

        sort(p.begin(), p.begin() + N);

        transform(p.cbegin(), p.cbegin() + N, perm.begin(), [](auto i){return i.second;});

    }



    constexpr unsigned long MOD = 998244353;

    array<unsigned long, maxN> binary;

    unsigned long n = binary[0] = 1;

    generate(binary.begin() + 1, binary.end(), [&n](){if(n >= MOD)n -= MOD;return n <<= 1;});



    array<unsigned long, maxN> fenwick_tree{};

    auto que = [&fenwick_tree, &N](unsigned long i){

        unsigned long s{0}, j{i};

        while (i) { s += fenwick_tree[i]; i -= i & -i; }

        while (j <= N) { ++fenwick_tree[j]; j += j & -j; }

        return s;

    };



    array<unsigned long, maxN> coef{};

    coef[N] = N + MOD - 4;

    for(unsigned long i = 0; i != N; ++i){

        auto p = perm[i], q = que(p);

        ++coef[q];

        ++coef[i - q];

        ++coef[p - q - 1];

        ++coef[N - i - p + q];

    }



    cout << inner_product(binary.begin(), binary.begin() + N + 1, coef.begin(), 4 + MOD - N) % MOD << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.9747403671750243x):
#include <bits/stdc++.h>



int main() {

    using namespace std;

    constexpr int maxN = 200010;

    int N;

    scanf("%d", &N);

    array<int, maxN> perm;

    {

        array<pair<int, int>, maxN> p;

        for(int i = 0; i < N; ++i)scanf("%d%d", &p[i].first, &p[i].second);

        sort(p.begin(), p.begin() + N);

        for(int i = 0; i < N; ++i)p[i] = {p[i].second, i + 1};

        sort(p.begin(), p.begin() + N);

        transform(p.cbegin(), p.cbegin() + N, perm.begin(), [](auto i){return i.second;});

    }



    constexpr unsigned long MOD = 998244353;

    array<unsigned long, maxN> binary;

    unsigned long n = binary[0] = 1;

    generate(binary.begin() + 1, binary.end(), [&n](){if(n >= MOD)n -= MOD;return n <<= 1;});



    array<int, maxN> fenwick_tree{};

    auto que = [&fenwick_tree, &N](int i){

        int s{0}, j{i};

        while(i){

            s += fenwick_tree[i];

            i -= i & -i;

        }

        while(j <= N){

            ++fenwick_tree[j];

            j += j & -j;

        }

        return s;

    };



    array<int, maxN> coef{};

    coef[N] = N + MOD - 4;

    for(int i = 0; i != N; ++i){

        auto p = perm[i], q = que(p);

        ++coef[q];

        ++coef[i - q];

        ++coef[p - q - 1];

        ++coef[N - i - p + q];

    }



    cout << inner_product(binary.begin(), binary.begin() + N + 1, coef.begin(), 4 + MOD - N) % MOD << endl;

    return 0;

}
// Slower C++ solution:
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>



int main() {

    using namespace std;

    constexpr unsigned long maxN = 200010;

    unsigned long N;

    scanf("%lu", &N);

    array<unsigned long, maxN> perm;

    {

        array<pair<long, long>, maxN> p;

        for(unsigned long i = 0; i < N; ++i)scanf("%lu%lu", &p[i].first, &p[i].second);

        sort(p.begin(), p.begin() + N);

        for(unsigned long i = 0; i < N; ++i)p[i] = {p[i].second, i + 1};

        sort(p.begin(), p.begin() + N);

        transform(p.cbegin(), p.cbegin() + N, perm.begin(), [](auto i){return i.second;});

    }



    constexpr unsigned long MOD = 998244353;

    array<unsigned long, maxN> binary;

    unsigned long n = binary[0] = 1;

    generate(binary.begin() + 1, binary.end(), [&n](){if(n >= MOD)n -= MOD;return n <<= 1;});



    array<unsigned long, maxN> fenwick_tree{};

    auto que = [&fenwick_tree, &N](unsigned long i){

        unsigned long s{0}, j{i};

        while (i) { s += fenwick_tree[i]; i -= i & -i; }

        while (j <= N) { ++fenwick_tree[j]; j += j & -j; }

        return s;

    };



    array<unsigned long, maxN> coef{};

    coef[N] = N + MOD - 4;

    for(unsigned long i = 0; i != N; ++i){

        auto p = perm[i], q = que(p);

        ++coef[q];

        ++coef[i - q];

        ++coef[p - q - 1];

        ++coef[N - i - p + q];

    }



    cout << inner_product(binary.begin(), binary.begin() + N + 1, coef.begin(), 4 + MOD - N) % MOD << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.973144304319989x):
#include <bits/stdc++.h>



int main() {

    using namespace std;

    constexpr int maxN = 200010;

    int N;

    scanf("%d", &N);

    array<int, maxN> perm;

    {

        array<pair<int, int>, maxN> p;

        for(int i = 0; i < N; ++i)scanf("%d%d", &p[i].first, &p[i].second);

        sort(p.begin(), p.begin() + N);

        for(int i = 0; i < N; ++i)p[i] = {p[i].second, i + 1};

        sort(p.begin(), p.begin() + N);

        transform(p.cbegin(), p.cbegin() + N, perm.begin(), [](auto i){return i.second;});

    }



    constexpr unsigned long MOD = 998244353;

    array<unsigned long, maxN> binary;

    unsigned long n = binary[0] = 1;

    generate(binary.begin() + 1, binary.end(), [&n](){if(n >= MOD)n -= MOD;return n <<= 1;});



    array<int, maxN> fenwick_tree{};

    auto que = [&fenwick_tree, &N](int i){

        int s{0}, j{i};

        while(i){

            s += fenwick_tree[i];

            i -= i & -i;

        }

        while(j <= N){

            ++fenwick_tree[j];

            j += j & -j;

        }

        return s;

    };



    array<int, maxN> coef{};

    coef[N] = N + MOD - 4;

    for(int i = 0; i != N; ++i){

        auto p = perm[i], q = que(p);

        ++coef[q];

        ++coef[i - q];

        ++coef[p - q - 1];

        ++coef[N - i - p + q];

    }



    cout << inner_product(binary.begin(), binary.begin() + N + 1, coef.begin(), 4 + MOD - N) % MOD << endl;

    return 0;

}