akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int MAX = 200060;
const double pi = acos(-1);
const ll INF = 1e16;


int num[300030];
int cnt[300030];
int cum[300030];
void solve() {
	int N; cin >> N;

	REP(i, N) {
		int x; cin >> x;
		x--;
		cnt[x]++;
	}
	REP(i, N) {
		num[cnt[i]]++;
	}
	REPR(i, N) {
		cum[i] = num[i];
		cum[i] += cum[i + 1];
	}
	int sum = N;
	ll ans = N;
	int now = N;
	FOR(k,1,N+1){
		bool ok = false;
		if (ans*k <= sum)ok = true;
		while (!ok) {
			sum -= cum[ans];
			ans--;
			if (ans*k <= sum) { ok = true; break; }
		}
		print(ans);
	}
}


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

	solve();
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<long long int,long long int>
#define vi vector<long long int >
#define vvi vector<vector< long long int>>
#define MP make_pair
#define PB push_back 
#define pb pop_back
#define PF push_front
#define pf pop_front
#define MOD 1000000007
#define MT make_tuple

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	ll a[n],b[n],c[n],d[n],maxa=-1e18,maxb=-1e18,maxc=-1e18,maxd=-1e18;
	for(ll i=0;i<n;i++)
	{
		ll x,y;
		cin>>x>>y;
		a[i]=x+y;
		b[i]=x-y;
		c[i]=y-x;
		d[i]=-x-y;
		maxa=max(maxa,a[i]);
		maxb=max(maxb,b[i]);
		maxc=max(maxc,c[i]);
		maxd=max(maxd,d[i]);
	}
	ll ans=-1e18;
	ans=max(ans,maxa+maxd);
	ans=max(ans,maxb+maxc);
	cout<<ans<<endl;
    return 0;
}
			

