akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

namespace seg{
int N;
P dat[400000];

void init(int n){
	N=1;while(N<n)N<<=1;
}
P merge(P a,P b){
	if(a.first)b.second*=-1;
	return P(a.first^b.first,a.second+b.second);
}
void update(int k,P x){
	k+=N;
	dat[k]=x;
	while(k>1){
		k>>=1;
		dat[k]=merge(dat[k*2],dat[k*2+1]);
	}
}
P query(int l,int r){
	P resl(0,0),resr(0,0);
	for(l+=N,r+=N;l<r;l>>=1,r>>=1){
		if(l&1)resl=merge(resl,dat[l++]);
		if(r&1)resr=merge(dat[--r],resr);
	}
	return merge(resl,resr);
}
};

int a[200000];
int main(){
	int K,n,q;cin>>K>>n>>q;
	rep(i,n){
		scanf("%d",&a[i]);a[i]*=-1;
	}
	seg::init(n);
	rep(i,n){
		seg::update(i,P(!a[i],a[i]));
	}
	rep(i,q){
		int l,r;scanf("%d%d",&l,&r);l--;r--;
		swap(a[l],a[r]);
		seg::update(l,P(!a[l],a[l]));
		seg::update(r,P(!a[r],a[r]));
		auto p=seg::query(0,n);
		ll sum=((p.second%K)+K)%K;
		sum=(sum+K)%K;
		int ans=sum+1;
		if(p.first)ans=-ans;
		printf("%d\n",ans);
	}
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll h,w;cin >>h>>w;
    vector<string>s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    ll ans=0;
    for (int sx = 0; sx < w; ++sx) {
        for (int sy = 0; sy < h; ++sy) {
            vector<vector<ll>>d(w,vector<ll>(h,INF));
            if(s[sy][sx]=='#')continue;
            queue<P>que;
            d[sx][sy]=0;
            que.push({sx,sy});
            auto add=[&](ll x,ll y,ll di){
                if(x<0||x>=w)return;
                if(y<0||y>=h)return;
                if(s[y][x]=='#')return;
                if(d[x][y]>di) {
                    d[x][y] = di;
                    que.push({x, y});
                    ans = max(di, ans);
                }
            };
            while(!que.empty()){
                P p=que.front();que.pop();
                ll x=p.first;
                ll y=p.second;
                add(x+1,y,d[x][y]+1);
                add(x-1,y,d[x][y]+1);
                add(x,y+1,d[x][y]+1);
                add(x,y-1,d[x][y]+1);
            }
        }
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{    
	char s[100005];    
	scanf("%s", s);   
	 int sum=0, len=strlen(s), p=0, g=0;    
	 for(int i=0;i<len;i++)    
	{        
	 	if(s[i]=='g')       
	  	{            
	  	if(g>p)            
	 	{                
	  		sum++;                
	  p++;        
	      }          
		    else                
			g++;      
			  }      
			    else      
				  {           
				   if(g>p)                
				   p++;            
				   else            
				   {                
				   sum--;                
				   g++;            
				   }
				           }    
						   }    
						   printf("%d\n", sum);    
						   return 0;
} 

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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int l, r, d;
  cin >> l >> r >> d;

  int cnt = 0;
  for (int i = l; i <= r; i++) {
    if (i % d == 0) {
      ++cnt;
    }
  }
  cout << cnt << endl;
}

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

  solve();
  return 0;
}


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


int main() {

    int n;
    cin >> n;
    vector<string> w(n);
    rep(i,n) cin >> w[i];
    set<string> s;
    int cnt = 0;
    for (int i = 0; i < n-1; ++i) {
        if (w[i][w[i].size()-1] == w[i+1][0]) {
            ++cnt;
        }
    }
    rep(i,n) s.insert(w[i]);
    if (cnt == n-1 && s.size() == n) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
int a,b,c;
scanf("%d %d %d\n",&a,&b,&c);
if(a>=b && b>=c){
  printf("%d %d %d\n",c,b,a);
}else if(a>=c && c>=b){
  printf("%d %d %d\n",b,c,a);

}else if(b>=a && a>=c){
  printf("%d %d %d\n",c,a,b);
}else if(b>=c && c>=a){
  printf("%d %d %d\n",a,c,b);

}else if(c>=a && a>=b){
  printf("%d %d %d\n",b,a,c);
}else if(c>=b && b>=a){
  printf("%d %d %d\n",a,b,c);
}
return 0; 
}

Measured memory_bytes: 2688
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
n = int(input())
s = []
for i in range(n):
  s.append(input().replace('\n',''))
# print(s)
print('AC x {}'.format(s.count('AC')))
print('WA x {}'.format(s.count('WA')))
print('TLE x {}'.format(s.count('TLE')))
print('RE x {}'.format(s.count('RE')))

