akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

int main()
{
    ll a, b, c, d, i, j, k, p=0, pp, m=0, mm=0, kk;
    cin>>a>>b>>c>>d;
    k=gcd(c, d);
    k=(c*d)/k;
    if(a%c==0){
        j=b-a;
        p=j/c +1;
    }
    else{
        j=a/c;
        j=c*(j+1);
        j=b-j;
        if(j<0) p=0;
        else p=j/c +1;
    }

    if(a%d==0){
        j=b-a;
        m=j/d +1;
    }
    else{
        j=a/d;
        j=d*(j+1);
        j=b-j;
        if(j<0) m=0;
        else m=j/d +1;
    }

    if(a%k==0){
        j=b-a;
        mm=j/k +1;
    }
    else{
        j=a/k;
        j=k*(j+1);
        j=b-j;
        if(j<0) mm=0;
        else mm=j/k +1;
    }
    //cout<<p<<" "<<m<<" "<<mm<<endl;
    kk=p+m-mm;
    kk=b-a+1-kk;
    cout<<kk<<endl;
    return 0;
}


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

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  int ret = 0;
  int n,x1=0,x2=0,x3=0;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(s[0]=='B'){
      if(s[s.size()-1]=='A')x2++;
      else x3++;
    } else {
      if(s[s.size()-1]=='A')x1++;
    }
    for(int j=1;j<s.size();j++)if(s[j]=='B'&&s[j-1]=='A')ret++;
  }
  if(x2>=1){
    ret+=(x2-1);
    if(x1>=1){
      x1--;
      ret++;
    }
    if(x3>=1){
      x3--;
      ret++;
    }
  }
  ret+=min(x1,x3);
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mod = 10 ** 9 + 7
MAX = n * m

aa = [0] * (MAX + 1)
bb = [0] * (MAX + 1)

for e in a:
    aa[e] += 1
for e in b:
    bb[e] += 1

a_acc = list(accumulate(aa))
b_acc = list(accumulate(bb))

ans = 1
for i in range(1, MAX + 1):
    if aa[i] > 1 or bb[i] > 1:
        ans = 0
        break

    if aa[i] == 1 and bb[i] == 1:
        continue

    if aa[i] == 1 and bb[i] == 0:
        ans *= m - b_acc[i-1]
    elif aa[i] == 0 and bb[i] == 1:
        ans *= n - a_acc[i-1]
    else:
        ans *= (n - a_acc[i-1]) * (m - b_acc[i-1]) - MAX + i

    ans %= mod

print(ans)