Measured memory_bytes: 9856
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
	while(1){
		int h, w;
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		rep(i, h){
			rep(j, w){
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}



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

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

    vector<pair<long long int, int>> prime_power;
    for (long long int p=2; p*p<=n; p++) {
        if(n % p != 0) continue;// break and proceed to p+1

        int power = 0;
        while(n % p == 0){
            power += 1;
            n /= p;
        }
        prime_power.push_back(make_pair(p, power));
    }

    // n has been divided by all primes (with power) smaller than sqrt(n)
    if(n != 1){
        prime_power.push_back(make_pair(n, 1));
    }

    
    int ans = 0;
    for(auto pp : prime_power){
        int rem = pp.second, times = 0;
        while(rem >= 0){
            times += 1;
            rem -= times;
        }
        ans += times - 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int ex = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'o') ex++;
  }
  cout << 700 + 100 * ex << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, m;
ll a[10];
ll dp[10101]; // ちょうどi本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
ll num[10]={inf, 2, 5, 5, 4, 5, 6, 3, 7, 6}; // 整数iを作るために使うマッチの本数
int main() {
    cin >> n >> m;
    REP(i, 0, m) cin >> a[i];

    sort(a, a + m);
    dp[0] = 0;
    REP(i, 1, 10101) dp[i] = -inf;
    REP(i, 1, n + 1) {
        REP(j, 0, m) {
            if (i - num[a[j]] >= 0) {
                dp[i] = max(dp[i], dp[i - num[a[j]]] + 1);
            }
        }
    }

    string ans = "";
    ll match = n;
    REP(i, 0, dp[n]) {
        RREP(j, 0, m) {
            if (match - num[a[j]] >= 0) {
                if (dp[match - num[a[j]]] == dp[match] - 1) {
                    ans += to_string(a[j]);
                    match -= num[a[j]];
                    break;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<int>> x(h, vector<int>(w)), y(h, vector<int>(w));
    rep(i,h) {
        rep(j,w) {
            if (s[i][j] == '#') continue;
            int l = 0;
            l = j;
            while (j < w && s[i][j] == '.') j++;
            int r = j;
            for (int k = l; k <= r-1; k++) x[i][k] = r-l; 
        }
    }
    rep(j,w) {
        rep(i,h) {
            if (s[i][j] == '#') continue;
            int l = 0;
            l = i;
            while (i < h && s[i][j] == '.') i++;
            int r = i;
            for (int k = l; k <= r-1; k++) y[k][j] = r-l; 
        }
    }
    int ans = 0;
    rep(i,h)rep(j,w) {
        if (s[i][j] == '#') continue;
        ans = max(x[i][j]+y[i][j]-1, ans);
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 42324
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>

using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define ull unsigned long long
#define ll long long
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}

int N;

ll gcd(ll a, ll b){
	if(a==0) return b;
	return gcd(b%a, a);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> N;

	if(N%4 == 0) {
		int k = N/4;
		ll sm = 0;
		for(int i=0;i<k;++i) {
			int three = (2*i+1)*3;
			cout << three-1 << " " << three << " " << three+1 << " ";
			sm += 3*three;
			if (i<k-1) {
				cout << three+3 << " ";
				sm += (three+3);
			}
		}

		for(int i=(2*k-1)*3+3;;++i){
			if (gcd(sm,i) > 1 && ((sm+i)%6==0) ) {
				cout << i << endl;
				return 0;
			} 
		}

	} else if(N%4==1) {
		int k = N/4;
		ll sm=0;
		for(int i=0;i<k;++i) {
			int three = (2*i+1)*3;
			cout << three-1 << " " << three << " " << three+1 << " " << three+3;
			cout << " ";
			sm += 4*three+3;			
		}
		for(int i=(2*k+1)*3-1;;++i){
			if (gcd(sm,i) > 1 && ((sm+i)%6==0) ) {
				cout << i << endl;
				return 0;
			} 
		}

	} else if (N%4==2) {
		int k = N/4;
		ll sm = 0;
		for(int i=0;i<k;++i) {
			int three = (2*i+1)*3;
			cout << three-1 << " " << three << " " << three+1 << " " << three+3;
			cout << " ";		
			sm += 4*three+3;	
		}

		cout << (2*k+1)*3 << " ";
		sm += (2*k+1)*3;
		for(int i=(2*k+1)*3-1;;++i){
			if(i == (2*k+1)*3) continue;
			if (gcd(sm,i) > 1 && ((sm+i)%6==0) ) {
				cout << i << endl;
				return 0;
			} 
		}

	} else {
		if (N == 3) {
			cout << 2 << " " << 3 << " " << 25 << endl;
			return 0;
		}
		if (N == 19999) {
			int k = N/4;
			ll sm = 0;
			for(int i=0;i<k;++i) {
				int three = (2*i+1)*3;
				cout << three-1 << " " << three << " " << three+1 << " " << three+3;
				cout << " ";		
				sm += 4*three+3;	
			}
			cout << (2*k+1)*3-1 << " " << (2*k+1)*3 << " ";
			sm += 2*(2*k+1)*3-1;
			for (int i=(2*k+1)*3-1;;++i) {
				if (i==(2*k+1)*3-1 || i== (2*k+1)*3) continue;
				if (gcd(sm,i) > 1 && ((sm+i)%6==0) ) {
					cout << i << endl;
					return 0;
				}			
			}						
		} else {
			int k = N/4;
			ll sm = 0;
			for(int i=0;i<k;++i) {
				int three = (2*i+1)*3;
				cout << three-1 << " " << three << " " << three+1 << " " << three+3;
				cout << " ";		
				sm += 4*three+3;	
			}
			cout << (2*k+1)*3 << " " << (2*k+1)*3+3 << " ";
			sm += 2*(2*k+1)*3+3;
			for (int i=(2*k+1)*3-1;;++i) {
				if (i==(2*k+1)*3 || i== (2*k+1)*3+3) continue;
				if (gcd(sm,i) > 1 && ((sm+i)%6==0) ) {
					cout << i << endl;
					return 0;
				}			
			}		
		}	
	}
}

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

int main() {
  string s; cin >> s;
  int ans = 0;
  int tmp = 0;
  for (int s_i = 0; s_i < s.size(); ++s_i) {
    char c = s[s_i];
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
      ++tmp; 
      ans = max(ans, tmp);
    }
    else tmp = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 764
s = input()
t = input()
x = len(s) - len(t) + 1
y = len(t)
lst = []
for i in range(x):
  c = 0
  for j in range(y):
    if (t[j] != s[j + i]):
      c = c + 1
  lst.append(c)
lst2 = sorted(lst)
print(lst2[0])

Measured memory_bytes: 9116
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

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

    ll ans = ((n - 1) * ((n - 1) + 1)) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,i,l[60],sum=0;
	priority_queue <int> pq;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
		pq.push(l[i]);
	}
	for(i=0;i<k;i++){
		sum+=pq.top();
		pq.pop();
	}
	printf("%d",sum);
}

Measured memory_bytes: 256
from bisect import bisect_left
N=int(input())
C=[int(input()) for i in range(N)]
mod=10**9+7
data=[[] for i in range(max(C)+1)]
for i in range(N):
    data[C[i]].append(i)
dp=[0]*N
dp[0]=1
for i in range(1,N):
    h=data[C[i]]
    b=bisect_left(h,i)
    if b==0:
        dp[i]=dp[i-1]
    elif C[i]==C[i-1]:
        dp[i]=dp[i-1]
    else:
        dp[i]=(dp[i-1]+dp[h[b-1]])%mod
print(dp[-1]%mod)

Measured memory_bytes: 81700
#include <stdio.h>

int main(){
	char S[11];
	char A[11]={};
	int x=0;

	scanf("%s",&S);
	for(int i=0;i<11;i++){
		if(S[i]=='0'){
			A[x]='0';
			x++;
		}
		else if(S[i]=='1'){
			A[x]='1';
			x++;
		}
		else if(S[i]=='B'){
			if(x!=0)
				x--;
		}

	}
	for(int i=0;i<x;i++){
		printf("%c",A[i]);
	}
	printf("\n");\
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        int n = in.nextInt();
        int last = -1;
        int res = 0;
        for (int i = 0; i < n; i++) {
            int cur = in.nextInt();
            if (cur == last) {
                res++;
                last = -1;
            } else {
                last = cur;
            }
        }
        out.println(res);
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

vector<bool> seen(200010, false);
vector<ll> ans(200010);
vector<ll> P(200010);
ll now;

void dfs(const Graph& G, int v) {
  ans[v] += P[v];
  seen[v] = true;
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue;
    ans[next_v] += ans[v];
    dfs(G, next_v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  Graph G(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i, q) {
    int p;
    ll x;
    cin >> p >> x;
    p--;
    P[p] += x;
  }
  dfs(G, 0);
  rep(i, n) cout << ans[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 25856
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const int INF = 1 << 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    vector<vector<int>> dp(1 << N, vector<int>(55, INF));
    dp[0][0] = 0;
    rep(mask, 0, 1 << N) {
        int card_num = __builtin_popcount(mask);
        vector<P> ords;
        int iter = card_num;
        rep(i, 0, N) {
            if (!((mask >> i) & 1)) {
                ords.emplace_back(i, iter++);
            }
        }
        rep(s, 0, 55) {
            if (dp[mask][s] == INF) {
                continue;
            }
            for (auto p : ords) {
                int ns = -1;
                if (abs(p.first - card_num) % 2 == 0) {
                    ns = A[p.first];
                }
                else {
                    ns = B[p.first];
                }
                if (ns >= s) {
                    chmin(dp[mask | (1 << p.first)][ns], dp[mask][s] + abs(p.second - card_num));
                }
            }
        }
    }
    int ans = INF;
    rep(s, 0, 55) {
        chmin(ans, dp[(1 << N) - 1][s]);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 67968
#include <stdio.h>

int main(void){
	int N, i, j, v, m;
	scanf("%d", &N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d", &A[i]);
	}
			for(m=0; m<N; m++){
			printf("%d", A[m]);
			if(m < N-1){
				printf(" ");
			}else printf("\n");
		}
	for(i=1;i<N;i++){
		v = A[i];
		j = i -1;
		while(j>=0 && A[j] > v){
			A[j+1] = A[j];
			j--;
			A[j+1] = v;
		}
		for(m=0; m<N; m++){
			printf("%d", A[m]);
			if(m < N-1){
				printf(" ");
			}else printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 1932
using System;
using System.Collections.Generic;
using System.Linq;

namespace _0030
{
    class Program
    {

        
        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');

            int n = int.Parse(str[0]);
            int k = int.Parse(str[1]);

            long[] tree = new long[n];

            for(long i = 0; i < n; i++)
            {
                tree[i] = long.Parse(Console.ReadLine());
            }

            Array.Sort(tree);

            long result = long.MaxValue;

            for(int i = 0; i < n - k + 1; i++)
            {
                if(result > tree[i + k - 1] - tree[i])
                {
                    result = tree[i + k - 1] - tree[i];
                }
            }

            Console.WriteLine(result);


        }
    }
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

ll dx[]={0,0,1,-1,1,1,-1,-1};
ll dy[]={1,-1,0,0,1,-1,1,-1};

int main()
{
    ll n, k, ans = 0;
    cin >> n >> k;
    while(n--)
    {

        ll x;
        cin >> x;
        ll y = abs(x-k);
        ans+=min(x*2,y*2);
    }
    cout << ans;
}


Measured memory_bytes: 256
def comb(n, k, MOD):
    if n < k:
        return 0
    if n - k < k:
        k = n - k
    comb = 1
    for x in range(n - k + 1, n + 1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, k + 1):
        d = (d * x) % MOD
    comb *= pow(d, MOD - 2, MOD)
    return comb % MOD

def main():
    N = int(input())
    MOD = 10 ** 9 + 7
    M = N // 3
    ans = 0
    for i in range(1, M + 1):
        t = N - (i * 3)
        ans += comb(i - 1 + t, t, MOD)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 66584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}

int m[3333][3333];
int a[5555];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init(55555);
	int n,q; cin>>n>>q;
	for(int i=0;i<n;i++) 
	{
		cin>>a[i]; a[i]--;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			m[i][j]=(a[i]>a[j]?1:0);
		}
	}
	int factor = 1;
	for(int i=0;i<q;i++)
	{
		int x,y; cin>>x>>y; x--; y--;
		factor = mult(factor, 2);
		vector<int> tmp(n);
		for(int j=0;j<n;j++)
		{
			tmp[j] = mult(add(m[x][j],m[y][j]),inv[2]);
		}
		vector<int> col(n);
		for(int j=0;j<n;j++)
		{
			col[j]=mult(add(m[j][x],m[j][y]),inv[2]);
		}
		int c = mult(add(m[x][y],m[y][x]),inv[2]);
		//swap(m[x][y],m[y][x]);
		//m[x][y]=mult(m[x][y],inv[2]); m[y][x]=mult(m[y][x],inv[2]);
		for(int j=0;j<n;j++)
		{
			m[x][j]=m[y][j]=tmp[j];
			m[j][x]=m[j][y]=col[j];
		}
		m[x][y]=m[y][x]=c;
		m[x][x]=m[y][y]=0;
		/*
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cerr<<mult(factor, m[i][j])<<' ';
			}
			cerr<<'\n';
		}
		*/
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			ans = add(ans, mult(factor, m[i][j]));
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 42112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define popcount(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(false) , cin.tie(0) ;
#define w(x) cout << (#x) << " is " << x << "\n" ;
const char nl = '\n';

int main()
{
//    fast ;
//#ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
//#endif
    ll c=0,n,t,x,y;
    string s;
    cin >> n;
    cin >> s;
    ll i=0,j=n-1;
    while(i<j && i<n && j>=0)
    {
        if(s[i]=='W' && s[j]=='R')
        {
            i++,j--;
            c++;
        }
        else if(s[i]=='R')
        {
            if(s[j]=='W')
                j--;
            i++;
        }
        else if(s[i]=='W' && s[j]=='W')
            j--;
    }
    cout << c << "\n";

    return 0;


}


Measured memory_bytes: 3676
//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <map>
//#include <iostream>
//#include <algorithm>
//#include <set>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pli = pair<ll,int>; 		
#define fi first
#define v vector
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
int INF = 1e9+7;
ll inf = 1e18+7;
const int V = 100010;
//const int V = 100;

ll dp[V+1];

void solve(){
	for(int i = 0; i <= V; ++i){
		dp[i] = inf;
	}
	dp[0] = 0;
	int n;
	ll w;
	scanf("%d%lld",&n,&w);
	for(int item = 0; item < n; ++item){
		ll tw;
		int tv;
		scanf("%lld%d", &tw,&tv);
		
		for(int value = V - tv; value >= 0; --value){
			dp[value + tv] = min(dp[value + tv], dp[value] + tw);
		}
	}
		
	//for(auto x : dp){
		//cout << x << "  ";
	//}
	//cout << endl;
	int ans = 0;
	for(int i = V; i>= 0; --i){
		if(dp[i] <= w) {
			ans = i;
			break;
		}
	}
	printf("%d\n", ans);
	
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	//scanf("%d",&t);
	while(t--){
		solve();
	}
		
			
}


Measured memory_bytes: 4616
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a:number[]=[];for(let i=0;i<arg;i++) {a.push(t.n());}return a;}else{const a = t.input[0];t.input.shift();return Number(a);}},s:(arg:number=0):any=>{if(arg){const a:string[]=[];for(let i=0;i<arg;i++){a.push(t.s());}return a;}else{const a=t.input[0];t.input.shift();return String(a);}},c:(arg:number=0):any=>{if(arg) {const a:string[]=[];for(let i=0;i<arg;i++) {a.push(t.c());}return a;}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('');}else{t.input.shift();}return String(b);}},o: (...arg)=>{console.log(...arg);},abs:(a)=>{return Math.abs(a);},min:(...a)=>{return Math.min(...a);},max:(...a)=>{return Math.max(...a);},floor:(a)=>{return Math.floor(a);},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b});},desc:(ar:number[])=>{ return ar.sort((a,b)=>{return b-a});},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1]}return arr[arr.length-1];}}
const main = ()=>{
  let [a,b] = t.n(2)
  t.o(a*a-b)
}
main()

Measured memory_bytes: 9420
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::string s;
  cin>>s;
  std::vector<int> catcheck(s.size());
  int checknum=1;
  int n=s.size();
  while(1){
    bool updated=false;
    for(int i=0;i<n;i++){

      if(s[i]=='m'){
        int beginpos=i;
        for(i++;i<n;i++){
          if(s[i]=='e'&&catcheck[i]==0){
            for(i++;i<n;i++){
              if(s[i]=='w'&&catcheck[i]==0){
                int endpos=i;
                for(int j=beginpos;j<=endpos;j++){
                  catcheck[j]=checknum;
                }
                checknum++;
                updated=true;
                goto start;
              }else if(catcheck[i]==0){
                i--;
                goto start;
              }
            }
          }else if(catcheck[i]==0){
            i--;
            goto start;
          }
        }
      }
      start:
      int h;
    }
    if(!updated)break;

  }

  for(auto i:catcheck){
    if(i==0||catcheck.front()!=i){
      cout<<"Rabbit"<<endl;
      return 0;
    }
  }
  cout<<"Cat"<<endl;
  return 0;


  return 0;
}



Measured memory_bytes: 3208
#include<iostream>
#include<cstdio>
using namespace std;
int n,ans;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<4;i++) {
		if(n%10 == 2) ans++;
		n /= 10;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
N, K = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(N)]
td.sort(key=itemgetter(1), reverse=True)
t, d = zip(*td)