Measured memory_bytes: 16212
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))

void run (void) {
  i32 a, b;
  scanf ("%" SCNi32 "%" SCNi32, &a, &b);
  if (a <= 5) {
    puts ("0");
  } else if (a <= 12) {
    printf ("%" PRIi32 "\n", b / 2);
  } else {
    printf ("%" PRIi32 "\n", b);
  }
}

int main (void) {
  run();
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    int nmin = N;
    int nmax = 0;
    for (int i = 0; i < N; i++) {
        nmin = min(nmin, a[i]);
        nmax = max(nmax, a[i]);
    }
    if (nmax-nmin>1) {
        cout << "No" << endl;
    }
    else if (nmax == nmin) {
        if (nmax <= N/2 || nmax == N-1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        int s = count(a.begin(), a.end(), nmin);
        int t = N-s;
        if (t >= 2 && s+1 <= nmax && nmax <= s+t/2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
        
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 200000000000000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

template <class T>
class SegmentTree{
  ll N;                         //葉の数
  vector<T> data;               //データを格納(要素数2*N-1)
  T def;                        //初期値かつoperationの単位元
  function<T(T,T)> operation;   //区間クエリで使う関数ラムダ式で入れる
  function<T(T,T)> update;      //一点更新で使う関数

  T _query(ll a,ll b,ll k,ll l,ll r){   //区間(a,b)を考え半開区間[l,r)が管轄
      if(b <= l || r <= a) return def;  
      if(a <= l && r <= b){
          return data[k];
      }else{
          T c1 = _query(a,b,k*2+1,l,(l+r)/2);   //左の子
          T c2 = _query(a,b,k*2+2,(l+r)/2,r);   //右の子
          return operation(c1,c2);
      }
  }
  public:
  SegmentTree(size_t _N,T _def,function<T(T,T)> _operaition,function<T(T,T)> _update):def(_def),operation(_operaition),update(_update){
          N = 1;                //N必要サイズにNを調整
          while(N < _N){
              N *= 2;
          }
          data = vector<T>(2*N-1,def);
  }

  void change(ll i,T x){
      i += N-1;
      data[i] = update(data[i],x);
      while(i > 0){
          i = (i-1)/2;
          data[i] = operation(data[i*2+1],data[i*2+2]);
      }
  }

  T query(ll a,ll b){
      return _query(a,b,0,0,N);
  }

  T operator[](ll i){
      return data[i+N-1];
  }
};


int main(){
  ll N;
  cin >> N;
  vector<ll> H(N),A(N);
  rep(i,N) cin >> H[i];
  rep(i,N) cin >> A[i];
  auto f = [](ll a,ll b){return max(a,b);};
  auto g = [](ll a,ll b){return b;};
  SegmentTree<ll> ST(N,0,f,g);
  rep(i,N){
    H[i]--;
    ST.change(H[i],ST.query(0,H[i])+A[i]);
  }
  cout << ST.query(0,N) << endl;
} 


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  rep(i,D) rep(j,26) cin >> s[i][j];
  rep(i,D) cout << 1 << endl;
  return 0;
} 

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

#include <boost/algorithm/string/classification.hpp>  // is_any_of
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/math/tools/minima.hpp>
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

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

namespace adaptor = boost::adaptors;
using namespace std;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::algorithm::split;
using boost::math::tools::brent_find_minima;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP
void Main()
{
	int n;
	cin >> n;
	rep(i, 2)
	{
		rep(j, 2)
		{
			rep(k, 2)
			{
				int a, b, c, d;
				a = n / 1000;
				b = (n % 1000) / 100;
				c = (n % 100) / 10;
				d = n % 10;
				char x = '+';
				char y = '+';
				char z = '+';
				if (i)
				{
					b *= -1;
					x = '-';
				}
				if (j)
				{
					c *= -1;
					y = '-';
				}
				if (k)
				{
					d *= -1;
					z = '-';
				}
				if (a + b + c + d == 7)
				{
					cout << a << x << abs(b) << y << abs(c) << z << abs(d) << "=7" << endl;
					return;
				}
			}
		}
	}
}
// END

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


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

typedef long long int ll;


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

    queue<string> q;
    for(ll i = 1;i <= 9;i++){
        string t;
        t += i + '0';
        q.push(t);
    }
    ll cnt = 1;

    while(!q.empty()){
        string t = q.front();
        q.pop();
        if(cnt == k){
            cout << t;
            break;
        }
        else{
            cnt++;
        }
        if(t[t.size() - 1] - 1 >= '0'){
            t.push_back(t[t.size() - 1] - 1);
            q.push(t);
            t.pop_back();
        }
        t.push_back(t[t.size() - 1]);
        q.push(t);
        t.pop_back();
        if(t[t.size() - 1] + 1 <= '9'){
            t.push_back(t[t.size() - 1] + 1);
            q.push(t);
            t.pop_back();
        }
    }

    return 0;
}

Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>

using namespace std;

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

    bool a[4][14];
    for (int i = 0; i < 4; i++)
    {
        for (int j = 1; j <= 13; j++)
        {
            a[i][j] = false;
        }
    }

    char s;
    int m, k;
    for (int i = 0; i < n; i++)
    {
        cin >> s >> m;
        switch (s)
        {
        case 'S':
            k = 0;
            break;
        case 'H':
            k = 1;
            break;
        case 'C':
            k = 2;
            break;
        case 'D':
            k = 3;
            break;
        }

        a[k][m] = true;
    }

    for (int i = 0; i < 4; i++)
    {
        for (int j = 1; j <= 13; j++)
        {
            if (!a[i][j])
            {
                switch (i)
                {
                case 0:
                    s = 'S';
                    break;
                case 1:
                    s = 'H';
                    break;
                case 2:
                    s = 'C';
                    break;
                case 3:
                    s = 'D';
                    break;
                }

                cout << s << " " << j << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3076
import heapq
N,M=map(int,input().split())
R=[]
G=[[] for i in range(N)]
for i in range(M):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    G[a].append((b,c))
    G[b].append((a,c))
    R.append((a,b,c))
Q=[[0]*N for i in range(N)]
INF=10**9
for i in range(N):
    stack=[]
    g=[INF for i in range(N)]
    g[i]=0
    n=1
    for b,c in G[i]:
        heapq.heappush(stack,(g[i]+c,i,b))
    used=[[0]*N for i in range(N)]
    while(stack):
        if n==N:
            break
        c,a,b=heapq.heappop(stack)
        g[b]=min(g[b],c)

        used[a][b]=1
        used[b][a]=1
        for j in G[b]:
            if used[b][j[0]] or g[j[0]]!=INF:
                continue
            if g[j[0]]<=g[b]+j[1]:
                continue
            heapq.heappush(stack,(g[b]+j[1],b,j[0]))
    for j in range(i+1,N):
        Q[i][j]=g[j]
ans=0
for a,b,c in R:
    if b<a:
        a,b=b,a
    if Q[a][b]<c:
        ans+=1
print(ans)


Measured memory_bytes: 3820
#include<iostream>
 #include<algorithm>
 #include<array>
 
 using namespace std;
 int main()
 {
     int a[4];
     for(int i=0;i<4; i++)
     cin>>a[i];
     
     sort(a,a+4);
     if(a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9)
     cout<<"YES";
     else
     cout<<"NO";
 }

Measured memory_bytes: 256
x,k,d = map(int,input().split())
x = abs(x)
n = x//d
#print(k-n,(abs(x-d*k)),(abs(x-(x//d)*d-d)),abs(x-(x//d)*d))
if n >= k:
    print(abs(x-d*k))
elif n < k:
    if (k-n)%2 == 1:
        print((abs(x-(x//d)*d-d)))#,abs(x-(x//d)*d)))
    else:
        print(abs(x-(x//d)*d))
        #print(min(abs(x%d),abs(x%d-d)))

Measured memory_bytes: 9160
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        String s = scanner.next();
        int temp = (int)s.chars().filter(c -> c == 'E').count() - (s.charAt(0) == 'E' ? 1 : 0), ans = temp;
        for (int i = 1; i < n; i++)
            ans = Math.min(ans, temp += (s.charAt(i - 1) == 'E' ? 0 : 1) - (s.charAt(i) == 'E' ? 1 : 0));
        System.out.println(ans);
    }
}

Measured memory_bytes: 35172
//  Created by Sengxian on 2017/6/3.
//  Copyright (c) 2017年 Sengxian. All rights reserved.
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
inline int readInt() {
	int n = 0, ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
	return n;
}

const int MAX_N = 100 + 3, MAX_VAL = 100 + 3, MAX_SUM = MAX_N * MAX_VAL;
int n, s[MAX_N];
bool dp[MAX_SUM];

int main() {
	n = readInt();
	dp[0] = true;	
	for (int i = 0; i < n; ++i) {
		s[i] = readInt();
		for (int j = MAX_SUM - 1; j >= s[i]; --j)
			dp[j] |= dp[j - s[i]];	
	}
	
	int mx = 0;
	for (int i = MAX_SUM - 1; i >= 0; --i)
		if (i % 10 != 0 && dp[i]) {
			mx = i;
			break;
		}
	
	printf("%d\n", mx);
	
	return 0;
}


Measured memory_bytes: 256
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
a = [0] * (10 ** 5)
if d[0] != 0 or d.count(0) != 1:
  print(0)
  exit()
for i in d:
  a[i] += 1
now = a[1]
if now == 0:
  if n == 1:
    print(1)
    exit()
  else:
    print(0)
    exit()
ans = 1
now_sum = now + 1
for i in a[2:]:
  if not i:
    if n != now_sum:
      ans = 0
    break
  else:
    ans *= pow(now, i, mod)
  now_sum += i
  now = i
print(ans % mod)

Measured memory_bytes: 14396
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

struct Point {
	int x, y, id;
	bool inline operator<(const Point &p) const {
		return x < p.x;
	}
};

int n;
Point p[1 << 18];
int res[1 << 18];

int main() {
	scanf("%d", &n);
	cont(i, n) scanf("%d%d", &p[i].x, &p[i].y), p[i].id = i;
	sort(p + 1, p + n + 1);
	int mn = n + 1, lst = 0;
	cont(i, n) {
		mn = min(mn, p[i].y);
		if(mn == n - i + 1) {
			res[p[i].id] = i - lst;
			lst = i;
		}
	}
	range(i, n, 1, -1) if(!res[p[i].id]) {
		res[p[i].id] = res[p[i + 1].id];
	}
	cont(i, n) printf("%d\n", res[i]);
	return 0;
}


Measured memory_bytes: 6892
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
    char buf[30];
    int X,A,B;

    scanf("%d %d %d",&X,&A,&B);
    //fgets(buf,sizeof(buf)+1,stdin);
    //X = atoi(strtok(buf ," "));
    //A = atoi(strtok(NULL," "));
    //B = atoi(strtok(NULL," "));

    if(B-A<=0) printf("delicious\n");
    else if(B-A >= X+1) printf("dangerous\n");
    else printf("safe\n");

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define maxn 500005
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fu(i,l,r) for(int i=(l);i<=(r);i++)
#define fd(i,l,r) for(int i=(l);i>=(r);i--)
#define Set set<int>
using namespace std;
#define Inf 2e8
//#define int long long
#define P pair<int,int>
int n,m,a[maxn],b[maxn];
int z[maxn],y[maxn];

int32_t main()
{
    IOS;
    cin>>n;
    cin>>a[1];
    int gg=a[1];
    z[1]=a[1];
    fu(i,2,n)
    {
        cin>>a[i];
        gg=__gcd(gg,a[i]);
        z[i]=gg;//1-i
    }
    int ff=a[n];
    y[n]=ff;
    fd(i,n-1,1)
    {
        ff=__gcd(ff,a[i]);
        y[i]=ff;//n-i
    }
    int ans=-Inf;
    y[n+1]=z[n-1];
    z[0]=y[2];
    fu(i,1,n)
    {
        ans=max(ans,__gcd(y[i+1],z[i-1]));
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
	
	while(1){
		int a,b;
		char op;
		cin >> a >> op >> b ;
		if(op=='+'){cout << a+b << endl;}
		else if(op=='-'){cout << a-b << endl;}
		else if(op=='/'){cout << a/b << endl;}
		else if(op=='*'){cout << a*b << endl;}
		else if(op=='?'){break;}
	}
	return 0;
}

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

int main() {
    int h, w; cin >> h >> w;
    char a[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h + 2; i++) {
        for (int j = 0; j < w + 2; j++) {
            if (1 <= i && i <= h && 1 <= j && j <= w) cout << a[i-1][j-1];
            else cout << '#';
        }
        puts("");
    }
}

Measured memory_bytes: 256
def main():
    import sys
    from collections import deque
    from operator import itemgetter
    b=sys.stdin.buffer
    n,d,a=map(int,b.readline().split())
    m=map(int,b.read().split())
    p,q=deque(),deque()
    f,g=p.popleft,q.popleft
    s=b=0
    for x,h in sorted(zip(m,m),key=itemgetter(0)):
        while p and p[0]<x:
            f()
            b-=g()
        h-=b
        t=0--h//a
        if t>0:
            s+=t
            b+=t*a
            p+=x+d+d,
            q+=t*a,
    print(s)
main()

Measured memory_bytes: 55768
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#define INF 1000000000000
using namespace std;
using ll = long long;
int main(){
    ll s;
    cin >> s;
    map<ll,ll> m;
    ll i=1;
    m.insert(make_pair(s,i));
    i++;
    while(true){
        if(s%2==0){
            s = s/2;
        }else{
            s = 3*s+1;
        }
        if(m.count(s)!=0){
            cout << i << endl;
            return 0;
        }
        m.insert(make_pair(s,i));
        i++;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    // ll t;
    // cin>>t;
    // while(t--)
    // {
        
    // }
    ll n;
    cin>>n;
    ll amt=100,years=0;
    double interest=0.01;
    while(amt<n)
    {
         years++;
         ll x=(amt*interest);
         amt+=x;
        //cout<<amt<<endl;
    }
    cout<<years;
    return 0;
}


Measured memory_bytes: 3632
from collections import deque

N = int(input())
ab = [list(map(int, input().split())) for i in range(N-1)]
tree = [list() for _ in range(N+1)]
color = [0] * (N-1)

for i, (a, b) in enumerate(ab):
    tree[a].append((b, i))

q = deque([(1, 0)]) # パス先, パスの色でキューに追加
while q:
    v, pc = q.popleft()
    nc = 1 # 使用する色
    for nv, edge in tree[v]: # nv=パス先 edge=abでの順番
        if nc == pc: # 渡ってきたパスの色と同じなら+1した色にする
            nc += 1
        color[edge] = nc # 使用する色を答えのリストに格納
        q.append((nv, nc))
        nc += 1

print(max(color))
print(*color, sep="\n")

Measured memory_bytes: 82392
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
const int maxn=2e5;
int n,tot,cnt;
int pre[maxn+8],now[maxn+8],son[maxn+8];
bool vis[maxn+8],cir[maxn+8],inq[maxn+8];
int v[maxn+8],fa[maxn+8];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

void add(int u,int v)
{
    pre[++tot]=now[u];
    now[u]=tot;
    son[tot]=v;
}

void get(int x)
{
    for (int p=now[x];p;p=pre[p])
	{
	    int child=son[p];
	    if (cir[child]) continue;
	    get(child);
	}
    for (int p=now[x];p;p=pre[p])
	{
	    int child=son[p];
	    if (cir[child]) continue;
	    inq[v[child]]=1;
	}
    while(inq[v[x]]) v[x]++;
    for (int p=now[x];p;p=pre[p])
	{
	    int child=son[p];
	    if (cir[child]) continue;
	    inq[v[child]]=0;
	}
}	    

int main()
{
    n=read();
    for (int i=1;i<=n;i++)
	{
	    fa[i]=read();
	    add(fa[i],i);
	}
    int x=1,mx=-inf,mn=inf;
    while(!vis[x]) vis[x]=1,x=fa[x];
    while(!cir[x]) cir[x]=1,x=fa[x];
    for (int i=1;i<=n;i++)
	if (cir[i])
	    {
		get(i),cnt++;
		mx=max(mx,v[i]);
		mn=min(mn,v[i]);
	    }
    mx==mn&&(cnt&1)?puts("IMPOSSIBLE"):puts("POSSIBLE");
    return 0;
}


Measured memory_bytes: 4480
N = input()
L = len(N)
if L == 1:
    print(int(N))
    exit()

def count(c,d):
    if c == int(N[0]):
        if L == 2:
            if d > int(N[-1]):
                n = 0
            else:
                n = 1
        else:
            n = int(N[1:-1]) + 1
            n += sum(10**i for i in range(L-2))
            if d > int(N[-1]):
                n -= 1
    elif c < int(N[0]):
        n = sum(10**i for i in range(L-1))
    else: # c > N[0]
        if L == 2:
            n = 0
        else:
            n = sum(10**i for i in range(L-2))
    if c == d:
        n += 1
    return n

ans = 0
for c in range(1,10):
    for d in range(1,10):
        nA = count(c,d)
        nB = count(d,c)
        # if nA * nB > 0:
        #     print(c,d,nA,nB)
        ans += nA * nB
print(ans)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
vector<int> to[100010];
int main(){
    cout << fixed << setprecision(10);
    int n,m;
    cin >> n >> m;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        to[a].push_back(b);
    }
    int ans = 0;
    priority_queue<int> que;
    rep(i,m){
        for(auto u : to[i+1]){
            que.push(u);
        }
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8900
#include <iostream>
#include <queue>
#define INF (1e9)
#define N 8
using namespace std;
void bfs();
int w,h,d[N][N],data[N][N],sy,sx,gy,gx,ans;
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
struct dat{
  int y,x,life,dis;
};

int main(){
  while(1){
    cin>>w>>h;
    if(!w&&!h) break;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++) d[i][j]=0;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin>>data[i][j];
	if(data[i][j]==2) sy=i,sx=j,data[i][j]=1;
	if(data[i][j]==3) gy=i,gx=j,data[i][j]=1;
      }
    ans=INF;
    bfs();
    if(ans!=INF) cout<<ans<<endl;
    else cout<<-1<<endl;
  }
  return 0;
}

void bfs(){
  queue<dat> q;
  q.push((dat){sy,sx,6,0});
  d[sy][sx]=6;
  while(!q.empty()){
    dat t=q.front(); q.pop();
    int uy=t.y,ux=t.x,life=t.life,dis=t.dis;
    for(int i=0;i<4;i++){
      int ny=uy+dy[i],nx=ux+dx[i];
      if(ny<0||nx<0||h<=ny||w<=nx) continue;
      if(life==1||!data[ny][nx]||(d[ny][nx]>=life-1)) continue;
      if(ny==gy&&nx==gx) ans=min(ans,dis+1);
      if(data[ny][nx]==4) d[ny][nx]=6,q.push((dat){ny,nx,6,dis+1});
      if(data[ny][nx]==1){
	d[ny][nx]=life-1;
	q.push((dat){ny,nx,life-1,dis+1});
      }
    }
  }
}

Measured memory_bytes: 1200
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int x= sc.nextInt();
        int y = sc.nextInt();

        for(int i = 0;i<=x;i++){
            int tmp = 2*i + 4*(x-i);
            if(tmp == y){
                System.out.println("Yes");
                System.exit(0);
            }
        }
        System.out.println("No");

    }

}

Measured memory_bytes: 35948
function Main(input) {
   var tmp = input.split("\n");
   var origin = tmp[0].split("");
   var next = tmp[1].split("");
   var result = 0;
   
   if(tmp[0]==tmp[1]){
       console.log(result);
   }else{
       for(var i=0; i<tmp[0].length; i++){
           if(origin[i]!==next[i]){
               result+=1;
           }
       }
       console.log(result);
   }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 36420
A = int(raw_input()) # 500
B = int(raw_input()) # 100
C = int(raw_input()) #  50
X = int(raw_input()) # object

# 500*s + 100*t + 50*u = X
# 0<=s<=A, 0<=t<=B, 0<=u<=C

count = 0

for s in range(A+1):
    for t in range(B+1):
        for u in range(C+1):
            if (500*s + 100*t + 50*u == X):
#                print s, t, u
                count += 1
            else:
                pass

print count


Measured memory_bytes: 2568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int N=Integer.parseInt(br.readLine());
		String result=(N>999)?"ABD":"ABC";
		System.out.println(result);
	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vs s(n);
	cin>>s;
	ll ans=0;
	ll a=0,b=0,ba=0;
	rep(i,n){
		rep(j,s[i].size()-1)if(s[i][j]=='A' and s[i][j+1]=='B')ans++;
		if(s[i].front()=='B' and s[i].back()=='A')ba++;
		else if(s[i].front()=='B')b++;
		else if(s[i].back()=='A')a++;
	}
	if(ba>0){
		ans+=ba-1;
		if(a>0){a--;ans++;}
		if(b>0){b--;ans++;}
	}
	ans+=min(a,b);
	puta(ans);

	return 0;
}

Measured memory_bytes: 768
// inputに入力データ全体が入る
function Main(input) {
	ans = 0
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n");
	s = input[0].split(' ').map((n) => (parseInt(n)))[0]

	ans = s + (s * s) + (s * s * s)



	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

Measured memory_bytes: 29440
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = [list(map(int, input().split())) for _ in range(n)]
    flg = [[True] * n for _ in range(n)]

    for k in range(n):
        for i in range(n):
            if i == k:
                continue
            for j in range(n):
                if i == j or j == k:
                    continue
                if A[i][j] > A[i][k] + A[k][j]:
                    print(-1)
                    exit()
                elif A[i][j] == A[i][k] + A[k][j]:
                    flg[i][j] = False

    res = 0
    for i in range(n):
        for j in range(n):
            if flg[i][j]:
                res += A[i][j]

    print(res // 2)


if __name__ == '__main__':
    resolve()


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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

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

    #ifdef FILIP_KADAK
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int n;
    cin >> n;
    vi a(n);
    int suma=0;

    for(int i=0; i<n; i++){
        cin >> a[i];
        suma+=a[i];
    }

    double ars = (double)suma/n;
    ars = round(ars);

    int sol=0;
    for(int x: a)
        if(x != ars)
            sol+=(ars-x)*(ars-x);
    cout << sol;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
 
using ll=long long;
 
 
ll cmp(ll ten,string s,string t){
	ll a=0LL,b=0LL;
	for(auto &i:s) a=10LL*a+i-'0';
	for(auto &i:t) b=10LL*b+i-'0';
	return min(abs(a-b),ten-abs(a-b));
}
 
int main(void){
	string s,t;
	cin >> s;
	int n=s.size();
	ll ten=1LL;
	rep(i,n) ten*=10LL;
 
	rep(i,10) t+=(i+'0');
	ll cmax=0;
	string ans="";
	do{
		string ct=t.substr(0,n);
		ll cur=cmp(ten,s,ct);
		if(cur>cmax||(cur==cmax&&ct<ans)) cmax=cur,ans=ct;
	}while(next_permutation(t.begin(),t.end()));
 
	cout << ans << endl;
	return 0;
}	

Measured memory_bytes: 3204
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)
#define MOD (1000000007LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

#define vv(t) vector< vector< T > >
#define pb push_back
#define pu push
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define EQ(a,b) (abs((a)-(b))<EPS)

int main(void){
  ios_base::sync_with_stdio(0);
  int n;
  while(cin >> n, n){
    int cnt = 0;
    for(int i = 1; i <= n; i++){
      int sum = i;
      for(int j = i + 1; j <= n; j++){
        sum += j;
        if(sum == n) cnt++;
        if(sum >= n) break;
      }
    }
    cout << cnt << endl;
  }
  return 0; 
}

Measured memory_bytes: 1192
S = list(input())
s = ["A", "T", "G", "C"]
for i in range(len(S)):
    if S[i] not in s:
        S[i] = "takayg"
S = ''.join(S)
S = S.split("takayg")
ans = []
for i in S:
    ans.append(len(i))
print(max(ans))

Measured memory_bytes: 3064
n = int(input().strip())
arr = [[0] * 2] * n

for i in range(n):
    arr[i] = list(map(int, input().split()))

s = sorted(arr, key=lambda x: x[1])

t = 0
flg = True

for e in s:
    if (e[1] < t + e[0]):
        flg = False
        break

    t += e[0]

if (flg):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 77400
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int n;
    cin>>n;
    int maxi=0;
    ll ans=0;
    rep(i,1,n){
        int a;
        cin>>a;
        maxi=max(maxi,a);
        ans+=maxi-a;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3652
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		int count = 0;
		for(int i = 0; i < N; i++){
			int x = sc.nextInt();
			if(x == (count + 1)){
				count++;
			}
		}
		System.out.println((count == 0)?"-1":N - count);
	}
}

Measured memory_bytes: 65536
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int imos[5010][5010];

void disp(int n) {
	for (int i = 0; i <= n + 1; i++) {
		for (int j = 0; j <= n + 1; j++) {
			cout << imos[i][j] << ' ';
		}
		cout << endl;
	}
}
signed main() {
	int n, m; cin >> n >> m;
	rep(i, m) {
		int a, b, x; cin >> a >> b >> x;
		imos[a][b]++;
		imos[a][b + 1]--;
		imos[a + x + 1][b]--;
		imos[a + x + 1][b + x + 2]++;
		imos[a + x + 2][b + 1]++;
		imos[a + x + 2][b + x + 2]--;
	}
	

	rep(i, n + 3)rep(j, n + 3)imos[i][j + 1] += imos[i][j];
	
	rep(i, n + 3)rep(j, n + 3)imos[i + 1][j] += imos[i][j];
	
	rep(i, n + 3)rep(j, n + 3)imos[i + 1][j + 1] += imos[i][j];

	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			if (imos[i][j]>0)cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 198956
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		sc.close();
		out.println(a+b>=c?"Yes":"No");
	}
}


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

typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#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 speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int MID = 1e5 + 3;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int main(){
    speed;
    int n;
    cin >> n;
    for(int i = 1; i < MOD; ++i){
        if(i * (i + 1) / 2 >= n){
            cout << i;
            return 0;
        }
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
#include <vector>
#include <set>
using namespace std;

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;

signed main() {
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
    return 0;
}

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

int main() {
    int testcase = 0;
    int num1, num2;
    int cnt = 0;
    bool jail = false;
    cin >> testcase;
    for (int i = 0; i < testcase; i++) {
        cin >> num1 >> num2;
        if (num1 == num2){
            cnt++;
            if (cnt >= 3){
                jail = true;
            }
        }else{
            cnt = 0;
        }
    }
    if (jail){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int n;

int a[112345];
int b[112345];
pair<LL,int> d[112345];
int sub[112345];
vector<vector<int>> g;
pair<LL,int> f(int v,int p) {
	pair<LL, int> ret = { 0ll,1 };
	for (int u : g[v]) {
		if (p == u)continue;
		auto cret=f(u, v);
		ret.first += cret.first;
		ret.second += cret.second;
	}
	ret.first += ret.second;
	return ret;
}
bool check() {
	g.resize(n);
	for (int i : range(n - 1)) {
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);

	}
	LL A = f(0, 0).first - n;
	LL B = d[0].first;
	return A == B;
}
int main() {
	cin >> n;
	
	for (int i : range(n)) {
		cin >> d[i].first;
		d[i].second = i + 1;
	}
	sort(d, d + n);
	reverse(d, d + n);
	for (int i : range(n))sub[i] = 1;
	map<LL, int> id;
	for (int i : range(n))id[d[i].first] = i;
	for (int i : range(n - 1)) {
		LL k = sub[i];
		LL rest = n - sub[i];
		LL nxt_dist = d[i].first + k - rest;
		if (id.count(nxt_dist) == 0) {
			cout << -1 << endl;
			return 0;
		}
		int j = id[nxt_dist];
		a[i] = i;
		b[i] = j;
		sub[j] += sub[i];
	}

	if (check()) {
		for (int i : range(n - 1)) {
			cout << d[a[i]].second << " " << d[b[i]].second << endl;
		}
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 22144
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();

    for i in 0..(n + 1) {
        for j in 0..(m + 1) {
            let a = i * (m - j) + j * (n - i);
            if a == k {
                return String::from("Yes");
            }
        }
    }

    return String::from("No");
}


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

int main() {
	string s;
	cin>>s;
	int a=0,b=0;char c='0',d='1';
	
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!=c)
		a++;
		if(i%2==0)
		c='1';
		else c='0';
		if(s[i]!=d)
	     b++;
	     if(i%2==0)
	     d='0';
	     else d='1';
	}
	if(a>b)
	cout<<b;
	else cout<<a;
	
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
   ll n,m;
   cin>>n>>m;
   ll a[m],b[m];

   ll i,j,k;
   vll v[m];
   for(i=0;i<m;i++)
   {
       cin>>a[i]>>b[i];
       for(j=0;j<b[i];j++)
       {
          ll x;
          cin>>x;
          v[i].pb(x);
       }
   }

   ll bitmax =(1ll<<n);
   bitset<60> bb[m];
   for(i=0;i<m;i++)
   {
       for(auto it:v[i])
       {
           bb[i][it-1]=1;
       }
   }
//    for(i=0;i<m;i++)
//    {
//        cout<<bb[i]<<"\n";
//    }
   ll res = 1e18;

   ll dp[bitmax];
   for(i=0;i<bitmax;i++)
   {
      dp[i]=1e18;
   }
   ll noo[m];
   dp[0]=0;
   for(i=0;i<m;i++)
   {
    //    cout<<bb[i]<<"\n";
       ll no =bb[i].to_ullong();
       noo[i]=no;
    //    cout<<no<<"--\n";
       dp[no]=min(dp[no],a[i]);
   }
   
   for(i=0;i<bitmax;i++)
   {
       for(j=0;j<m;j++)
       {
           if((noo[j]|i)!=i)
           {
               dp[i|noo[j]]=min(dp[noo[j]|i],dp[i]+a[j]);
           }
       }
   }

   res=dp[bitmax-1];
   if(res==1e18)
   {
       cout<<"-1\n";
       return;
   }
   cout<<res<<"\n";
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
    int n,tmp,tmp_p;
    int a[1000]={};
    
    scanf("%d",&n);
    
    for(int i=0;i<n-1;i++){
        scanf("%d",&a[i]);
        printf("%d ",a[i]);
    }
    scanf("%d",&a[n-1]);
    printf("%d\n",a[n-1]);
    
    for(int i=1;i<n;i++){
        tmp_p=-1;
        for(int j=i;j>=0;j--){
            if(a[i]<a[j]){
                tmp_p=j;
            }
            if(j==0&&tmp_p==-1){
                tmp_p=i;
            }
        }
        tmp=a[i];
        for(int j=i;j>tmp_p;j--){
            a[j]=a[j-1];
        }
        a[tmp_p]=tmp;
        for(int j=0;j<n-1;j++){
            printf("%d ",a[j]);
        }
        printf("%d\n",a[n-1]);
    }
    
    
    return 0;
    
}


Measured memory_bytes: 2084
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    vector<string> v(3);
    cin>>v[0]>>v[1]>>v[2];
    cout<<v[0][0]<<v[1][1]<<v[2][2]<<endl;

    return 0;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 
int a[60];
ll k;
ll dp[60][10];

ll dfs(int pos, int sta, bool lead, bool limit)
{
	if(pos == -1) return 1;
	if(!lead && !limit && dp[pos][sta] != -1) return dp[pos][sta];
	int up = limit ? a[pos] : 9;
	ll tmp = 0;
	for(int i = 0; i <= up; ++i) {
		if(lead) tmp += dfs(pos - 1, i, lead && i == 0, limit && i == a[pos]);
		else {
			if(abs(sta - i) <= 1) tmp += dfs(pos - 1, i, lead && i == 0, limit && i == a[pos]);
		}
	}
	if(!limit && !lead) dp[pos][sta] = tmp;
	return tmp;
}

 ll solve(ll x)
{
 	int pos = 0;
 	//ll t = x;
 	while(x){
 		a[pos++] = x % 10;
 		x /= 10;
 	}
 	ll ans = dfs(pos - 1,0,true,true) - 1;
 	//cout << t << " " << ans << endl;
 	return ans;
}

int main()
{
	fastIO;
	cin >> k;
	memset(dp,-1,sizeof dp);
	//cout << solve(1) << endl;
	ll l = 0, r = 1ll << 60;
		while(r - l > 1) {
			ll mid = (l + r) >> 1;
			//cout << mid << endl;
			if(solve(mid) < k) l = mid;
			else r = mid;
		}
		cout << l + 1 << endl;		
	return 0;
}

Measured memory_bytes: 256