akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct T{
    int key;
    T *parent,*left,*right;
};
    T *root=NULL;
void insert(int k){
    T *y=NULL;
    T *x=root;
    T *z=new T();
    *z={NULL};
    z->key=k;
    while(x!=NULL){
        y=x;
        if(z->key < x->key){
            x=x->left;
        }
        else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NULL){
        root=z;
    }
    else if(z->key < y->key){
        y->left=z;
    }
    else{
        y->right=z;
    }
}
void Preorder(T *root){
    if(root!=NULL){
        cout<<" "<<root->key;
        Preorder(root->left);
        Preorder(root->right);
    }
}
void Inorder(T *root){
    if(root!=NULL){
        Inorder(root->left);
        cout<<" "<<root->key;
        Inorder(root->right);
    }
}
int main(){
    int n,k;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s=="insert"){
            cin>>k;
            insert(k);
        }
        else{
            Inorder(root);
            cout<<endl;
            Preorder(root);
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 26664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

	int n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int g = 1;
	while (true) {
		int  tmp = k + (g - 1) * (k - 1);
		if (tmp < n) {

		}
		else {
			break;
		}
		g++;
	}
	cout << g << endl;
	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
int main()
{
	dhoom;
	string s;
	cin >> s;
	int flag = 1;
	if(s[0] != 'A')
		flag = 0;
	int cnt = 0;
	for(int i = 1 ; i < (int)s.size() ; i++)
	{
			if(isupper(s[i])){
				if(i == 1 || i == (int)s.size() - 1 || s[i] != 'C')
					flag = 0;	
				cnt++;
			}
	}
	if(cnt != 1)
		flag = 0;
	if(flag)
		cout << "AC" <<endl;
	else 
		cout << "WA" << endl;
	return 0;
} 



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int t = 0;
    int ans = 0;
    for(int i = 0;i < n;i++){
          int a,b;
          cin >> a >> b;
          if(a == b){
                t++;
          }else{
                ans = max(ans,t);
                t = 0;
          }
    }
    ans = max(ans,t);
    if(ans >= 3){
          cout << "Yes" << endl;
    }else{
          cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <map>
using namespace std;

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

  bool al[26];
  for(int i=0; i<26; i++) al[i] = false;

  for(int i=0; i<s.length(); i++){
    al[s[i]-'a'] = true;
  }

  for(int i=0; i<26; i++){
    if(!al[i]){
      cout << s + (char)(i+'a') << endl;
      return 0;
    }
  }

  for(int i=0; i<26; i++) al[i] = false;

  for(int i=s.length()-1; i>0; i--){
    al[s[i]-'a'] = true;
    if(s[i-1] < s[i]){
      cout << s.substr(0, i-1);
      for(int j=0; j<26; j++){
        if(al[j] && (char)(j+'a') > s[i-1]){
          cout << (char)(j+'a') << endl;
          return 0;
        }
      }
    }
  }

  cout << -1 << endl;

  return 0;
}


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

using namespace std;

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

	for (int i = 0; (size_t)i < s.size(); i++) {
		if (count(s.begin(), s.end(), s[i]) != 2) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())

d = getSomeInputListInt(n)

buildings = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

for b, f, r, v in d:
    buildings[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        print("",*buildings[i][j], sep=" ")

    if i!=3:
        for k in range(20):
            print("#", end="")
        print()


Measured memory_bytes: 7000
s=require("fs").readFileSync("/dev/stdin","utf8").split('\n')
n=s[0].split(' ')[0]|0,k=s[0].split(' ')[1]|0
s.shift()
s=s.sort((a,b)=>b-a)
console.log(Math.min(...[...Array(n-k+1)].map((_,i)=>s[i]-s[i+k-1])))


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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

void solve(){
	int x, y;
	cin >> x >> y;
	string s = "No";
	if(y % 2 == 0 && x * 2 <= y && y <= x * 4) s = "Yes";
	cout << s;
}

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

	solve();
    
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cmath>

using namespace std;

int main(){
	int N,D,count=0;
	cin >> N >> D;
	double x[N],y[N],dis[N];
	for(int i=0;i<N;i++){
		cin >> x[i] >> y[i];
		dis[i] = sqrt(fabs((x[i]*x[i])+(y[i]*y[i]))); 
	}
	for(int i=0;i<N;i++){
		if(dis[i]<=D){
			count++;
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 8524
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cassert>
using namespace std;
#define N 200020
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,d[N],t[N],ans[N];
pair<int,int> p[N];
vector<pair<int,int> > G[N];
struct Union{
	int f[N];
	void init(int n){
		for(int i=1;i<=n;++i)f[i]=i;
	}
	inline int getf(int x){
		return f[x]==x?x:f[x]=getf(f[x]);
	}
}S;
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;++i){
		d[i]=read();
		t[i]=-1;
	}
	for(int i=1;i<=m;++i){
		int u=read(),v=read();
		G[u].emplace_back(v,i);
		G[v].emplace_back(u,i);
		ans[i]=1e9;
	}
	for(int i=1;i<=n;++i){
		p[i]=(*min_element(G[i].begin(),G[i].end(),[&](pair<int,int> i,pair<int,int> j){
			return d[i.first]==d[j.first]?i.first<j.first:d[i.first]<d[j.first];
		}));
		if(d[p[i].first]>d[i]){
			return !printf("-1\n");
		}
	}
	for(int i=1;i<=n;++i){
		int u=p[i].first;
		if(~t[i])continue;
		if(d[u]==d[i]){
			if(~t[u]){
				t[i]=t[u]^1;
			}
			else{
				t[i]=0,t[u]=1;
			}
			ans[p[i].second]=d[i];
		}
	}
	S.init(n);
	for(int i=1;i<=n;++i){
		if(~t[i])continue;
		int u=p[i].first;
		S.f[i]=u;
		ans[p[i].second]=d[i]-d[u];
	}
	for(int i=1;i<=n;++i){
		putchar(t[S.getf(i)]?'B':'W');
	}
	putchar('\n');
	for(int i=1;i<=m;++i){
		printf("%d\n",ans[i]);
	}
	return 0;
}


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

int main(){
int A, B, C;
  cin >> A >> B >> C;
bool a = false;  
  
  for(int i = 1;i <= 1001;i++){
  if(A * i % B == C){
  a = true;
    break;
  }  
  }
  
  if(a) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main()
{ 
 int a,b;
cin>>a>>b;
if(a>b) 
{ 
cout<<(2*a-1)<<endl;
}
else if(a<b) 
{  cout<<(2*b-1)<<endl; 
}
else 
cout<<(2*a)<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void funcA() {

    int n;
    cin >> n;
    for (int i = 1; i <= 10; ++i) {
        if (i * 1000 >= n) {
            cout << i * 1000 - n;
            break;
        }
    }
}

int main() {

    funcA();

    return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    const int ulim = 7500000;
    bitset<ulim> sieve;

    for (;;) {
        int m, n;
        cin >> m >> n;
        if (!m)
            break;

        sieve.reset();
        sieve.flip();

        int tog = 0;

        for (int i = m; i < ulim; i++)
            if (sieve[i]) {
                tog++;
                if (tog == n + 1) {
                    cout << i << endl;
                    goto nxt;
                }
                for (int j = i; j < ulim; j += i)
                    sieve[j] = false;
            }

    nxt:
        void(0);
    }
}



Measured memory_bytes: 4068
n, m = list(map(int, input().split()))

ans = 10 ** n
num = [-1] * n

for i in range(m):
    s, c = list(map(int, input().split()))
    if num[s - 1] == -1:
        num[s - 1] = c
    elif num[s - 1] != c:
        ans = -1
        break

if ans != -1:
    #1桁
    if n == 1:
        if num[0] == -1:
            ans = 0
        else:
            ans = num[0]
    #2桁以上
    else:
        # 先頭0チェック
        if num[0] == 0:
            ans = -1
        else:
            # 最小値なので1桁目が―1ならば1を代入
            if num[0] == -1:
                num[0] = 1

            # 最小値なので2桁目以降は-1があれば0を代入
            for j in range(1, n):
                if num[j] == -1:
                    num[j] = 0
            
            ans = int(''.join(list(map(str, num))))

print(ans)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    cout << (n-1) * (m-1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#define ll long long
#define dec DEEP_DARK_FANTASY
#define add VAN_YOU_SEE
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll add[100010],dec[100010],n,m,a[100010];
void addition(ll l,ll r,ll val){
//	cout<<"addition "<<l<<' '<<r<<' '<<val<<'\n';
	add[l]+=val;
	add[r+1]-=val;
}
void decrease(ll l,ll r,ll val){
//	cout<<"decrease "<<l<<' '<<r<<' '<<val<<'\n';
	dec[l]+=val;
	dec[r+1]-=val;
}
int main(){
	n=read();m=read();ll i,l,r;
	for(i=1;i<=n;i++) a[i]=read();
	for(i=1;i<n;i++){
		l=a[i];r=a[i+1];
		if(l==r) continue;
		if(l<r){
			addition(1,l,r-l);
			addition(r+1,m,r-l);
			
			addition(l+1,r,r+1);
			decrease(l+1,r,1);
		}
		else{
			addition(r+1,l,r+m-l);
			
			addition(1,r,r+1);
			decrease(1,r,1);
			
			addition(l+1,m,r+m+1);
			decrease(l+1,m,1);
		}
	}
	ll ans=1e15;
	for(i=1;i<=m;i++){
		add[i]+=add[i-1];
		dec[i]+=dec[i-1];
//		if(i==54400) cout<<i<<' '<<add[i]<<' '<<dec[i]<<'\n';
		ans=min(ans,add[i]-dec[i]*i);
	}
	cout<<ans<<'\n';
}


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

int main() {
  int N, A[110];
  cin >> N;
  string ans = "APPROVED";
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if(A[i] % 2 == 0){
	    if (A[i] % 3 != 0 && A[i] % 5 != 0) {
	    	ans = "DENIED";
	    }
	  }
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
#define pi 3.141592653589
using namespace std;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
signed main(){
	string s;
	int n;
	cin >> s;
	n = s.size();
	stack<char>st;
	int cnt = 0;
	rep(i, n) {
		char a = s[i];
		if (a == '0') {
			if (!st.empty()) {
				if (st.top() == '1') {
					st.pop();
				}
				else {
					st.push('0');
				}
			}
			else {
				st.push('0');
			}
		}
		else {
			if (!st.empty()) {
				if (st.top() == '0') {
					st.pop();
				}
				else {
					st.push('1');
				}
			}
			else {
				st.push('1');
			}
		}
	}
	while (!st.empty()) {
		cnt++;
		st.pop();
	}
	cout << s.size()-cnt << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> count(26);
  string S;cin>>S;
  for(int i=0;i<S.size();i++){
    count[S[i]-'a']++;
  }
  for(int i=0;i<26;i++){
    if(!count[i]){
      cout<<(char)('a'+i)<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a[4][3][10];
int n;
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int b, c, d, e;
		cin >> b >> c >> d >> e;
		a[b - 1][c - 1][d - 1] += e;
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int z = 0; z < 10; z++) {
				cout << " " << a[i][j][z];
			}
			cout << endl;
		}
		if (i < 3) {
			for (int z = 0; z < 20; z++) cout << "#";
			cout << endl;
		}
	}
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define lin "\n"
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(0)

void solve() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n&1){
        cout<<"No";
        return;
    } else{
        for(int i=0;i<n/2;++i){
            if(s[i]!=s[i+n/2]){
                cout<<"No";
                return;
            }
        }
    }
    cout<<"Yes";
}

int main() {
    fast_io;
    int t = 1;
//    cin >> t;
    int c = 1;
    while (t--) {
//        printf("Case %lld: ",c);
//        cout<<"Case "<<c<<": ";
        solve();
        c++;
    }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName


bool solve(){
	string s;cin>>s;
	cout<<string(s.begin(),s.begin()+3)<<endl;
  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    ll a,b;
    cin >> a >> b;
    cout << (a*b)/__gcd(a,b) << endl;

    return 0;    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

signed main() {
  ll N;
  cin >> N;
  vector<ll> a(N), b(N);
  rep(i, N)
    cin >> a[i] >> b[i];
  sort(begin(a), end(a));
  sort(begin(b), end(b));
  if (N % 2 == 1) {
    ll x = a[(N-1) / 2];
    ll y = b[(N-1) / 2];
    cout << (y - x + 1) << endl;
  } else {
    ll x2 = a[N/2] + a[N/2-1];
    ll y2 = b[N/2] + b[N/2-1];
    cout << (y2 - x2) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 6388
#include <cassert>
#include <cstddef>
#include <tuple>
#include <utility>
#include <vector>

template <class Abelian> class PotentializedUnionFind {

public:
  using value_type = Abelian;
  using size_type = std::size_t;
  using container_type =
      std::vector<std::tuple<size_type, value_type, size_type>>;

protected:
  container_type c;

private:
  size_type &par(const size_type i) { return std::get<0>(c[i]); }
  size_type par(const size_type i) const { return std::get<0>(c[i]);
                                         assert(false);}
  value_type &val(const size_type i) { return std::get<1>(c[i]); }
  const value_type &val(const size_type i) const { return std::get<1>(c[i]);
                                                 assert(false);}
  size_type &siz(const size_type i) { return std::get<2>(c[i]); }
  size_type siz(const size_type i) const { return std::get<2>(c[i]); }
  value_type potential(size_type x) {
    value_type ret = {};
    while (x != par(x)) {
      val(x) = val(x) + val(par(x));
      ret = ret + val(x);
      x = par(x) = par(par(x));
    }
    return std::move(ret);
  }

public:
  PotentializedUnionFind() : c() {}
  explicit PotentializedUnionFind(const size_type size)
      : c(size, std::forward_as_tuple(static_cast<size_type>(0), value_type(),
                                      static_cast<size_type>(1))) {
    for (size_type i = 0; i < size; ++i)
      par(i) = i;
  }

  size_type size() const { return c.size(); }
  bool empty() const { return c.empty(); }

  size_type find(size_type x) {
    assert(x < size());
    while (x != par(x)) {
      val(x) = val(x) + val(par(x));
      x = par(x) = par(par(x));
    }
    return x;
  }
  value_type diff(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    assert(same(x, y));
    return potential(y) + (-potential(x));
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return siz(find(x));
  }

  bool unite(size_type x, size_type y, value_type d) {
    assert(x < size());
    assert(y < size());
    d = d + potential(x) + (-potential(y));
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (siz(x) < siz(y))
      std::swap(x, y), d = -d;
    siz(x) += siz(y);
    par(y) = x;
    val(y) = std::move(d);
    return true;
  }
};

#include<iostream>

int main() {
	int n, m;
	std::cin >> n >> m;
	PotentializedUnionFind<int> T(n);
	while (m--) {
		int l, r, d;
		std::cin >> l >> r >> d;
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) {
				std::cout << "No" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}


Measured memory_bytes: 2560
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.AbstractCollection;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        IntegerCards solver = new IntegerCards();
        solver.solve(1, in, out);
        out.close();
    }

    static class IntegerCards {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            PriorityQueue<Long> pq = new PriorityQueue<>(n, Long::compare);
            // 降順
            PriorityQueue<Pair> conditions = new PriorityQueue<>(n, (o1, o2) -> Long.compare(o2.value, o1.value));
            for (int i = 0; i < n; i++) {
                pq.add(Long.parseLong(in.next()));
            }

            for (int i = 0; i < m; i++) {
                long b = Long.parseLong(in.next());
                long c = Long.parseLong(in.next());
                conditions.add(new Pair(c, b));
            }
            while (!conditions.isEmpty()) {
                Pair p = conditions.poll();
                for (int i = 0; i < p.time; i++) {
                    Long a = pq.poll();
                    if (p.value <= a) {
                        conditions.clear();
                        pq.add(a);
                        break;
                    }
                    pq.add(p.value);
                }
            }
            long result = 0;
            while (!pq.isEmpty()) {
                result += pq.poll();
            }
            out.print(result);
        }

        class Pair {
            public final Long value;
            public final Long time;

            public Pair(Long value, Long time) {
                this.value = value;
                this.time = time;
            }

        }

    }
}



Measured memory_bytes: 71968
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	
	ll D, T, S;
	cin>>D>>T>>S;
	double x = (double) D/ (double) S;
	if ((double)x <= (double)T) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>

int main(void){
	int n;
	int infFlag1, infFlag2;
	double x1, y1, x2, y2, x3, y3, x4, y4;
	double m1, m2;
	scanf("%d",&n);
	while(n > 0){
		infFlag1 = 0;
		infFlag2 = 0;
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
		if(x2 != x1){
			m1 = (y2 - y1) / (x2 - x1);
		}else{
			infFlag1 = 1;
		}
		if(x4 != x3){
			m2 = (y4 - y3) / (x4 - x3);
		}else{
			infFlag2 = 1;
		}
		if(infFlag1 && infFlag2){
			puts("YES");
		}else if(!infFlag1 && !infFlag2){
			puts(m1 == m2 ? "YES" : "NO");
		}else{
			puts("NO");
		}
		n--;
	}
	return 0;
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int a , p;
        cin >> a >> p;
        int tot = a * 3 + p;
        cout << tot/2 << endl;
        return 0;
}






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

const int MOD = 1e9+7;

int r1, r2, c1, c2;

int ksm(long long x,long long y)
{
	x %= MOD;
	long long rt = 1LL;
	while ( y )
	{
		if ( y & 1 )
			rt = rt * x % MOD;
		x = x * x % MOD;
		y >>= 1;
	}
	return (int)rt;
}

int C(int n,int m)
{
	if ( n < m )
		return 0;
	long long rt = 1LL;
	for ( int i = 0 ; i < m ; i++ )
		rt = rt * (long long)(n-i) % (long long)MOD * (long long)ksm(i+1,MOD-2) % (long long)MOD;
	return (int)rt;
}

int u(int x,int y)
{
	return C(x+y,min(x,y));
}

int s(int x,int y)
{
	return u(y+1,x+1)-1;
}

int main()
{
	scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
	printf("%d",(s(r2,c2)-s(r2,c1-1LL)-s(r1-1LL,c2)+s(r1-1LL,c1-1LL)+MOD)%MOD);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	int N; cin >> N;
	long* A = new long[N];
	long sum = 0;

	bool oddflag = false;
	long m = 1000000005;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] > 0) {
			sum += A[i];
		}
		else {
			oddflag = !oddflag;
			sum -= A[i];
		}
		m = min(m, abs(A[i]));
	}
	
	if (oddflag) {
		sum -= m * 2;
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int):
    print(Z, X, Y)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    solve(X, Y, Z)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#define llint long long
#define mod 998244353

using namespace std;

llint n, k;

llint fact[1000005], fact_inv[1000005];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 1000005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 1000005; i++){
		fact_inv[i] = modpow(fact[i], mod-2);
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	cin >> n >> k;
	make_fact();
	
	llint ans = 0;
	for(int r = n; r <= k; r++){
		int b = k - r;
		if(r < b) continue;
		
		if(r > b){
			ans += comb(r+b, r), ans %= mod;
			if(r-b < n) ans += mod - comb(r+b, 2*r-n+1), ans %= mod;
		}
		if(r == b){
			ans += comb(r+b-1, r), ans %= mod;
			ans += mod - comb(r+b-1, 2*r-n+1), ans %= mod;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int a,b;
	cin>>a>>b;
	cout<<(a+b)%24<<endl;
}

Measured memory_bytes: 256
lsnum = list(input())
lsnum1 = [int(i) for i in lsnum]
ls = ['+','-']
for i in range(2 ** 3):
    ans = lsnum1[0]
    for j in range(3):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
           ans += lsnum1[j+1]
        else:
            ans -= lsnum1[j+1]
    if ans == 7:
        bit = i
        break
ans2 = lsnum[0]
for i in range(3):
    if ((bit >> i) & 1):
        ans2 += '+'+lsnum[i+1]
    else:
        ans2 += '-'+lsnum[i+1]
print(ans2+'=7')

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> A(N);
    int ma = 0;
    ll ans = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        ans += max(ma-A[i],0);
        ma = max(A[i],ma);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll n,d[222222],m,t[222222];
set<ll> s;

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>n;
  REP(i,n){
    cin>>d[i];
  }
  cin>>m;
  REP(i,m){
    cin>>t[i];
    s.insert(t[i]);
  }
  if(n<m){
    P("NO");
    return 0;
  }
  sort(d,d+n);
  sort(t,t+m);

  for(auto x:s){
    ll a1=lower_bound(d,d+n,x)-d;
    ll a2=upper_bound(d,d+n,x)-d;
    ll A=a2-a1;
    ll b1=lower_bound(t,t+m,x)-t;
    ll b2=upper_bound(t,t+m,x)-t;
    ll B=b2-b1;
    if(A<B){
      P("NO");return 0;
    }
  }
  P("YES");
  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
void swap(int *a,int *b)
{
  int temp=*a;
  *a=*b;
  *b=temp;
}
  
int main()
{
  int x,y,z;
  cin>>x>>y>>z;
  swap(&x,&y);
  swap(&x,&z);
  cout<<x<<" "<<y<<" "<<z<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const long long MOD = 1000000007;
const int MAX = 3000 + 10;

int n, m;

long long dpb[MAX][MAX];
long long dps[MAX][MAX];
long long tmpxb[MAX];
long long tmpxs[MAX];
long long tmpyb[MAX];
long long tmpys[MAX];
long long lazy[MAX];

int rec[MAX];

void update(int x) {
    for(int i = 0 ; i < n ; i++) {
        dpb[x][i] *= lazy[x];
        dpb[x][i] %= MOD;
        dps[x][i] *= lazy[x];
        dps[x][i] %= MOD;
    }
    lazy[x] = 1LL;
}

long long inv(int x) {
    if(x == 1) return 2LL;
    long long tmp = inv(x/2);
    if(x&1) return tmp * tmp % MOD * 2 % MOD;
    return tmp * tmp % MOD;
}

int main() {
    scanf("%d %d", &n, &m);

    for(int i = 0 ; i < n ; i++) {
        scanf("%d", &rec[i]);
    }

    long long ans = 0;

    for(int i = 0 ; i < n ; i++) {
        lazy[i] = 1LL;
        for(int j = 0 ; j < n ; j++) {
            if (rec[j] < rec[i]) {
                dps[i][j]++;
                if (j > i) {
                    ans++;
                }
            } else if (rec[j] > rec[i]) {
                dpb[i][j]++;
            }
        }
    }
    
    long long INV = inv(MOD-2);

    while (m--) {
        int x, y;
        scanf("%d %d", &x, &y);
        x--, y--;
        update(x);
        update(y);
        if (x > y) swap(x, y);

        ans *= 2;
        ans %= MOD;
        
        for(int i = x+1 ; i <= y ; i++) {
            ans += dpb[x][i] - dps[x][i];
            ans %= MOD;
        }

        for(int i = x+1 ; i < y ; i++) {
            ans += dps[y][i] - dpb[y][i];
            ans %= MOD;
        }

        for(int i = 0 ; i < n ; i++) {
            tmpxs[i] = dps[x][i];
            tmpxb[i] = dpb[x][i];
            tmpys[i] = dps[y][i];
            tmpyb[i] = dpb[y][i];
        }

        swap(tmpxs[x], tmpxs[y]);
        swap(tmpxb[x], tmpxb[y]);
        swap(tmpys[y], tmpys[x]);
        swap(tmpyb[y], tmpyb[x]);

        for(int i = 0 ; i < n ; i++) {
            dps[x][i] += tmpys[i];
            dps[x][i] %= MOD;
            dpb[x][i] += tmpyb[i];
            dpb[x][i] %= MOD;
            dps[y][i] += tmpxs[i];
            dps[y][i] %= MOD;
            dpb[y][i] += tmpxb[i];
            dpb[y][i] %= MOD;
        }

        for(int i = 0 ; i < n ; i++) {
            if(i == x || i == y) continue;
            lazy[i] *= 2;
            lazy[i] %= MOD;

            long tmp = dpb[i][x];
            dpb[i][x] += dpb[i][y];
            dpb[i][y] += tmp;
            dpb[i][x] *= INV;
            dpb[i][x] %= MOD;
            dpb[i][y] *= INV;
            dpb[i][y] %= MOD;

            tmp = dps[i][x];
            dps[i][x] += dps[i][y];
            dps[i][y] += tmp;
            dps[i][x] *= INV;
            dps[i][x] %= MOD;
            dps[i][y] *= INV;
            dps[i][y] %= MOD;
        }
    }
    
    ans = ((ans % MOD) + MOD) % MOD;
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 141696
N = int(input())
A = list(map(int, input().split()))
B = [0] *(N+1)
B[0] = 1
ans = 0
for i in range(1, N+1):
    B[i] = (B[i-1] - A[i-1])*2
    if B[i] <= 0:
        ans = -1
        break
if B[N] < A[N]:
    ans = -1
if ans == 0:
    check = 0
    for j in range(N, 0, -1):
        check += A[j]
        if check < B[j]:
            ans += check
        else:
            last = j
            for k in range(1, last+1):
                ans += B[k]
            break
    ans += 1
if N == 0 and A[0] == 1:
    ans = 1
print(ans)


Measured memory_bytes: 674536
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer []AN  = new Integer[N];
        int []BN = new int[N];
       // List<Integer> list = new LinkedList<>();
        for (int i=0;i<N;i++){
            AN[i]=sc.nextInt();
            BN[i]=AN[i];
            //list.add(AN[i]);
        }
        Arrays.sort(BN);

        //list.addAll(Arrays.asList(AN));
        Long cnt = 0L;

        for(int i=0;i<N;i++){
            int tmp = i + Arrays.binarySearch(BN, AN[i]);

          //  System.out.println(AN[i]+" "+list.indexOf(AN[i])+" "+tmp);
            if (tmp%2!=0) cnt++;

        }
        System.out.println(cnt/2);

    }
 }


Measured memory_bytes: 25668
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int n,w;
ll dp[105][100005];

ll solve(int W[], ll V[]){
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
		{
			//cout<<"1"<<endl;
			if(i==0 || j==0)
			{
				dp[i][j] = 0;
				continue;
			}
			if(W[i-1]<=j)
			{
				dp[i][j] = max(V[i-1]+dp[i-1][j-W[i-1]],dp[i-1][j]);
			}
			else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	return dp[n][w];
}

int main()
{
	
	cin>>n>>w;
	
	ll V[n];
    int W[n];
	for(int i=0;i<n;i++)
	{
		cin>>W[i]>>V[i];
	}
	
	cout<<solve(W,V)<<endl;
	return 0;
}

Measured memory_bytes: 80128
h,w=map(int,input().split())
dp=[ [-1]*(w+1) for _ in range(h+1) ]
for i in range(h):
  i+=1
  tmp=input()
  for j in range(w):
    j+=1
    if tmp[j-1]=='.':
      dp[i][j]=0
    else:
      dp[i][j]=-1
dp[1][1]=1

for i in range(1,h+1):
  for j in range(1,w+1):
    if i==1 and j==1:continue
    if dp[i][j]==-1:continue
    dp[i][j]=0
    if dp[i-1][j]!=-1:
      dp[i][j]+=dp[i-1][j]
    if dp[i][j-1]!=-1:
      dp[i][j]+=dp[i][j-1]
    dp[i][j]=dp[i][j]%(10**9+7)
#print(dp)
print(dp[-1][-1])

Measured memory_bytes: 52572
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
    int a, b; cin >> a >> b;
    int res = a+b;
    if(res>=10) cout << "error" << ln;
    else cout << res << ln;
}


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

const int INF = 1 << 30;
const int N = 1551;
typedef pair<int, int> Pairs;

inline char get(void) {
	static char buf[100000], *S = buf, *T = buf;
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 100000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}
template<typename T>
inline void read(T &x) {
	static char c; x = 0; int sgn = 0;
	for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
	for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
	if (sgn) x = -x;
}

int a[N];
Pairs ans[N];
int n, p, mn, mx, cnt, pn, px;

int main(void) {
	read(n); p = 1; mn = INF; mx = -INF;
	for (int i = 1; i <= n; i++) read(a[i]);
	for (int i = 1; i <= n; i++) {
		if (a[i] < mn) {
			mn = a[i]; pn = i;
		}
		if (a[i] > mx) {
			mx = a[i]; px = i;
		}
	}
	if (-mn > mx) {
		for (int i = 1; i <= n; i++)
			if (a[i] > 0) {
				ans[++cnt] = Pairs(pn, i);
				a[i] += mn;
			}
		for (int i = n; i > 1; i--)
			if (a[i] < a[i - 1]) {
				ans[++cnt] = Pairs(i, i - 1);
				a[i - 1] += a[i];
			}
	} else {
		for (int i = 1; i <= n; i++)
			if (a[i] < 0) {
				ans[++cnt] = Pairs(px, i);
				a[i] += mx;
			}
		for (int i = 1; i < n; i++)
			if (a[i] > a[i + 1]) {
				ans[++cnt] = Pairs(i, i + 1);
				a[i + 1] += a[i];
			}
	}
	printf("%d\n", cnt);
	for (int i = 1; i <= cnt; i++)
		printf("%d %d\n", ans[i].first, ans[i].second);
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = yorukatsu6B()

fun yorukatsu6B() {
    val n = readLine()!!.toInt()
    val txyList = (1..n).map { readLine()!!.split(' ').map { it.toInt() } }
        .map { Txy(it[0], it[1], it[2]) }

    var beforeTime = 0
    var beforeX = 0
    var beforeY = 0

    for ((t, x, y) in txyList) {
        val moveDist = Math.abs(beforeX - x) + Math.abs(beforeY - y)
        val timeDiff = t - beforeTime
        if (moveDist in 1..timeDiff && (timeDiff - moveDist) % 2 == 0) {
            beforeTime = t
            beforeX = x
            beforeY = y
        } else return println("No")

    }

    println("Yes")
}

private data class Txy(val t: Int, val x: Int, val y: Int)


Measured memory_bytes: 62428
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int n;
    cin >> n;

    vector< vs32 > cnt(10, vs32(10, 0));
    rep (i, n + 1)
    {
        int u = i;
        while (u >= 10) u /= 10;
        ++cnt[u][i % 10];
    }

    int ans = 0;
    for (int i = 1; i < 10; ++i)
    {
        for (int j = 1; j < 10; ++j)
        {
            ans += cnt[i][j] * cnt[j][i];
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;

inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

int main(){
  string s;cin>>s;
  ll n=s.size(),ans=0;
  string t="";
  if(n<3){
    cout<<0<<endl;return 0;
  }
  rep(i,0,n-1){
    if(s[i]=='B'&&s[i+1]=='C'){
      t+="Z";
      i++;
    }
    else t+=s[i];
  }
  ll m=t.size();
  ll cnt=0;
  rep(i,0,m){
    if(t[i]=='Z')ans+=cnt;
    else if(t[i]=='A')cnt++;
    else cnt=0;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3900
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define p pair<int,int>
 
int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) {
        cin >> a[i];
    }
    int ratecolor[8];
    rep(i,8){
        ratecolor[i] = 0;
    }
    int overred = 0;
    rep(i,n){
        int c = a[i]/400;
        if (c > 7) {
            overred++;
            continue;
        }
        ratecolor[c] = 1;
    }
    int colors = 0;
    rep(i,8){
        colors = colors + ratecolor[i];
    }
    if (colors == 0) {
        cout << 1 << " " << overred << endl;
    }
    else{
        cout << colors << " ";
        colors = colors + overred;
        cout << colors << endl;
    }

 
    return 0;
}

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

int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    ll abs_X = abs(X);
    ll ans;
    if(abs_X / D >= K) {
        ans = abs_X - D * K;
    } else {
        if((K - abs_X / D) % 2 == 0) {
            ans = min(abs_X % D, abs(abs_X % D - 2 * D));
        } else {
            ans = min(abs_X % D + D, abs(abs_X % D - D));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>

int main() {

    std::string s = "";
    std::cin >> s;

    int a = s.find("A");
    int z = s.rfind("Z");
    int result = s.substr(a, z - a + 1).size();
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<char> c(n);
    for (int i = 0; i < n; i++){
      cin >> c[i];
    }
    vector<int> cnt(26, 0);
    bool tie = true;
    for (int i = 0; i < n; i++){
      cnt[c[i] - 'A']++;
      vector<int> cnt2 = cnt;
      sort(cnt2.rbegin(), cnt2.rend());
      if (cnt2[0] - cnt2[1] > n - i - 1){
        char C;
        for (int j = 0; j < 26; j++){
          if (cnt[j] == cnt2[0]){
            C = 'A' + j;
            break;
          }
        }
        cout << C << ' ' << i + 1 << endl;
        tie = false;
        break;
      }
    }
    if (tie){
      cout << "TIE" << endl;
    }
  }
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main(){
  ll n;
  cin >> n;
  vector<ll>v(n + 100);
  v[1] = 0;
  REP(i,1,n + 1){
    REP(j,1,n + 1){
      if(i * j > n)break;
      v[i * j]++;
    }
  }
  ll ans = 0;
  rep(i,n + 1)ans += v[i] * i;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 81392