s = set()
q = []
tmp = 0
now = 0
for i in range(K):
    if t[i] not in s:
        s.add(t[i])
    else:
        q.append(d[i])

    tmp += d[i]
    now += 1
kind = len(s)
sums = [-100000000000]*(kind+1)
sums[kind] = tmp
for i in range(K, N):
    if not q:
        break
    if t[i] not in s:
        s.add(t[i])
        tmp = q.pop()
        kind += 1
        sums.append(sums[kind-1] + d[i] - tmp)
for i in range(len(sums)):
    sums[i] += i**2
print(max(sums))



Measured memory_bytes: 36108
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        s: chars
    }
    let mut t = s.clone();
    t.reverse();
    println!("{}",
        s.iter().zip(t.iter()).filter(|&(i,j)| i != j).count() / 2);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int n,l;
	vector<int> b;
	vector<int> a;
	cin >> n;
	l = n;
	for(int i=0;i<n;++i){
		int k;
		cin >> k;
		b.push_back(k);
	}
	for(int i=0;i<n;++i){
		for(int j=l-1;j>=0;--j){
			if(b[j] == j+1){
				a.push_back(j+1);
				b.erase(b.begin() + j);
				l--;
				break;
			}
		}
	}
	reverse(a.begin(),a.end());
	if(a.size() == n){
		for(int i=0;i<n;++i)cout << a[i] << endl;
	}else{
		cout << -1 << endl;
	}
}

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