Measured memory_bytes: 34596
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, m;
long long Mod = 998244353, po[101000];
struct Graph {
	vector<int>E[101000];
	int D[101000], m, v[100010], Mx;
	long long C[100010];
	void Input() {
		int i, a, b, j;
		scanf("%d", &m);
		for (i = 0; i < m; i++) {
			scanf("%d%d", &a, &b);
			if (a > b)swap(a, b);
			E[a].push_back(b);
		}
		for (i = n; i >= 1; i--) {
			for (auto &t : E[i])v[D[t]] = 1;
			for (j = 0; v[j]; j++);
			D[i] = j;
			for (auto &t : E[i])v[D[t]] = 0;
			Mx = max(Mx, D[i]);
			C[D[i]] = (C[D[i]] + po[i]) % Mod;
		}
	}
}A, B, C;
int main() {
	int i;
	long long z = 1e18;
	scanf("%d", &n);
	po[0] = 1;
	for (i = 1; i <= n; i++)po[i] = po[i - 1] * (z%Mod) % Mod;
	A.Input();
	B.Input();
	C.Input();
	long long res = 0;
	for (i = 0; i <= A.Mx; i++) {
		for (int j = 0; j <= B.Mx; j++) {
			res = (res + A.C[i] * B.C[j] % Mod*C.C[i^j]) % Mod;
		}
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 18176
#include <stdio.h>
int main()
{
    int a,b,c,d;
     scanf("%d %d %d %d",&a,&b,&c,&d);
     if(a+b > c+d)
           printf("Left");
    else if(a+b < c+d)
              printf("Right");
      else
             printf("Balanced");


         return 0;
  }

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;

int n;
int a[100];
vector< pair<int, int> > vp;

int main(){
	while (cin >> n){
		if (!n)break;
		int k = 0;
		REP(i, n){
			cin >> a[i];
			if (i == 0){
				vp.push_back(make_pair(a[i], a[i]));
				continue;
			}
			if (a[i] == a[i - 1] + 1){
				vp[k].second = a[i];
			}
			else{
				vp.push_back(make_pair(a[i], a[i]));
				k++;
			}
		}
		REP(i, vp.size()){
			if (vp[i].first == vp[i].second){
				cout << vp[i].first;
			}
			else{
				cout << vp[i].first << "-" << vp[i].second;
			}
			i != vp.size() - 1 ? cout << " " : cout << endl;
		}
		vp.clear();
		REP(i, n){
			a[i] = 0;
		}
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
//#define LOCAL LOCAL
#define ll long long
#define endl "\n"
#define ld long double
#define si(x) (ll)((x).size())
#define pb push_back
#define F first
#define S second
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>=1;i--)
#define all(x) (x).begin(), (x).end()
#define make_unique(x) (x).resize(unique(all(x))-(x).begin())
#define pr_vec(v) for(ll _=0;_<v.size();_++) cout << v[_] << " " ;
const int N = 3e5 + 7;
#define log 26

void solve()
{
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i,40)
    {
        ans+=(1ll<<i);
        if(ans>=n)
            break;
    }
    cout<<ans;

}


int main()
{



#ifdef LOCAL
    // for getting input from input.txt

    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    // cin >> t;


    rep1(i, t)
    {
        // cout << "Case #" << i << ": ";
        solve();
        cout << endl;
    }


}

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

using namespace std;

using ll = long long;

int main(){
    ll n, m;
    cin >> n >> m;
    ll arr[n + 10] = {0}, arr1[n] = {0};
    arr1[0] = 1;
    for(ll i = 0; i < m; ++i){
        ll tmp; cin >> tmp;
        arr[tmp] = -1;

    }
    for(ll i = 0; i < n; ++i){
        if(arr[i] == arr[i + 1] && arr[i] == -1){
            cout << 0;
            return 0;
        }
    }
    if (arr[1] != -1)arr1[1] = 1;
    for(ll i = 2; i <= n; ++i){
        if(arr[i] != -1){
            arr1[i] = (arr1[i - 1] % 1000000007 + arr1[i - 2]% 1000000007)% 1000000007;
        }
    }
    cout << arr1[n];
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

mod = (10**9)+7
sumA = sum(A)%mod
sumSq = sum([(i*i)%mod for i in A])%mod
r = (((sumA*sumA)%mod)-sumSq) * modinv(2, mod)
print(r%mod)

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

int main() {

  int N, X, fx = 0;
  cin >> N;
  for (int i = N; i > 0; i /= 10){
    fx += i % 10;
  }
  if (N % fx == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  } 
}


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

int main() {
	int N;
	cin >> N;
	vector<long int> vec (N);
	for(int i = 0;i < N;i++){
		cin >> vec.at(i);
	}
	sort(vec.begin(),vec.end());
	long int a = vec.at(0);
	reverse(vec.begin(),vec.end());
	long int b = vec.at(0);
	cout << b - a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); 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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    string s;
    cin >> s;
    ll ans = 0;
    ll N = s.size();
    reverse(all(s));
    bool pp = false;
    rep(i,N){
        s[i] += pp;
        if(s[i]>'9'){
            pp = true;
        }
        else if(s[i]>'5'){
            ans += '9' - s[i] + 1;
            pp = true;
        }
        else if(s[i]=='5'){
            if(i<N-1&&s[i+1]>='5'){
                ans += 5;
                pp = true;
            }
            else{
                ans += 5;
                pp = false;
            }
        }
        else{
            ans += s[i]-'0';
            pp = false;
        }
    }
    if (pp) ans ++;
    cout << ans << endl;
}


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

int main(){
  int K, N;
  cin >> K;
  cin >> N;
  vector<int> Dis(N);
  for(int i = 0; i < N; i++){
    cin >> Dis.at(i);
  }
  int L;
  for(int j = 0; j < N; j++){
    int Lwork;
    if(j == N - 1){
   	   Lwork = Dis.at(0) + K - Dis.at(N-1);
    }else{
   		Lwork =  Dis.at(j+1) - Dis.at(j);
    }
    if(L < Lwork){
      L = Lwork;
    	}
  	}
  cout << K - L;
  
}


Measured memory_bytes: 1024
(let* ((n (read))
       (c (coerce (loop repeat n collect (read-char)) 'vector))
       (l 0)
       (r (1- (length c)))
       (count 0))
  (loop do (loop until (eql (aref c l) #\W)
                 while (< l r)
                 do (incf l))
        do (loop until (eql (aref c r) #\R)
                 while (< l r)
                 do (decf r))
        while (< l r)
        do (setf (aref c l) #\R
                 (aref c r) #\W
                 count (1+ count)
                 l (1+ l)
                 r (1- r)))
  (format t "~A~%" count))

Measured memory_bytes: 29308
s = list(str(input()))
cl = []
for i in set(s):
    tar = i
    temp = s[:]
    count = 0
    while len(set(temp)) != 1:
        for j in range(len(temp)):
            if j < len(temp)-1:
                if temp[j + 1] == tar:
                    temp[j] = tar
            else:
                temp.pop()
        count += 1
    cl.append(count)
print(min(cl))


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 100010
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
map<int,int>ma;
int n;
int a[maxn],b[maxn],c[maxn],d[maxn];
int book[maxn];
int fa[maxn];
int ans;
int find(int x)
{
    if(fa[x]==x)  return x;
    return fa[x]=find(fa[x]);
}
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    for(int i=1;i<=n;i++)  b[i]=read();
    for(int i=1;i<=n;i++)  a[n+1]^=a[i];
    for(int i=1;i<=n;i++)  b[n+1]^=b[i];
    int flag=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=b[i])  flag=1;
    }
    if(flag==0){
        puts("0");
        return 0;
    }
    n++;
    for(int i=1;i<=n;i++)  c[i]=a[i];
    for(int i=1;i<=n;i++)  d[i]=b[i];
    sort(c+1,c+n+1);sort(d+1,d+n+1);
    for(int i=1;i<=n;i++)
    {
        if(c[i]!=d[i])
        {
            puts("-1");
            return 0;
        }
    }
    int N=unique(c+1,c+n+1)-(c+1);
    for(int i=1;i<=N;i++)   ma[c[i]]=i;
    for(int i=1;i<=N;i++)   fa[i]=i;
    for(int i=1;i<=n-1;i++)
    {
        if(a[i]==b[i])  continue;
        int x=ma[a[i]],y=ma[b[i]];
        book[x]=book[y]=1;
        int u=find(x),v=find(y);
        if(u!=v)  fa[u]=v;
        ans++;
    }
    book[ma[a[n]]]=1;
    for(int i=1;i<=N;i++)   if(book[i]&&find(i)==i)  ans++;
    printf("%d\n",ans-1);
    return 0;
}

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

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

const int mod = 1e9 + 7;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint c[4005][4005];
void init() {
  c[0][0] = 1;
  rep(i, 4001) rep(j, i+1) {
    c[i+1][j] += c[i][j];
    c[i+1][j+1] += c[i][j];
  }
}

mint comb(int n, int k) {
  return c[n][k];;
}

mint f2(int n, int k) {
  return comb(n+k-1, k-1);
}

mint f(int n, int k) {
  if (n < k) return 0;
  if (n == 0 && k == 0) return 1;
  if (k < 1) return 0;
  return f2(n-k, k);
}

int main() {
  int n, k;
  cin >> n >> k;
  init();
  for (int i=1; i<=k; i++) {
    mint blue = f(k, i);
    mint red = f2(n-k-(i-1), i+1);;
    mint ans = blue * red;
    printf("%lld\n", ans.x);
  }
  return 0;
}


Measured memory_bytes: 125568
N = int(input())
s = [input() for k in range(N)]
s = [''.join(sorted(list(s_element))) for s_element in s]
memory = {}
result = 0
for s_element in s:
    if s_element not in memory:
        memory[s_element] = 1
    else:
        result += memory[s_element]
        memory[s_element] += 1
print(result)

Measured memory_bytes: 19852
#include <bits/stdc++.h> 
 
using namespace std;
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const LL INF=LONG_MAX;
const int MAX_V=1e5+3;
 
struct edge{int to;LL cost;};
typedef pair<LL,int> P;//firstは最短距離,secondは頂点番号
 
int V;
vector<edge> G[MAX_V];
LL d[MAX_V];
 
void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));
    
    while(!que.empty()){
        P p=que.top();que.pop();//仮の最短距離が短い順に取り出す
        int v=p.second;
        if(d[v]<p.first)continue;
        REP(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));//仮の最短距離と頂点の組を更新が行われる度に追加していく
            }
        }
    }
}
 
