akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;
vector<int> s(100005);
int main(void){
	int N,K,ans = 0,cnt = 0,p;
	string S;
	cin >> N >> K;
	cin >> S;
	for(int i=0;i<S.size();i++){
		if(S[i] == 'R')s[i] = 0;
		else s[i] = 1;
	}
	vector<int> v;
	for(int i=0;i<N;i++){
		int cnt = 1;
		while( i<N-1 && s[i]==s[i+1]){
			i++;
			cnt++;
		}
		v.push_back(cnt);
	}
	cnt = 0;
	int sum = 0;
	for(auto x:v){
		ans += x-1;
		sum += x;
	}
	cout << min(ans+ K*2,sum-1) << endl;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Main {
    int N;
    vector<ll> A;
    ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }
    void input() {
        cin >> N;
        A.resize(N);
        REP(i, N) { cin >> A[i]; }
    }
    void output() {
        ll g = A[0];
        REP(i, N - 1) { g = gcd(g, A[i + 1]); }
        if (g > 1) {
            cout << "not coprime" << endl;
            return;
        }
        vector<ll> prime;
        int a = 1000;
        vector<int> memo(a);
        FOR(i, 2, a) {
            if (memo[i]) continue;
            prime.emplace_back(i);
            for (ll j = i; i * j < a; ++j) { memo[i * j] = 1; }
        }
        set<ll> st;
        REP(i, N) {
            for (auto &p : prime) {
                if (A[i] % p) continue;
                if (st.count(p)) {
                    cout << "setwise coprime" << endl;
                    return;
                }
                st.emplace(p);
                while (A[i] % p == 0) A[i] /= p;
                if (A[i] == 1) break;
            }
            if (A[i] > 1) {
                if (st.count(A[i])) {
                    cout << "setwise coprime" << endl;
                    return;
                }
                st.emplace(A[i]);
            }
        }
        cout << "pairwise coprime" << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    Main();

    return 0;
}


Measured memory_bytes: 11108
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a,b,c,d;
  cin>>a>>b;
  c=a;
  reverse(c.begin(),c.end());
  d=b;
  reverse(d.begin(),d.end());
  if(c==b && d==a) puts("YES");
  else puts("NO");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,b) for(int i=0;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;

int main() {

	int n, k;
	cin >> n >> k;

	vector<int> x(n), y(n);
	vector<int>xary, yary;

	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];

		xary.push_back(x[i]);
		yary.push_back(y[i]);
	}

	sort(begin(xary), end(xary));
	sort(begin(yary), end(yary));

	ll ans = 1LL * (xary[n - 1] - xary[0])*(yary[n - 1] - yary[0]);


	//4点全探索。幅をもたせる。
	for (int xi = 0; xi < n; xi++) {
		for (int xj = xi + 1; xj < n; xj++) {
			for (int yi = 0; yi < n; yi++) {
				for (int yj = yi + 1; yj < n; yj++) {

					int num = 0;
					ll lx = xary[xi], rx = xary[xj];
					ll by = yary[yi], uy = yary[yj];

					//現在決めた長方形に含まれているか全ての点を数え上げ。
					for (int i = 0; i < n; i++) {
						if (lx <= x[i] && x[i] <= rx && by <= y[i] && y[i] <= uy) {
							num++;
						}
					}
					
					//更新処理。
					if (num >= k)ans = min(ans, 1LL * (rx - lx)*(uy - by));

				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
k, x = M()
ans = list()
for i in range(1, k):
    ans.append(x-i)
ans.append(x)
for i in range(1, k):
    ans.append(x+i)
ans.sort()
print(' '.join(map(str, ans)))

Measured memory_bytes: 68400
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

ll dp[1005][1005];

int main(){
    string s,ss;
    cin >> s >> ss;
    ll n,nn;
    n=s.size();
    nn=ss.size();
    
    rep(i,n+1) dp[i][0]=i;
    rep(i,nn+1) dp[0][i]=i;
    
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=nn;j++){
            if(s[i-1]==ss[j-1]){
                dp[i][j]=dp[i-1][j-1];
            }else{
                dp[i][j]=min({dp[i][j-1]+1,dp[i-1][j]+1,dp[i-1][j-1]+1});
            }
        }
    }
    
    cout << dp[n][nn] << endl;

    return 0;
}












Measured memory_bytes: 11048
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    cout << c << " " << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long;

const int INF = 1e9;
const long long  LLINF = 1e15;

using namespace std;

int main() {
  int N, a[105];
  cin>>N;
  vector<int> v;
  REP(i,0,N){
    int tmp;
    cin>>tmp;
    v.push_back(tmp);
  }
  sort(v.begin(), v.end());
  cout<<v[v.size()-1] - v[0]<<endl;
  return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = [a, b, c, d, e]
s = []

for i in l:
    if i % 10 > 0:
        s.append(10 - (i % 10))
if len(s) > 0:
    s.sort()
    del s[-1]

ans = sum(l) + sum(s)
print(ans)


Measured memory_bytes: 3064
using System;
class Program
{
	static void Main(string[] args)
	{
      // スペース区切りの整数の入力
      var n = int.Parse(Console.ReadLine());
      var inputs = Array.ConvertAll(Console.ReadLine().Split(' '), x => int.Parse(x));
      var max=inputs[0];
      var sum=0;
      foreach(var input in inputs){
        if(input>=max){
          sum++;
          max=input;
        }
      }
      Console.WriteLine(sum);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long count = 0;
  int bcount = 0;

  vector<int> bb(n, 0);
  vector<pair<int, int>> rg;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'B') {
      bb.at(i)++;
      bcount++;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s.at(i) == 'R' && s.at(j) == 'G') {
        rg.push_back(make_pair(i, j));
      }
      if (s.at(i) == 'G' && s.at(j) == 'R') {
        rg.push_back(make_pair(i, j));
      }
    }
  }
  for (int j = 0; j < rg.size(); j++) {
    int dis = abs(rg.at(j).first - rg.at(j).second);
    int left = rg.at(j).first - dis;
    int right = rg.at(j).second + dis;
    int center = -1;
    int tem = 0;
    if ((rg.at(j).first + rg.at(j).second) % 2 == 0)
      center = (rg.at(j).first + rg.at(j).second) / 2;
    if (left >= 0 && left <= n - 1 && bb.at(left) == 1) tem++;
    if (right >= 0 && right <= n - 1 && bb.at(right) == 1) tem++;
    if (center >= 0 && center <= n - 1 && bb.at(center) == 1) tem++;
    count += bcount - tem;
  }
  cout << count;
}


Measured memory_bytes: 19704
#include <bits/stdc++.h>

using namespace std;

const int MD  = 1e9 + 7;
typedef long long ll;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,ans = 1;cin >> n;
    for(int i = 1; i <= n; i++) ans = (ans * i) % MD;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        final int N = scan.nextInt();
        int count = 0;
        for (int i = 0; i < N; i++) {
            if (scan.nextInt() - i != 1) {
                count++;
            }
        }
        if (count > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n,k;cin>>n>>k;
    ll ans=0;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll ksub;
    if(k%2==0){ksub=(k/2)*(k-1)%mod;}
    else{ksub=((k-1)/2)*k%mod;}
    for(int i=0;i<n;i++){
        ll c1=0,c2=0,num=a[i];
        for(int j=0;j<n;j++){
            if(a[i]<a[j]){
                c1++;
                if(i>j) c2++;
            }
        }
        ans=(ans+(k*c2)%mod+(ksub*c1)%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int inf = 1<<30;
typedef pair<int, int> P;

int main() {
  int n; cin >> n;
  vector<int> a(n+1);
  rep(i, n) cin >> a[i+1];
  vector<int> b(n+1);
  for(int i = n; i >= 1; i--) {
    int sum = 0;
    for(int j = i+i; j <= n; j += i) {
      sum ^= b[j];
    }
    b[i] = sum^a[i];
  }

  vector<int> ans;
  for(int i = 1; i <= n; i++) {
    if(b[i]) ans.push_back(i);
  }
  cout << ans.size() << endl;
  rep(i, ans.size()) {
    if(i) cout << " ";
    cout << ans[i];
    if(i == ans.size() -1) cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3064
while True:
    W,H=map(int,input().split())
    if (W == 0 and H == 0):
        break
    for i in range(W):
        for j in range(H):
            if (i%2 == 0):
                if (j%2 == 0):
                    print("#", end="")
                else:
                    print(".", end="")
            else:
                if (j%2 == 0):
                    print(".", end="")
                else:
                    print("#", end="")
        print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>                          
using namespace std;                              
int main(void){                                   
  int n,q,count = 0,ans;                          
  bool a = false;                                 
  string s;                                       
  cin >> n >> q;                                  
  cin >> s;                                       
  int l[q],r[q];                                  
  int ac[n+1];                                    
  for(int i = 0; i < q;++i){                      
    cin >> l[i] >> r[i];                          
  }                                               
  ac[0] = 0;                                      
  for(int i = 0;i < n;++i){                       
      if(s[i] == 'A'){                            
        a = true;                                              
      }                                           
      else if(s[i] == 'C'){                       
        if(a){                                    
          count++;                                
          a = false;                              
        }                                         
        else a = false;                           
      }                                           
      else a = false;                                                                       
    ac[i] = count;                                
  }                                               
  for(int i = 0; i < q;++i){                      
    cout << ac[r[i]-1] -ac[l[i]-1] << endl;       
  }                                               
  return 0;                                       
}                                                 


Measured memory_bytes: 2176
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/11/20 07:29:12
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  int n; cin>>n;
  set<int> paper;
  for (int i = 0; i < n; i++) {
    int a; cin>>a;
    if (paper.count(a))
      paper.erase(a);
    else
      paper.insert(a);
  }
  cout << paper.size() << endl;

  return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		for(int i = 1; i <= 10000; i++){
			int x = sc.nextInt();
			int y = sc.nextInt();
			if(x == 0 && y == 0){
			break;
			}else{
				System.out.println(Math.min(x, y) + " " + Math.max(x, y));
			}				
		}
	sc.close();
	}
}

Measured memory_bytes: 35856
import sys
import math
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
L.sort()

ans = 10 ** 18
def dfs(index, z, al):
    global ans
    if len(al) == N:
        if len(set(al) - {0}) < 3:
            return

        m = {
            1: 0,
            2: 0,
            3: 0,
        }
        mp = 0
        for i in range(N):
            v = al[i]
            if v == 0:
                continue
            if m[v] != 0:
                mp += 10
            m[v] += L[i]
        ans = min(ans, mp + abs(A - m[1]) + abs(B - m[2]) + abs(C - m[3]))
        return

    dfs(index + 1, 0, al + [0])
    dfs(index + 1, 1, al + [1])
    dfs(index + 1, 2, al + [2])
    dfs(index + 1, 3, al + [3])
    return

dfs(0, 0, [])

print(ans)

Measured memory_bytes: 3064
Q, H, S, D = map(int, input().split())
N = int(input())
plice_dict = {0.25: Q, 0.5: min(2*Q, H), 1: min(4*Q, 2*H, S), 2: min(8*Q, 4*H, 2*S, D)}
result = 0

while N != 0:
    if N > 2:
        result += plice_dict[2] * (N - 2) // 2 if (N - 2) % 2 == 0 else plice_dict[2] * (N - 3) // 2 + plice_dict[1]
        N = 2
    elif N == 2:
        result += plice_dict[2]
        N -= 2
    elif N >= 1:
        result += plice_dict[1]
        N -= 1
    elif N >= 0.5:
        result += plice_dict[0.5]
        N -= 0.5
    else:
        result += plice_dict[0.25]
        N -= 0.25

print(result)

Measured memory_bytes: 3188
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

#define MAX_ANS 7500000

int m;
ll n;
bool is_prime[MAX_ANS];
int ans;

void solve(int a,int b){
    int count=0;
    for(int i = 0; i<b-a;i++)is_prime[i] = false;

    for(int i=m;;i++){
        if(!(is_prime[i-a])){
            for(int j = i;j<b;j+=i) is_prime[j-a]=true;
            count++;
            if(count == n)break;
        }
    }
}

int main(){
    while(1){
        cin >> m >> n ;
        if(m==0 && n == 0)break;
        solve(m,MAX_ANS);
        for(int i=m;i<MAX_ANS;i++){
            if(is_prime[i-m] == false){
                ans = i;
                break;
            }
        }
        cout << ans << endl;
    }


}


Measured memory_bytes: 10432
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, A[100001];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    for(int i = 0; i < N; ++i) cin >> A[i];
    int res = 0;
    for(int i = 0; i < N; ++i) {
        res += A[i] / 2;
        if(A[i] % 2) {
            if(A[i + 1] > 0) {
                --A[i + 1];
                ++res;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main(){
	int a,b,f=0,c;
	for(;;){
		char word[80];
		for(a=0;;a++){
			if(scanf("%c",&word[a])==EOF){f=1;break;}
			if(word[a]==10){break;}
		}
		if(f==1){break;}
		for(a=0;a<26;a++){
			c=0;
			for(b=0;;b++){
				if(c==0 && word[b]=='t'){c++;}
				else if(c==1 && word[b]=='h'){c++;}
				else if(c==2 && word[b]=='e'){c++;}
				else if(c==3 && word[b]==' '){break;}
				else if(c==2 && word[b]=='a'){c=4;}
				else if(c==4 && word[b]=='t'){c++;}
				else if(c==5 && word[b]==' '){break;}
				else if(c==2 && word[b]=='i'){c=6;}
				else if(c==6 && word[b]=='s'){c++;}
				else if(c==7 && word[b]==' '){break;}
				else{c=0;}
				if(word[b]==10){break;}
			}
			if(c!=0){
				for(b=0;;b++){
					printf("%c",word[b]);
					if(word[b]==10){break;}
				}
				break;
			}
			else{
				for(b=0;;b++){
					if(word[b]==122){word[b]=97;}
					else if(word[b]>=97 && word[b]<122){word[b]++;}
					else if(word[b]==10){break;}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)
//#define int long long
using namespace std;
 
int power(int a, int n) {
	int ret = 1;
	for (int i = 0; i < n; i++) {
		ret *= a;
	}
	return ret;
}
 
int n;
vector<int> oks;
int dp[100001];
 
signed main() {
	int i, j;
	
	cin >> n;
	for (i = 0; power(6, i) <= n; i++) oks.push_back(power(6, i));
	for (i = 0; power(9, i) <= n; i++) oks.push_back(power(9, i));
	
	for (i = 0; i <= n; i++) dp[i] = 114514;
	
	dp[0] = 0;
	for (i = 0; i < n; i++) {
		for (j = 0; j < oks.size(); j++) {
			int nxt = i + oks[j];
			if (nxt > n) continue;
			dp[nxt] = min(dp[nxt], dp[i] + 1);
		}
	}
	
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;

int main() {
  string S;
  cin >> S;

  int cnt = 0;
  if(S[0]=='o') ++cnt;
  if(S[1]=='o') ++cnt;
  if(S[2]=='o') ++cnt;

  cout<<(700+100*cnt)<<endl;



  return 0;

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.awt.Point;

public class Main {
    static int INF = (1 << 30) - 1;
    // static long L_INF = (1L << 62) - 1;
    // static long MOD = (long) 1e9 + 7;

    static class Solver {
        int n;
        ArrayList<ArrayList<Integer>> g;
        int[] d;
        int[] f;
        int time;

        void rec(int v) {
            if (d[v] != INF) {
                return;
            }
            d[v] = time;
            time++;
            for (int i = 0; i < g.get(v).size(); i++) {
                int newV = g.get(v).get(i);
                rec(newV);
            }
            f[v] = time;
            time++;
            return;
        }

        // write your code
        void solve(InputReader in, PrintWriter out) {
            n = in.nextInt();
            g = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                ArrayList<Integer> al = new ArrayList<>();
                int u = in.nextInt() - 1;
                int k = in.nextInt();
                for (int j = 0; j < k; j++) {
                    int v = in.nextInt() - 1;
                    al.add(v);
                }
                g.add(al);
            }
            d = new int[n];
            Arrays.fill(d, INF);
            f = new int[n];
            Arrays.fill(f, INF);
            for (int i = 0; i < n; i++) {
                if (d[i] == INF) {
                    rec(i);
                }
            }

            for (int i = 0; i < n; i++) {
                out.printf("%d %d %d\n", i + 1, d[i] + 1, f[i] + 1);
            }
        }

        void debug(Object... os) {
            System.err.println(Arrays.deepToString(os));
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}



Measured memory_bytes: 25364
#include<bits/stdc++.h>

using namespace std;

int main(){
  int n;
  cin >> n;

  vector<string> s(n);
  map<string,long long> mp;

  string l;
  long long ans=0;
  for(int i =0; i < n; i++){
    cin >> l;
    sort(l.begin(),l.end());
    ans+=mp[l]++;
  }
  cout << ans << endl;
}




Measured memory_bytes: 12032
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	
	if (K >= (1 << N)) {
		cout << -1 << endl;
		return 0;
	}
	if (N == 1) {
		if (K == 1) {
			cout << -1 << endl;
			return 0;
		}
		else {
			cout << "0 0 1 1" << endl;
			return 0;
		}
	}
	int n = (1 << N);
	vector<int> res;
	for (int i = 0; i < n; i++) {
		if (i != K) {
			res.push_back(i);
		}
	}
	res.push_back(K);
	for (int i = n - 1; i >= 0; i--) {
		if (i != K) {
			res.push_back(i);
		}
	}
	res.push_back(K);
	for (int i = 0; i < res.size(); i++) {
		if (i > 0)cout << " ";
		cout << res[i];
	}
	cout << endl;
}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    vector <ll> X(N), A(N);
    ll start=0;
    loop(i,0,N) {cin >> X[i]; start^=X[i];}
    loop(i,0,N)
    {
        A[i]=X[i]^start;
    }
    loop(i,0,N) cout << A[i] << " ";cout << "\n";
    return 0;
}

Measured memory_bytes: 6360
#include<iostream>

int main() {
	int n, ans = 0;
	std::cin >> n;
	int *h = new int[n];
	for (int i = 0; i < n; i++) {
		std::cin >> h[i];
		bool flag = true;
		for (int j = 0; j < i; j++) {
			if (h[j] > h[i])flag = false;
		}
		ans += flag;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	static int a;
	static int b;
	static int c;
	static int x;
	private static Scanner sc;
	public static void main(String[]agrs){
		sc=new Scanner(System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		for(;a<=b;a++){
			if(c%a==0){
				x=x+1;
			}
			
		}
		System.out.println(x);

		
		
	}
}

Measured memory_bytes: 17328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl c(n), s(n), f(n);
  rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];
  rep(i, n) {
    ll ans = 0;
    rep2(j, i, n - 1) ans = (max(ans, s[j]) + f[j] - 1) / f[j] * f[j] + c[j];
    cout << ans << '\n';
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;

    vector<vector<int>> g(n);
    rep(i, 0, n - 1)
    {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }

    g[x].push_back(y);
    g[y].push_back(x);

    vector<vector<int>> res(n, vector<int>(n, 0)); // res[node][length]

    rep(i, 0, n)
    {
        vector<bool> seen(n, false);
        vector<int> dist(n, 0);
        queue<int> q;
        seen[i] = true;
        q.push(i);

        int idx = i;
        while (!q.empty())
        {
            rep(k, 0, g[idx].size())
            {
                if (!seen[g[idx][k]]) 
                {
                    seen[g[idx][k]] = true;
                    q.push(g[idx][k]);
                    dist[g[idx][k]] = dist[idx] + 1;
                    res[i][dist[idx] + 1]++;
                }
            }
            // cout << q.front() << endl;
            q.pop();
            idx = q.front();
        }
    }

    rep(i, 1, n)
    {
        ll ans = 0L;
        rep(k, 0, n)
        {
            ans += res[k][i];
        }
        cout << ans / 2 << endl;
    }
}


Measured memory_bytes: 16128
#include<stdio.h>
int main(){
  long long s;
  int n,i;
  while(scanf("%d",&n),n){
    s=0;
    for(i=1;i*i<n;i++){
      if(n%i)continue;
      s+=i+n/i;
    }
    if(i*i==n)s+=i;
    if(s==n*2)printf("perfect number\n");
    if(s> n*2)printf("abundant number\n");
    if(s< n*2)printf("deficient number\n");
  }
  return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n";
#define m 1000000000000000000



int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);


    long double ans = 1;
    int n;
    cin >> n;
    ll t;
    for (int i = 0; i < n; i++) {
        cin >> t;
        ans = ans * t;
        if(ans > m)ans = -1;
        if(t == 0)ans = 0;
        if(ans < 0)ans = -1;
   }

   cout << (ll)ans << endl;






}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _006_B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nx = ReadInts();
            int n = nx[0];
            int x = nx[1];
            if (x == 1 || x == 2 * n - 1)
            {
                Console.WriteLine("No");
                return;
            }

            var nums = new List<int>();
            for (int i = 0; i < 2 * n - 1; i++)
            {
                nums.Add(i + 1);
            }
            if (n > 2)
            {
                if (x == 2 * n - 2)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        nums.RemoveAt(x - 3);
                    }
                    nums.Insert(n - 2, x - 2);
                    nums.Insert(n - 1, x);
                    nums.Insert(n, x + 1);
                    nums.Insert(n + 1, x - 1);
                }
                else
                {
                    for (int i = 0; i < 4; i++)
                    {
                        nums.RemoveAt(x - 2);
                    }
                    nums.Insert(n - 2, x + 1);
                    nums.Insert(n - 1, x);
                    nums.Insert(n, x - 1);
                    nums.Insert(n + 1, x + 2);
                }
            }
            Console.WriteLine("Yes");
            for(int i = 0; i < nums.Count; i++)
            {
                Console.WriteLine(nums[i]);
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 18140
#include <iostream>
#include <climits>
using namespace std;

int main()
{
    int Max=INT_MIN, Min=INT_MAX;
    int Num;
    
    while(cin >> Num)
    {
        if(Max < Num) Max = Num;
        if(Min > Num) Min = Num;
    }
    
    cout << Min << " " << Max << endl;
    
}


Measured memory_bytes: 3120
// (c) 2020, redotter

// Roses are red
// The Tardis is blue
// The Doctor once said
// Rose Tyler...

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#pragma comment(linker, "/stack:500000000")
#endif

#define pb push_back
#define the(a) (a).begin(), (a).end()
#define ft first
#define sd second
#define endl "\n"
#define forn(i, n) for (int i = 0; i < (n); i++)
#define forr(i, s, n) for (int i = (s); i < (n); i++)

using i64 = long long;
using i32 = int;
using f64 = long double;

template <class T> using vec = vector<T>;
using str = string; using p64 = pair<i64, i64>;
using v64 = vec<i64>; using vv64 = vec<v64>;
using s64 = set<i64>; using m64 = map<i64, i64>;
template <size_t Size1> using a64 = array<i64, Size1>;
template <size_t Size1, size_t Size2> using aa64 = array<a64<Size2>, Size1>;
template <class T> using hash_set = unordered_set<T>;
template <class T, class U> using hash_map = unordered_map<T, U>;

mt19937 gen(998244353);
const i64 inf = numeric_limits<i64>::max() / 2;

template <class T> inline i64 len(const T& a) { return (i64)(a.size()); }
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <class T, class S>
inline bool check_min(T& a, S b) { if (a > b) return a = b, 1; return 0; }
template <class T, class S>
inline bool check_max(T& a, S b) { if (a < b) return a = b, 1; return 0; }

void read() {}
template<class T, class ...U>
void read(T& a, U& ...b) { cin >> a; read(b...); }
void print() {}
template<class T, class ...U>
void print(const T& a, const U& ...b) { cout << a << " "; print(b...); }
void println() { cout << "\n"; }
template<class T, class ...U>
void println(const T& a, const U& ...b) { cout << a << " "; println(b...); }

struct Problem {
	void files(str in, str out) {
#ifdef ONLINE_JUDGE
		freopen(in.c_str(), "r", stdin), freopen(out.c_str(), "w", stdout);
#endif
	}
	void solve(), input();
	void many() { i32 t; cin >> t; while (t--) input(), solve(); }
	void make(bool mt = 0) { if (mt) many(); else input(), solve(); }
} problem;

signed main() {
	fast();
	problem.make();
#ifdef _DEBUG
	println(); println("[finished]"); system("pause > nul");
#endif
	return 0;
}

#define ws ws_is_cool

i64 n, W;
v64 ws, vs;

void Problem::solve() {
	vv64 dp(n + 1, v64(W + 1, -inf));
	dp[0][0] = 0;
	forr(i, 1, n + 1) {
		forn(j, W + 1) {
			dp[i][j] = dp[i - 1][j];
			if (j >= ws[i]) {
				check_max(dp[i][j], dp[i - 1][j - ws[i]] + vs[i]);
			}
		}
	}
	i64 ans = -inf;
	forn(j, W + 1) {
		check_max(ans, dp[n][j]);
	}
	println(ans);
}

void Problem::input() {
	read(n, W);
	ws.resize(n + 1), vs.resize(n + 1);
	forr(i, 1, n + 1) {
		read(ws[i], vs[i]);
	}
}


Measured memory_bytes: 83052
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, A, B;
    A = 0;
    B = 0;
    cin >> N;
    vector<int>list(N);

    for(int i=0;i<N;i++){
        cin >> list.at(i);
    }

    sort(list.begin(), list.end());
    reverse(list.begin(), list.end());

    for(int i = 0; i < N;i+=2)
    {
        A += list.at(i);
        if(i<N-1)
            B += list.at(i + 1);
    }

    cout << A - B;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#define PI 3.141592653589793238462643383279502884197

using namespace std;

int a, b, c;

int main() {
    cin >> a >> b >> c;
    double S, L, h;
    S = 0.5 * a * b * sin((2*PI)*c/360);
    L = sqrt(a * a + b * b - (2 * a * b * cos((2*PI)*c/360))) + a + b;
    h = b * sin((2*PI)*c/360);
    printf("%.7f %.7f %.7f\n", S, L, h);
}


Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K, x = 1;
  cin >> N >> K;
  
  for ( int i = 0; i < N; i++ ) {
    if ( x > K ) x += K;
    else x *= 2;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  char c;
  int ans=700;
  rep(i,3){
    cin>>c;
    if(c=='o') ans+=100;
  }
  cout<<ans<<endl;
  return 0;
}






Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def nasu(x):
  t = make_divisors(x)
  c = 0
  for i in t:
    c += D[i]
  return c

def honya(x):
  y = 0
  k = 1
  for i in range(x - 1, -1, -1):
    if X[i]:
      y = (y + k) % MOD
    k = (k * 2) % MOD
  return y + honyaraka(x)

def honyaraka(x):
  cnt = 0
  for i in range(N // x):
    t = i % 2
    for j in range(x):
      if X[cnt] != (X[j] ^ t):
        if X[cnt] == 0:
          return 0
        else:
          return 1
      cnt += 1
  return 1


N = int(input())
X = list(map(int, input()))
MOD = 998244353

Y = 0
k = 1
for i in range(N - 1, -1, -1):
  if X[i]:
    Y = (Y + k) % MOD
  k = (k * 2) % MOD

D = [0] * (N + 1)
L = make_divisors(N)

cnt = 0
for i in L:
  if i != N and (N // i) % 2 == 1:
    D[i] = honya(i) - nasu(i)
    cnt += D[i]

D[N] = Y - cnt + 1

ans = 0
for i in L:
  ans = (ans + D[i] * i * 2) % MOD

print(ans)

Measured memory_bytes: 48216
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N;
    cin >> N;
    vll A(N);
    rep(i,N) cin >> A[i];

    ll MOD = 1e9+7;

    ll sum = 0;
    ll memo = 0;
    rep(i,N-1){
        memo += A[i];
        memo %= MOD;
        sum += (memo * A[i+1])%MOD;
        sum %= MOD;
    }
    
    cout << sum << endl;
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll k,a,b;

// int dfs(int k,int haveb,int havey){
// 	if(!k) return haveb;
// 	if(havey) haveb+=b,havey--;
// 	else if(haveb<a||k==1) haveb+=1;
// 	else haveb-=a,havey+=1;
// 	printf("k:%d\n",k);
// 	dfs(k-1,haveb,havey);
// }

ll solve(ll k,ll haveb,ll havey){
	for(int i=k;i>0;i--){
		if(havey) haveb+=b,havey--;
		else if(haveb<a||i==1) haveb+=1;
		else haveb-=a,havey+=1;
	}
	return haveb;
}

int main(){
	while(scanf("%lld%lld%lld",&k,&a,&b)!=EOF){
		if(k<=a||b<=a||b-a==1) printf("%d\n",k+1);
		else printf("%lld\n",solve(k,1,0));
		}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NY = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NY[0];
            var Y = NY[1];

            for (var i = 0; i <= N; i++)
            {
                for (var j = 0; j <= N - i; j++)
                {
                    var k = N - i - j;
                    var money = i * 10000 + 5000 * j + 1000 * k;
                    if (money == Y)
                    {
                        Console.WriteLine($"{i} {j} {k}");
                        return;
                    }
                }
            }

            Console.WriteLine("-1 -1 -1");
        }
    }
}


Measured memory_bytes: 13396
L,R = map(int,input().split())
 
cnt = 0
i = L
j = L+1
min_num = 2020
while i <= R and cnt <= 2019:
    j = i+1
    while j <= R:
        min_num = min(min_num,(i*j)%2019)
        if not min_num:
            break
        j += 1
    i += 1
    cnt += 1
print(min_num)

Measured memory_bytes: 3064
///////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <typeinfo>

using namespace std;

///////////////////////////////////////////////////////////////////////////////

#define pb push_back

struct T2 {
        long t0;
        long t1;
};

struct T3 {
        long t0;
        long t1;
        long t2;
};

void longin(long &a)
{
        cin >> a;
}

void longinl1(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a;
                cin >> a;
                v.push_back(a);
        }
}

void longinl2(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a, b;
                cin >> a >> b;
                v.push_back({a, b});
        }
}

void longinl3(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a, b, c;
                cin >> a >> b >> c;
                v.push_back({a, b, c});
        }
}

void longina(auto &v, long count)
{
        longinl1(v, count);
}

long min(const vector<long> v)
{
        long ret = (long)numeric_limits<double>::infinity();
        for (auto i : v) ret = min(ret, i);
        return ret;
}

///////////////////////////////////////////////////////////////////////////////

static long nn;
static long mod = pow(10, 9) + 7;

bool ok(const string &last4)
{
        string last3 = string(last4, 1, 3);
        string last2 = string(last4, 2, 2);
        string first2 = string(last4, 0, 2);

        if (last3 == "AGC") return false;
        if (last3 == "ACG") return false;
        if (last3 == "GAC") return false;
        if (last4[0] == 'A' && last2 == "GC") return false;
        if (last4[3] == 'C' && first2 == "AG") return false;

        return true;
}

long dfs(long cur, const string & last3)
{
        static map<string, long> *memo = new map<string, long>[nn+1];
        if (memo[cur].count(last3) > 0) {
                return memo[cur][last3];
        }

        if (cur == nn) return 1;

        long ret = 0;
        for (const char &c : "ACGT") {
                if (c == 0) continue;
                string cs = string(1, c);
                if (ok(last3 + cs)) {
                        ret = (ret + dfs(cur + 1, string(last3, 1, 2) + cs)) % mod;
                }
        }

        memo[cur][last3] = ret;
        return ret;
}

int main()
{
        long n;
        longin(n);
        nn = n;

        cout << dfs(0, "TTT");

        return 0;
}

///////////////////////////////////////////////////////////////////////////////


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int MOD = 1e9+7;
int dp[2001];
int solve( int s ){
    if(s<0){
        return 0;
    }
    if(s==0){
        return 1;
    }
    int &ans =dp[s];
    if(ans!=-1)return ans;
    ans = 0 ;
    for(int i = 3 ; i<=s ; i ++){
        ans+=solve(s-i);
        ans%=MOD;
    }
    return ans;
}
int main(){
    int s ;
    cin>>s;
    memset(dp,-1,sizeof(dp));
    cout<<solve(s)<<endl;
}

Measured memory_bytes: 3632
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    int a,b;
    cin>>a>>b;
    cout<<(a+b+1)/2<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

/*
0-index
functionの中を書いて使う
segtree<ll> seg(n, [](ll a, ll b){return a + b;}, 0);
*/
template<typename T>
struct segtree{
	int n;
	vector<T> dat;
	T ZERO;
	function<T(T,T)> func;//要素と要素をマージする関数

	segtree(int n_, function<T(T,T)> func_, T zero):func(func_), ZERO(zero){
	  n = 1;
	  while(n < n_)n*=2;
	  dat.resize(2*n);
	  for(int i = 0;i < 2*n;i++)dat[i] = ZERO;
	}

	void update(int k, T a){
	  k += n - 1;dat[k] = a;
	  while(k > 0){
		k = (k-1)/2;
		dat[k] = func(dat[k*2+1],dat[k*2+2]);
	  }
	}

	void set(int k, T a) {
		k += n - 1;dat[k] = a;
	}

	void build(){
		for(int i = n - 2;i >= 0;i--){
			dat[i] = func(dat[2 * i + 1], dat[2 * i + 2]);
		}
	}

	T get(int k){return dat[k+n-1];}

	T que(int a,int b){
		T L = ZERO,R = ZERO;
		int A = a + n - 1;
		int B = b + n - 1;
		while(A < B){
			if((A & 1) == 0)L = func(L,dat[A++]);
            if((B & 1) == 0)R = func(dat[--B],R);
            A = A >> 1;
            B = B >> 1;
		}
		return func(L,R);
	}
};

void compression(vector<P> &v){
	int n = v.size();
	vector<ll> x(n);
	vector<ll> y(n);
	REP(i, n) {
		x[i] = v[i].FI;
		y[i] = v[i].SE;
	}

	sort(ALL(x));
	sort(ALL(y));
	x.erase(unique(ALL(x)), x.end());
	x.erase(unique(ALL(y)), y.end());

	REP(i, n){
		v[i].FI = lower_bound(ALL(x), v[i].FI) - x.begin();
		v[i].SE = lower_bound(ALL(y), v[i].SE) - y.begin();
	}
}

ll twoPow[222222];

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

	twoPow[0] = 1;
	REP(i, 222222 - 1)twoPow[i+1] = twoPow[i] * 2 % MOD;

	int n;cin >> n;
	vector<P> v(n);
	REP(i, n)cin >> v[i].FI >> v[i].SE;
	compression(v);

	segtree<ll> seg(n, [](ll a, ll b){return a + b;}, 0);

	sort(ALL(v));

	ll ans = twoPow[n-1] * n % MOD;
	REP(i, n){
		ll xy = seg.que(0, v[i].SE);
		ll Xy = v[i].SE - xy;
		ll xY = seg.que(v[i].SE, n);
		ll XY = (n - v[i].SE - 1) - xY;
		REP(j, (1 << 4)){
			ll tmp = 1;
			if(j & (1 << 0))tmp = (tmp * (twoPow[xy] + MOD - 1)) % MOD;
			if(j & (1 << 1))tmp = (tmp * (twoPow[Xy] + MOD - 1)) % MOD;
			if(j & (1 << 2))tmp = (tmp * (twoPow[xY] + MOD - 1)) % MOD;
			if(j & (1 << 3))tmp = (tmp * (twoPow[XY] + MOD - 1)) % MOD;
			if(((j & 9) == 9) || ((j & 6) == 6)){
				ans = (ans + tmp) % MOD;
			}
		}

		seg.update(v[i].SE, 1);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9288
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define int ll

static const int INF = 2147483647;

int h[114514];
int n,a,b;

bool expl(int m){
    int ret = 0;
    REP(i,n){
        int cur = h[i];
        if(cur <= m*b) continue;
        else cur -= m*b;
        ret += (cur+(a-b)-1)/(a-b);
    }
    return (ret<=m);
}

signed main(){
    scanf("%lld%lld%lld",&n,&a,&b);
    REP(i,n) scanf("%lld",&h[i]);
    int high = INF, low = -1;
    while(high-low>1){
        //printf("%lld %lld\n",high,low);
        int mid = (high+low)/2;
        if(expl(mid)) high = mid;
        else low = mid;
        //printf("%lld %lld\n\n",high,low);
    }

    printf("%lld\n",high);

    return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

// UnionFind is union find structure
type UnionFind struct {
	Par []int
}

// NewUnionFind generates a new union find
func NewUnionFind(n int) *UnionFind {
	uf := &UnionFind{make([]int, n)}
	for i := range uf.Par {
		uf.Par[i] = i
	}
	return uf
}

// Root searches the root of the arguement
func (uf *UnionFind) Root(x int) int {
	if x == uf.Par[x] {
		return x
	}
	uf.Par[x] = uf.Root(uf.Par[x]) // 経路圧縮
	return uf.Par[x]
}

// Unite unites two trees by adding one root to another
func (uf *UnionFind) Unite(x, y int) {
	rx := uf.Root(x)
	ry := uf.Root(y)
	if rx == ry {
		return
	}
	uf.Par[rx] = ry
}

// Same returns true when the two are in the same group
func (uf *UnionFind) Same(x, y int) bool {
	return uf.Root(x) == uf.Root(y)
}

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)
	uf := NewUnionFind(n)

	friends := make(map[int]int)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		uf.Unite(a-1, b-1)
		friends[a-1]++
		friends[b-1]++
	}

	sizes := make([]int, n)
	for i := range sizes {
		r := uf.Root(uf.Par[i])
		sizes[r]++
	}

	blocks := make([]int, n)
	for i := 0; i < k; i++ {
		var c, d int
		fmt.Scan(&c, &d)
		if uf.Same(c-1, d-1) {
			blocks[c-1]++
			blocks[d-1]++
		}
	}

	for i := 0; i < n; i++ {
		ans := sizes[uf.Root(i)] - friends[i] - blocks[i] - 1
		fmt.Printf("%v ", ans)
	}
	fmt.Println()
}


Measured memory_bytes: 13952