using namespace std;

bool areDiff(int a, int b, int c) {
    if(a == b || b == c || c == a) return false;
    return true;
}
bool areTri(int a, int b, int c) {
    if((a + b > c) && (a + c > b) && (c + b > a)) return true;
    return false;
}   

int main() {
    long long n;
    cin >> n;
    vector<long long> l(n);
    for(int i = 0; i < n; i++) {
        cin >> l[i];
    }
    long long total = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
           for(int k = j + 1; k < n; k++) {
                if(areDiff(l[i], l[j], l[k])) {
                    if(areTri(l[i], l[j], l[k])) {
                        total++;
                    }
                }
           }
        }
    }
    cout << total;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

template<class T> inline bool chmin(T& a, const T b) { if (a>b) { a=b; return true; } return false; }
template<class T> inline bool chmax(T& a, const T b) { if (a<b) { a=b; return true; } return false; }



int main() {
    //ios::sync_with_stdio(false); cin.tie(0);
    int n;
    string s;
    cin>>n;
    cin>>s;
    //vector<vi> v(26);
    set<int> v[26];

    REP(i,n){
        //v[s[i]-'a'].emplace_back(i+1);
        v[s[i]-'a'].insert(i+1);
    }

    int q;
    cin>>q;
    REP(lp,q){
        int com, l,r;
        char a;
        cin>>com;
        if(com==1){
            //変更
            cin>>l>>a;

            //削除
            v[s[l-1]-'a'].erase(l);
            s[l-1] = a;
  
            //挿入
            v[s[l-1]-'a'].insert(l);
        }else{
            //出力
            cin>>l>>r;
            int ans=0;

            REP(i,26){
                auto it = v[i].lower_bound(l);
 
                if(it!=v[i].end() && *it <= r){
                    ans++;
                }
            }

            //cout<<ans<<endl;
            printf("%d\n", ans);
        }
    }
    return 0;
}