int main(){
    int N,Q,K;
    cin>>N;V=N;
    REP(i,N-1){
        int a,b;
        LL c;
        cin>>a>>b>>c;a--;b--;
        G[a].PB(edge{b,c});
        G[b].PB(edge{a,c});
    }
    cin>>Q>>K;
    K--;
    dijkstra(K);
    REP(i,Q){
        int x,y;
        cin>>x>>y;x--;y--;
        cout<<d[x]+d[y]<<endl;
    }
    return 0;
}

Measured memory_bytes: 11120
#include <iostream>
using namespace std;
int main(){
	int high[11] , i , j ;
	for( i=1 ; i<=10 ; i++ ){
		cin >> high[i] ;
	}
	for( i=1 ; i<=10 ; i++ ){
		for( j=1 ; j<=10 ; j++ ){
			if( high[i] > high[j] )
				swap( high[i] , high[j] );
		}
	}
	for( i=1 ; i<=3 ; i++ )
		cout << high[i] << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr ll MOD = 1e12;
constexpr double PI = 3.14159265358979323846;
vector<int> cnt = {0,2,5,5,4,5,6,3,7,6};

struct usednum{
    int used[10] = {0};
    int sum = 0;
};

int main(){
    int n,m;
    cin >> n >> m ;
    vector<int> a(m);
    rep(i,m) cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());

    vector<usednum> dp(n+1);
    for(int i=1;i<=n;i++){
        for(int j=0;j<m;j++){
            if(i - cnt[a[j]] < 0) continue;
            if(i - cnt[a[j]] > 0 && dp[i-cnt[a[j]]].sum == 0) continue;
            if(dp[i].sum < dp[i-cnt[a[j]]].sum + 1){
                dp[i] = dp[i-cnt[a[j]]];
                dp[i].used[a[j]] ++;
                ++ dp[i].sum;
            }else if(dp[i].sum == dp[i-cnt[a[j]]].sum + 1){
                dp[i-cnt[a[j]]].used[a[j]] ++;
                rep(k,m){
                    if(dp[i].used[a[k]] < dp[i-cnt[a[j]]].used[a[k]]){
                        dp[i] = dp[i-cnt[a[j]]];
                        ++ dp[i].sum;
                        break;
                    }else if(dp[i].used[a[k]] > dp[i-cnt[a[j]]].used[a[k]]){
                        break;
                    }
                }
                dp[i-cnt[a[j]]].used[a[j]] --;
            }
        }
    }
   

    string ans;
    rep(i,m){
        rep(j,dp[n].used[a[i]]){
            ans += (char)(a[i] + '0');
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
from collections import Counter
N, K, mod = map(int, input().split())
dp = [Counter() for _ in range(2*N)]

dp[0][(None, (0,))] = 1
for i in range(2*N-1):
    for (left, top), v in dp[i].items():
        if len(top) > K+1:
            continue
        if left == None:
            if top and i+1 - top[0] <= K:
                dp[i+1][(i+1, top)] = (dp[i+1][(i+1, top)] + v) % mod 
        elif (i+1 - left <= K) and len(top) > 1 and (i+1 - top[1] <= K):
            dp[i+1][(i+1, top[1:])] = (dp[i+1][(i+1, top[1:])] + v) % mod
        if top and (i+1 - top[-1] <= K):
            top = list(top)
            top.append(i+1)
            top = tuple(top)
            dp[i+1][(left, top)] = (dp[i+1][(left, top)] + v) % mod

res = 0
for (left, top), v in dp[2*N-1].items():
    if len(top) == 1:
        assert left == 2*N - 1
        res = (res + v) % mod
print(res)



Measured memory_bytes: 188616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define cu continue
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf LLONG_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define f first
#define s second
#define vll vector <ll>
#define dbg(n) cout<<n<<' ';

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


    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    for(ll i=0;i<n-k;i++)
        ans+=a[i];
    cout<<ans<<'\n';
}       


Measured memory_bytes: 1792
n=int(input())
ans=[]
if n%2==0:
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i+j!=n+1:
                ans.append([i,j])
else:
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i+j!=n:
                ans.append([i,j])
print(len(ans))
for i,j in ans:
    print(i,j)


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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	vector<ll> a(7);
	REPU(i, 0, 7) cin >> a[i];
	ll res = a[1] + a[0] / 2 * 2 + a[3] / 2 * 2 + a[4] / 2 * 2;
	ll ans = res;
	REPU(i, -1, 1) if (a[0] + i >= 0) {
		REPU(j, -1, 1) if (a[3] + j >= 0) {
			REPU(k, -1, 1) if (a[4] + k >= 0) {
				ll tmp = a[1] + (a[0] + i) / 2 * 2 + (a[3] + j) / 2 * 2 + (a[4] + k) / 2 * 2;
				bool ok(true);
				if (!(i < 0 || a[0] % 2 == 1)) ok = false;
				if (!(j < 0 || a[3] % 2 == 1)) ok = false;
				if (!(k < 0 || a[4] % 2 == 1)) ok = false;
				if (ok) amax(ans, tmp + 3);
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()

def main():
    X, Y = map(int, input().split())
    """
    必勝法は「相手に山の差が１になるようにターンを渡すこと」
    そしたら相手がどんな操作をしてきても再び山の差を１にできるので、
    最終的には(0, 0), (0, 1), (1, 0)のどれかの状態を相手にわたすことになる。

    これどうやったら気づけるの？定常状態があるのがこの手の問題の定石？
    """
    if abs(X - Y) <= 1:
        print("Brown")
    else:
        print("Alice")
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 62096
k , n = map(int,input().split())
a = list(map(int,input().split()))
x = 0
for i in range(n-1):
  if x < a[i+1]-a[i]:
    x = a[i+1] - a[i]
if x < a[0] + k - a[n-1]:
  x = a[0] + k - a[n-1]
print(k-x)

Measured memory_bytes: 26420
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;
 
typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)round(x))<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

int main(void){
  int n;

  while(cin >> n){
    if(n == 0){
      break;
    }
    if(n == 1){
      cout << 0 << endl;
      continue;
    }

    int sum = 0;
    int lo = 1;
    int hi = 1;
    int ans = 0;

    while(lo < n){
      while(sum < n){
        sum += hi; hi++;
      }

      if(sum == n){
        ans++;
        sum -= lo; lo++;
      }

      while(sum > n){
        sum -= lo; lo++;
      }

      if(sum == n){
        ans++;
        sum += hi; hi++;
      }
    }

    cout << ans - 1 << endl;
  }
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
import sys

def main():
	N = int(input())
	tmp = input().split(" ")
	field = []
	field.append([int(s) for s in tmp])
	tmp2 = input().split(" ")
	field.append([int(s) for s in tmp2])
	
	ans = 0
	sp = N-1
	for _ in range(N):
		tmp = 0
		i = 0
		for j in range(N):
			tmp += field[i][j]
			if j == sp:
				i = 1
				tmp += field[i][j]
		sp -= 1
		if ans < tmp:
			ans = tmp
		
	print(ans)
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 3064
A,B,C,X,Y  = map(int,input().split())
AB = A*X + B*Y
ans = AB #すべてAとBで

for i in range(max(X,Y)+1):
  c = C * 2*i# 2*i個のCでAとBでを１つづつ
  a = max(0,X-i)*A#不足分Aの代金
  b = max(0,Y-i)*B#不足分B
  ans = min(ans,c+a+b)
print(ans)

Measured memory_bytes: 9080
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N, W;
    cin >> N >> W;

    vector<ll> V0;
    vector<ll> V1;
    vector<ll> V2;
    vector<ll> V3;

    ll w1 = -1;
    FOR(i, 0, N){
        ll w, v;
        cin >> w >> v;
        
        if(w1==-1){
            w1 = w;
        }

        ll diff = w - w1;
        switch(diff){
            case 0:
                V0.push_back(v);
                break;
            case 1:
                V1.push_back(v);
                break;
            case 2:
                V2.push_back(v);
                break;
            case 3:
                V3.push_back(v);
                break;
        }
    }

    sort(ALL(V0), greater<ll>());
    sort(ALL(V1), greater<ll>());
    sort(ALL(V2), greater<ll>());
    sort(ALL(V3), greater<ll>());

    ll n0 = V0.size();
    ll n1 = V1.size();
    ll n2 = V2.size();
    ll n3 = V3.size();

    // 価値の累積和
    ll Ac0[n0];
    ll Ac1[n1];
    ll Ac2[n2];
    ll Ac3[n3];

    if(n0>0) Ac0[0] = V0[0];
    FOR(i, 1, n0){
        Ac0[i] = Ac0[i-1] + V0[i];
    }

    if(n1>0) Ac1[0] = V1[0];
    FOR(i, 1, n1){
        Ac1[i] = Ac1[i-1] + V1[i];
    }

    if(n2>0) Ac2[0] = V2[0];
    FOR(i, 1, n2){
        Ac2[i] = Ac2[i-1] + V2[i];
    }

    if(n3>0) Ac3[0] = V3[0];
    FOR(i, 1, n3){
        Ac3[i] = Ac3[i-1] + V3[i];
    }

    ll value_max = 0;
    FOR(i, 0, n0+1){
        FOR(j, 0, n1+1){
            FOR(k, 0, n2+1){
                FOR(l, 0, n3+1){

                    ll value = 0;
                    ll weight = 0;

                    if(i>0){
                        value += Ac0[i-1];
                        weight += i * w1;
                    }
                    if(j>0){
                        value += Ac1[j-1];
                        weight += j * (w1+1);
                    }
                    if(k>0){
                        value += Ac2[k-1];
                        weight += k * (w1+2);
                    }
                    if(l>0){
                        value += Ac3[l-1];
                        weight += l * (w1+3);
                    }
                    
                    if(weight <= W){
                        value_max = max(value_max, value);
                    }









                }
            }
        }
    }

    p(value_max);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N=1e3+10;
const int MOD=1e9+7;
int main(){
    int a,b;
    long long int dp[N][N];
    string l,r;
    cin>>l>>r;
    a=(int)l.size();
    b=(int)r.size();
    for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=0;
    for(int i=1;i<=a;i++)dp[i][1]=dp[i-1][1]+(l[i-1]==r[0]?1:0);
    for(int i=1;i<=a;i++)for(int j=2;j<=b;j++){
        dp[i][j]=dp[i-1][j];
        if(l[i-1]==r[j-1])dp[i][j]+=dp[i-1][j-1];
        dp[i][j]%=MOD;
    }
    printf("%lld\n",dp[a][b]%MOD);
}


Measured memory_bytes: 11156
#include <bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define bp __builtin_popcountll
#define f(i,l,n) for(int i=l;i<n;i++)
#define E "\n"
#define MOD  (int)(1e9+7)
 
#define float long double
 
 
int ADD(int &a,int &b)
{
  return (a%MOD + b%MOD )%MOD;
}
 
 
 
int ADD(int &a,int &b,int &c)
{
  return ( ADD(a,b) + c%MOD )%MOD;
}
 
 
int n,m;
 
 
 
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
int32_t main()
{
  FAST;
 
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt" , "w" , stdout);
  // #endif
 
	int n,m;
	cin >> n >> m;
	int ans;
	if(n!=0) ans+=(n*(n-1))/2;
	if(m!=0) ans+=(m*(m-1))/2;
    cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctime>
#include<cmath>
#include<utility>
#include<cstdlib>
#include<bitset>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iomanip>
using namespace std;                       

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const ll M = 1e9 + 7;

ll add(ll a, ll b){
    (a += b)%=M;
    (a += M)%=M;
    return a;
}

ll mul(ll a, ll b){
    (a *= b)%=M;
    (a += M)%=M;
    return a;
}

ll fastpo(ll a, ll x){
    if(x == 0) return 1ll;
    if(x == 1) return a;
    ll y = fastpo(a, x/2);
    if(x%2 == 0){
        return y*y;
    }
    return y*y*a;
}

ll inv(ll a, ll M){
    return fastpo(a, M-2);
}

ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1) 
        return -1; 
    else
    { 
        ll res = (x%m + m) % m; 
        return res;
    } 
}


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

ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}

void print(vector<int> &a){
    int n = a.size();
    for(int i=0; i<n; i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}



int main(){
//    clock_t time_req;
//     time_req = clock();
    fastio;
    int x;
    cin>>x;
    if(x >= 30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    // print(cost);
    // print(cost1);
    // time_req = clock()-time_req;
    // cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int N, X;
    cin >> N >> X;
    X = min(X, N - X);

    int a = N - X;
    int b = X;
    int ans = 0;
    while (b != 0) {
        int shou = a / b;
        ans += b * shou;
        int amari = a % b;
        a = b;
        b = amari;
    }
    cout << 3 * ans << endl;

}


Measured memory_bytes: 256
// In His Name

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define ll long long
#define gcd __gcd

using namespace std;

typedef pair<int, int> pii;

const int INF = 1e5;
int ans = INF;

int MakeNum (char a, char b, char c){
    int x = a - '0';
    int y = b - '0';
    int z = c - '0';
    int Num = x * 100 + y * 10 + z;
    return (abs (753 - Num));
}

int main(){
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	for (int i = 0 ; i < s.size() - 2 ; i++){
        ans = min (MakeNum(s[i] , s[i+1] , s[i+2]) , ans);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	ll a, b;cin >> a >> b;
	vector<ll> x(n);
	rep(i,n) cin >> x.at(i);
	ll ans = 0;
	rep(i,n - 1){
		ans += min((x.at(i + 1) - x.at(i)) * a, b);
	}
	cout << ans << endl;
}


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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    ll n,k;
    cin>>n>>k;
    double a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i] = (1+a[i])/2.0;
    }
    double ans = 0;
    double now = 0;
    for(int i=0;i<k;i++){
        now += a[i];
    }
    ans = now;
    for(int i=k;i<n;i++){
        now -= a[i-k];
        now += a[i];
        ans = max(ans,now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:128777216")
  
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <sstream>
  
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
  
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <string.h>
  
#include <memory.h>
#include <cassert>
#include <time.h>
  
using namespace std;
  
#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i,a,b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, b, a) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
  
#define _(a, val) memset (a, val, sizeof (a))
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
  
typedef long long lint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;
  
const lint LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;
  
#ifdef MY_DEBUG
#define dbgx( x ) { cerr << #x << " = " << x << endl; }
#define dbg( ... ) { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#else
#define dbgx( x ) {  } 
#define dbg( ... ) {  } 
#endif
  
void prepare(string s)
{
#ifdef MY_DEBUG
    freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
#else
    if (s.length() != 0)
    {
        freopen ((s + ".in").c_str(), "r", stdin);
        freopen ((s + ".out").c_str(), "w", stdout);
    }
#endif
}

const int NMAX = 200005;
const int lg = 60;
int n;
lint k;
int a[NMAX][lg];

void read() {
  scanf("%d %lld", &n, &k);
  forn(i, n) {
    scanf("%d", &a[i][0]);
    a[i][0]--;
  }
}

void solve() {
  forab(i, 1, lg - 1) {
    forn(j, n) {
      a[j][i] = a[a[j][i - 1]][i - 1];
    }
  }

  int v = 0;
  while (k > 0) {
    fornd(i, lg - 1) {
      lint jump = (1LL << i);
      if (k >= jump) {
        v = a[v][i];
        k -= jump;
      }
    }
  }
  printf("%d\n", v + 1);
}

int main() {
  prepare("");

  read();
  solve();
  return 0;
}

Measured memory_bytes: 50656
package main

import (
	"bufio"
	"os"
	"fmt"
	"strings"
)

func main() {
	S := scan()
	ords := strings.Split(S, "")
	ramen := 700
	for _, ord := range ords {
		if ord == "o" {
			ramen += 100
		}
	}
	fmt.Println(ramen)
}

func scan() string {
	reader := bufio.NewReaderSize(os.Stdin, 1000000)
	bytes := make([]byte, 0, 1000000)
	for {
		line, isPrefix, _ := reader.ReadLine()
		bytes = append(bytes, line...)
		if !isPrefix {
			break
		}
	}
	return string(bytes)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

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

  for (auto &e : s) {
    if (e == '1')
      e = '9';
    else if (e == '9')
      e = '1';
  }

  puts(s.c_str());

  return 0;
}

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

int main() {
string s;
cin >> s;
int t = 0;
for( int l = 0; l < s.size()-1-l; l++ ){
 if( s.at(l) != s.at( s.size()-1-l ) ){
 	t++;
 }
 else{
 	t = t+0;
 }
}
 cout << t << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n == 0) break;
			boolean state = false;
			int count = 0;
			boolean left = false;
			boolean right = false;
			for(int i=0; i<n; i++){
				char[] f = in.next().toCharArray();
				if(f[0] == 'l') left = !left;
				else right = !right;
				if(right == left){
					if(left != state){
						count++;
						state = left;
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 26948
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右攜下昴 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 敘大公約摧
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 敘擣公倍摧
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/


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

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

	// ちょうどK個つくってあげる

	// 木構造
	// いらない分は一本に伸ばしてあげる

	//まずできるか
	ll sum = 0;
	rep(i, n - 1) sum += i;
	if (sum < k) {
		cout << -1 << endl;
		return 0;
	}

	// 一本線でも最短距離2は存在する l - 2個

	// ここ変えなきゃ
	if (true) {
		// 閉路を作らなきゃいけない

		// すべてが中心からつながっている
		vector<pair<int, int>> ans;
		Rep(i, 1, n) {
			ans.push_back({ i + 1, 1 });
		}
		// さらに閉路を作ってあげる
		int tmp = sum;
		// 一個一個つなげる
		int i = 2;
		int j = 3;
		int m = n - 1;
		while (tmp != k) {
			ans.push_back({ i, j });
			j++;
			if (j > n) {
				i++;
				j = i + 1;
			}
			tmp--;
			m++;
		}

		cout << m << endl;
		rep(l, m) {
			cout << ans[l].first << " " << ans[l].second << endl;
		}

		return 0;
	}

	int index = -1;
	// k個存在する
	// 何頂点で作るか全探索
	Rep(i, 3, n + 1) {
		ll first = 0;
		rep(j, i - 1) {
			first += j;
		}
		ll second = 0;
		second = n - (i - 2) - 2;

		//cout << first + second << endl;
		if (first + second == k) {
			index = i;
			break;
		}
	}

	if (index == -1) { // ここは関係なかった 絶対できる
		cout << -1 << endl;
		return 0;
	}

	// グラフを作ってあげる
	ll m = n - 1;
	vector<pair<int, int>> ans;
	// まずindexの個数
	// 中央を1にする
	Rep(i,1, index) {
		ans.push_back({ i + 1, 1 });
	}

	// 次に一番大きい点から伸ばしてあげる
	Rep(i, index, n) {
		ans.push_back({ i, i + 1 });
	}

	cout << m << endl;
	rep(i, m) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    double a, b; cin >> a >> b;
    for (int i = ceil(a / 0.08); i < floor((a + 1) / 0.08); i++) {
        if (b / 0.1 <= i && i < (b + 1) / 0.1) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

int main()
{
    int x, y;
    cin >> x;
    if(x<600)y=8;
    else if(x<800)y=7;
    else if(x<1000)y=6;
    else if(x<1200)y=5;
    else if(x<1400)y=4;
    else if(x<1600)y=3;
    else if(x<1800)y=2;
    else y=1;
    cout << y;
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        char[] array = s.toCharArray();
        long countA = 0;

        long result = 0;
        for (int i = 0; i < array.length - 1; i++) {
            if (array[i] == 'A') {
                countA++;
            } else if (0 < countA) {
                if (array[i] == 'B' && array[i + 1] == 'C') {
                    result += countA;
                    i++;
                } else {
                    countA = 0;
                }
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 40512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
    long long a;
    cin >> a;
    a++;
    while(--a){
        if(sqrt(a)>floor(sqrt(a)))
            continue;
        else if(sqrt(a)==floor(sqrt(a))){
            cout << a;
            break;
        }
    }
	return 0;
}

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

// Author - Kevin Mathew
// Birla Institute of Technology, Mesra

ll n, a[((ll)(1e5 + 10L))], dp[((ll)(1e5 + 10L))];

ll solve(ll x){
	if(x == n-1)
		return 0;
	if(x > n-1)
		return 9999999999999;
	if(dp[x] != -1)
		return dp[x];

	return dp[x] = min(abs(a[x]-a[x+1]) + solve(x+1), abs(a[x]-a[x+2]) + solve(x+2));
}

void te(){
	cin >> n;
	for(ll i=0;i<n;i++){
		cin >> a[i];
		dp[i] = -1;
	}

	cout << solve(0) << "\n";
}

int main()
{
	//freopen("input.txt", "r", stdin);		//Comment
	//freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	te();

	return 0;
}

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

namespace M_SOLUTIONSプロコンオープン_D___Maximum_Sum_of_Minimum
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var connections = new List<int>[N + 1];
            for (int i = 0; i < N + 1; i++) connections[i] = new List<int>();
            for (int i = 0; i < N - 1; i++)
            {
                var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                connections[ab[0]].Add(ab[1]);
                connections[ab[1]].Add(ab[0]);
            }

            var C = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse).OrderByDescending(n => n).ToArray();
            var sum = C.Sum() - C[0];
            var Cqueue = new Queue<int>(C);
            var numbers = new int[N];
            var queue = new Queue<int>();
            queue.Enqueue(1);
            var Cmax = 0;
            while (queue.Count > 0)
            {
                var current = queue.Dequeue();
                numbers[current - 1] = Cqueue.Dequeue();
                foreach (int i in connections[current]) if (numbers[i - 1] == 0) queue.Enqueue(i);
            }
            Console.WriteLine(sum);
            Console.WriteLine(string.Join(" ", numbers));
        }
    }
}


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

int main() {
	int n,a,b,c;cin>>n>>a>>b>>c;
	vector<int> l(n);
	for(auto& x:l){
		cin>>x;
	}
	int ans=-1;
	int def=1;
	for(int i=0;i<n;i++){
		def*=4;
//		cout<<def<<endl;
	}

	for(int i=0;i<def;i++){
		int i2=i;
		vector<int> abc(4,0);
		vector<int> abca(4);
		abca[1]=a;
		abca[2]=b;
		abca[3]=c;
		int t=0;
		for(int j=0;j<n;j++){
			int num=i2%4;
			i2/=4;
			if(abc[num]*num){
				t+=10;
			}
			abc[num]+=l[j];
		}
		if(abc[1]*abc[2]*abc[3]==0){
			continue;
		}
		for(int j=1;j<=3;j++){
			int add=abc[j]-abca[j];
			if(add<0)add*=-1;
			t+=add;
		}

		if(t<ans){
			ans=t;
//			cout<<i<<' '<<t<<endl;
//			cout<<abc[1]<<' '<<abc[2]<<' '<<abc[3]<<endl;
		}
		if(ans==-1)ans=t;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

int n,k;
vector<int> g[100000];
int ma[100000],mi[100000];
int ans[100000];
bool flg[100000];

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

	cin>>n;
	REP(i,n-1) {
		int a,b;cin>>a>>b;a--,b--;
		g[a].pb(b),g[b].pb(a);
	}
	REP(i,n) ma[i]=-INF,mi[i]=INF,ans[i]=-INF;

	cin>>k;
	queue<int> q,qq;
	REP(i,k) {
		int v,p;cin>>v>>p;v--;
		ma[v]=p,mi[v]=p;
		q.push(v);
		qq.push(v);
		flg[v]=true;
		ans[v]=p;
	}
	while(!q.empty()) {
		int v=q.front();q.pop();
		for(auto u:g[v]) {
			if(abs(ma[u]-ma[v])==1&&abs(mi[u]-mi[v])==1) continue;
			if(ma[u]==-INF&&mi[u]==INF) {
				ma[u]=ma[v]+1,mi[u]=mi[v]-1;
				q.push(u);
			}
			else if(ma[u]<mi[v]-1||mi[u]>ma[v]+1||ma[u]%2==ma[v]%2) {
				cout<<"No"<<endl;
				return 0;
			}
			else if(flg[u]) continue;
			else {
				mi[u]=max(mi[u],mi[v]-1);
				ma[u]=min(ma[u],ma[v]+1);
				q.push(u);
			}
		}
		//cout<<"v="<<v<<endl;
		//REP(i,n) cout<<ma[i]<<' '<<mi[i]<<endl;
	}
	while(!qq.empty()) {
		int v=qq.front();qq.pop();
		for(auto u:g[v]) {
			if(ans[u]!=-INF) continue;
			if(ma[u]+1==ans[v]) ans[u]=ans[v]-1;
			else ans[u]=ans[v]+1;
			qq.push(u);
		}
	}
	cout<<"Yes"<<endl;
	REP(i,n) cout<<ans[i]<<endl;


	return 0;
}


Measured memory_bytes: 9344
n=int(input())
rst=['AC','WA','TLE','RE']
cnt=[0,0,0,0]
for i in range(0,n):
    a=input()
    for j in range(0,4):
        if a==rst[j]:
            cnt[j]=cnt[j]+1
            break

for i in range(0,4):
    print(rst[i]," x ",cnt[i])


Measured memory_bytes: 9200
s=input()

N=0
S=0
E=0
W=0

for i in s:
	if i=="N":
		N=1
	if i=="S":
		S=1
	if i=="E":
		E=1
	if i=="W":
		W=1
		
if N+S==1 or E+W==1:
	ans="No"
else:
	ans="Yes"
print(ans)

Measured memory_bytes: 3064