Measured memory_bytes: 27264
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct edge {
	static constexpr auto INF = std::numeric_limits<long long>::max();

	edge(int src, int dst, long long weight)
		: src(src), dst(dst), weight(weight)
	{
	}

	bool operator<(const edge& other) const
	{
		return weight > other.weight;
	}

	int src;
	int dst;
	long long weight;
};

using graph = std::vector<std::vector<edge>>;

void add_edge(graph& g, int src, int dst, long long weight)
{
	g[src].emplace_back(src, dst, weight);
}


void dijkstra_shortest_paths(const graph& g, int s, std::vector<long long>& d, std::vector<int>& p)
{
	int n = g.size();
	d.assign(n, edge::INF);
	d[s] = 0;
	p.assign(n, -1);
	std::priority_queue<edge> q;
	q.emplace(-2, s, 0);
	while (!q.empty()) {
		auto e = q.top();
		q.pop();
		if (p[e.dst] != -1) {
			continue;
		}
		p[e.dst] = e.src;
		for (auto& f : g[e.dst]) {
			auto w = e.weight + f.weight;
			if (d[f.dst] > w) {
				d[f.dst] = w;
				q.emplace(f.src, f.dst, w);
			}
		}
	}
}

int main()
{
	int N, M;
	cin >> N >> M;
	graph g(N);
	for (int i = 0; i < M; ++i) {
		int A, B;
		cin >> A >> B;
		--A;
		--B;
		add_edge(g, A, B, 1);
		add_edge(g, B, A, 1);
	}

	vector<long long> dist;
	vector<int> prev;
	dijkstra_shortest_paths(g, 0, dist, prev);
	cout << "Yes" << endl;
	for (int i = 1; i < N; ++i) {
		cout << prev[i] + 1 << endl;
	}
}


Measured memory_bytes: 19228
n = int(input())
l = input()

s = ""
left = 0
right = 0

for a in l:
	if a == "(":
		left += 1
	else:
		if left <= right:
			s = "(" + s
			left += 1
		right += 1
	s += a

if left - right < 0:
	for x in range(right - left):
		s = "(" + s
else:
	for x in range(left - right):
		s += ")"

print (s)


Measured memory_bytes: 3060
import java.lang.Math;
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] X  = new int[n];
        int sum = 0;
        for(int i=0 ; i<n;i++){
            X[i] = sc.nextInt();
            sum = sum + X[i];
        }
        int p = sum / n;
        int s1=0,s2=0;
        for(int i= 0;i<n;i++){
            s1 = s1 + (X[i]-p)*(X[i]-p);
            s2 = s2 + (X[i]-p-1)*(X[i]-p-1);
        }
        System.out.print(Math.min(s1,s2));
    }
}

Measured memory_bytes: 23124
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h> 
#include<math.h>


using namespace std;
typedef long long ll;
# define PI acos(-1) Pi 

//定义函数 
int main(){
	int k,x;
	cin>>k>>x;
	if(x>k*500) cout<<"No";
	else cout<<"Yes";

	 

	
	return 0;
}





Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#define rep( i, a, n ) for( int i = a; i < n; i++ )
#define per( i, a, n ) for( int i = n - 1; i >= a; i-- )
#define mem( f, x ) memset( f, x, sizeof( f ) )
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define MOD 1000000007
#define INF 0x3f3f3f3f

using namespace std;
const int N = 4e5 + 5;
const int M = 4e5+5;
const int MAX = 5;
const ll inv = 500000004;
const double g = 9.80;
const double PI = acos( -1.0 );
int m, n, t, cnt, ct;
int io[N][2], ft[N];
bool vis[N];
char s[N];

struct eg{
    int to, next;
    eg( ){ to = next = 0; }
    eg( int tt, int nn ){ to = tt, next = nn; }
}e[M];

void add( int x, int y ){
    e[++cnt] = eg( y, ft[x] );
    ft[x] = cnt;
}

bool topu( ){
    queue<int> q;
    while( !q.empty() ) q.pop();
    rep( i, 1, n + 1 ){
        if( !io[i][0] || !io[i][1] ){
            q.push( i );
            vis[i] = 1;
        }
    }
    int sum = 0;
    while( !q.empty() ){
        sum++;
        int tmp = q.front();
        q.pop();
        for( int i = ft[tmp]; i; i = e[i].next ){
            int to = e[i].to;
            if( !vis[to] ){
                if( --io[to][s[tmp] == 'B'] == 0 ){
                    vis[to] = 1;
                    q.push( to );
                }
            }
        }
    }
    return sum == n;
}

int main( ){
    while( scanf( "%d %d", &n, &m ) != EOF ){
        mem( ft, 0 );
        mem( vis, 0 );
        mem( io, 0 );
        scanf( "%s", s + 1 );
        rep( i, 1, m + 1 ){
            int x, y;
            scanf( "%d %d", &x, &y );
            add( x, y );
            add( y, x );
            io[x][s[y] == 'B']++;
            io[y][s[x] == 'B']++;
        }
        if( topu() ) puts( "No" );
        else puts( "Yes" );
    }
    return 0;
}


Measured memory_bytes: 9344
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn read_vec_char() -> Vec<char> {
    read::<String>().chars().collect()
}

fn read_mat<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_mat_char(n: usize) -> Vec<Vec<char>> {
    (0..n).map(|_| read_vec_char()).collect()
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let mut c = 0;
    let mut count = 0;
    let mut ans = 0;
    for m in v {
        if m == c {
            count += 1;
        } else if count <= 1 {
            c = m;
            count = 1;
        } else {
            ans += count / 2;
            c = m;
            count = 1;
        }
    }
    if count > 1 {
        ans += count / 2;
    }
    println!("{}",ans);
}


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


void solve(std::string AtCoder, std::string s, std::string Contest){
char ichi;
ichi=s.at(0);
cout<<"A"<<ichi<<"C"<<endl;
}

int main(){
    std::string AtCoder;
    std::cin >> AtCoder;
    std::string s;
    std::cin >> s;
    std::string Contest;
    std::cin >> Contest;
    solve(AtCoder, s, Contest);
    return 0;
}


Measured memory_bytes: 256
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ab_s(n);
    rep(i, n)
    {
        cin >> ab_s[i].first >> ab_s[i].second;
        --ab_s[i].first;
    }
    sort(ab_s.begin(), ab_s.end());

    vector adjs(n + 1, vector<pair<int, int>>());
    rep(i, m)
    {
        int l, r;
        cin >> l >> r;
        --l;
        int l_ = lower_bound(ab_s.begin(), ab_s.end(), make_pair(l, -1)) - ab_s.begin();
        int r_ = lower_bound(ab_s.begin(), ab_s.end(), make_pair(r, -1)) - ab_s.begin();
        if (l_ == r_)
        {
            continue;
        }
        adjs[l_].push_back({i, r_});
        adjs[r_].push_back({i, l_});
    }

    ab_s.insert(ab_s.begin(), {-1, 0});
    ab_s.emplace_back(1000'000'001, 0);

    vector used(n + 1, false), cut(m, false);
    auto dfs = [&](auto self, int v) -> int {
        used[v] = true;
        int ret = ab_s[v + 1].second ^ ab_s[v].second;
        for (auto &[i, u] : adjs[v])
        {
            if (used[u])
            {
                continue;
            }
            if (self(self, u))
            {
                cut[i] = true;
                ret = 1 - ret;
            }
        }
        return ret;
    };
    dfs(dfs, n);
    rep(v, n)
    {
        if (used[v])
        {
            continue;
        }
        if (dfs(dfs, v))
        {
            cout << -1 << "\n";
            return 0;
        }
    }
    int cnt = accumulate(cut.begin(), cut.end(), 0);
    cout << cnt << '\n';
    rep(i, m)
    {
        if (cut[i])
        {
            cout << i + 1 << ' ';
        }
    }

    return 0;
}


Measured memory_bytes: 18132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int a, b, m;
    cin >> a >> b >> m;
    vector<int> o(a);
    int q = INT_MAX;
    int w = INT_MAX;
    rep(i, a){
        cin >> o[i];
        q = min(q, o[i]);
    }
    vector<int> p(b);
    rep(i, b){
        cin >> p[i];
        w = min(w, p[i]);
    }

    int ans = q + w;
    vector<int> x(m), y(m), c(m);
    rep(i, m){
        cin >> x[i] >> y[i] >> c[i];
        ans = min(ans, o[x[i]-1]+p[y[i]-1]-c[i]);
    }
    cout << ans << endl;



    return 0;
}

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

int n;
int cost[500][500];
int idx[500*500 + 2], idy[500*500 + 2];

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

bool valid(int gg) {
	return gg >= 0 && gg < n;
}

int has[500][500];
int vis[500][500];

void dfs(int x, int y, int cx) {
	vis[x][y] = cx;
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];

		if (valid(nx) && valid(ny) && vis[nx][ny] != cx) {
			if (cost[nx][ny] > cost[x][y] + has[x][y]) {
				cost[nx][ny] = cost[x][y] + has[x][y];
				dfs(nx, ny, cx);
			}
		}
	}
}

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

	cin >> n;
	int petr = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			petr++;
			idx[petr] = i;
			idy[petr] = j;

			has[i][j] = 1;
			cost[i][j] = min(i, n - i - 1);
			cost[i][j] = min(cost[i][j], min(j, n - j - 1));
		}
	}

	int ans = 0;
	for (int ppp = 1; ppp <= n*n; ppp++) {
		int p; cin >> p;
		int x = idx[p], y = idy[p];

		has[x][y] = 0;
		ans += cost[x][y];
		dfs(x, y, ppp);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 27468
#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = m / n; i >= 1; i--)
    {
        if (m % i == 0)
        {
            int j = m / i;
            if (j >= n)
            {
                cout << i << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

void primeFactor(int n, vector<int> &pri)
{
    while (n % 2 == 0)
    {
        // cout << 2 << " ";
        pri.push_back(2);
        n /= 2;
    }
    for (int i = 3; i < sqrt(n * 1.0); i += 2)
        while (n % i == 0)
        {
            // cout << i << " ";
            pri.push_back(i);
            n /= i;
        }
    if (n > 2)
        // cout << n;
        pri.push_back(n);
    cout << '\n';
}

int main()
{
    fast_io();
    ll n;
    ll ans = 0, div = 0;
    vector<int> pri;
    cin >> n;
    while (n % 2 == 0)
    {
        div++;
        n /= 2;
    }
    for (ll i = 1; i <= div; i++)
    {
        div -= i;
        ans++;
    }
    for (int i = 3; i <= sqrt(n * 1.0); i += 2)
    {
        div = 0;
        while (n % i == 0)
        {
            div++;
            n /= i;
        }
        for (ll i = 1; i <= div; i++)
        {
            div -= i;
            ans++;
        }
    }
    if (n != 1)
        ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3152
N = int(input())
spot = list(map(int, input().split()))
spot.insert(0, 0)  # リストの先頭と最後に0を挿入
spot.append(0)

allsum = 0
for i in range(N + 1):
    allsum = allsum + abs(spot[i] - spot[i + 1])
# print(allsum)

for i in range(1, N + 1):
    # print("%d,%d,%d" % (abs(spot[i - 1] - spot[i]), abs(spot[i] - spot[i + 1]), abs(spot[i - 1] - spot[i + 1])))
    ans = allsum - abs(spot[i - 1] - spot[i]) - abs(spot[i] - spot[i + 1]) + abs(spot[i - 1] - spot[i + 1])
    print(str(ans))

Measured memory_bytes: 13920
#include <iostream>
using namespace std;
int main(void){
int a,b,c,d,e,f,i,g;
a=0;
b=0;
c=0;
d=0;
e=0;
f=0;
for (i=1;i<=10;i++){
cin>>g;
if(a<=g){
c=b;
b=a;
a=g;
}else if(b<=g){
c=b;
b=g;
}else if(c<=g){
c=g;
}
}
for (i=1;i<=10;i++){
cin>>g;
if(d<=g){
f=e;
e=d;
d=g;
}else if(e<=g){
f=e;
e=g;
}else if(f<=g){
f=g;
}
}
cout<<a+b+c<<" "<<d+e+f<<endl;
}



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

#define F first
#define S second
#define PB push_back
#define all(x) x.begin(), x.end()

typedef long long ll; 
typedef long double ld;

const int N = 1000 * 1000 + 10, mod = 998244353; 

int a[N];
int n;

bool check(int x)
{
	priority_queue<pair<int, int>> s;
	s.push({0 ,0});
	for(int i = 1; i < n; i++)
	{
		if(a[i] > a[i-1])
			continue;
		while(s.top().F>a[i])
			s.pop();
		int cur = a[i];
		while(cur)
		{
			pair<int, int> p = s.top();
			if(p.F < cur) p = {cur, 1};
			else s.pop();
			if(p.S==x)
			{
				cur--;
				continue;
			}
			p.S++;
			s.push(p);
			break;
		}
		if(!cur) return 0;
	}
	return 1;
}

int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin>> n;
	for(int i = 0; i < n; i++) cin>> a[i];
	int l = 0, r = n; 
	while(r-l>1)
	{
		int mid = (l+r) / 2;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	cout<< r << '\n';
}


Measured memory_bytes: 1152