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

int main() {
  int i1, i2, i3, i4, i5;
  cin >> i1 >> i2 >> i3 >> i4 >> i5;
  if (i1 == 0) {
    cout << 1 << endl;
  }
  else if (i2 == 0) {
    cout << 2 << endl;
  }
  else if (i3 == 0) {
    cout << 3 << endl;
  }
  else if (i4 == 0) {
    cout << 4 << endl;
  }
  else if (i5 == 0) {
    cout << 5 << endl;
  }
}


Measured memory_bytes: 3592
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, k, s; cin >> n >> k >> s;
    vector<int> ans(n, s);
    int d = s == 1e9 ? 1 : 1e9;
    fill(ans.begin()+k, ans.end(), d);
    for (int i : ans) cout << i << ' ';
    cout << endl;
}


Measured memory_bytes: 1664
n,k=map(int,input().split())

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


a.sort()
#print(a)
count=0
i=0
while count<k:
    count+=a[i][1]
    i+=1

print(a[i-1][0])

Measured memory_bytes: 27872
#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 400001
#define MAX_N 100001
using namespace std;
typedef long long ll;
typedef long double ld;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll comp(ll& a, ll& b){
    return a>b;
}

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}


int main(){





    // #ifndef ONLINE_JUDGE 

    // // For getting input from input.txt file 
    // freopen("input.txt", "r", stdin); 

    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout); 
    // #endif 

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a,b,c;
    cin>>a>>b>>c;
    ll t=a+b;
    ll d=c-a-b;
    if( d>0 && 4*a*b < d*d ){   
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define M 1000
using namespace std;

int n,q;
int c[300100],x;

int main(){
  scanf("%d%d",&n,&q);
  int lim = 0;
  for(int i=0;i<n;i++){ scanf("%d",&c[i]); lim = max(lim,c[i]); }
  sort(c,c+n);
  int m[M] = {0};
  for(int i=1;i<=M;i++){
    for(int j=0;j<n;j++)m[i] = max(m[i],c[j]%i);
  }

  for(int i=0;i<q;i++){
    scanf("%d",&x);
    if(x<=M)printf("%d\n",m[x]);
    else{
      int res = 0;
      for(int j=1;j*x<=lim;j++){
	int tmp = lower_bound(c,c+n,j*x) - c;
	if(tmp)res = max(res,c[tmp-1]%x);
      }
      printf("%d\n",res);
    }
  }
}

Measured memory_bytes: 2216
#include<iostream>
using namespace std;
const int INF=1e9;

main(){
  int N;
  cin >> N;
  int h[N];
  for(int ii=0;ii<N;ii++){
    cin >> h[ii];
  }
  int ans=0;
  int now;
  int t=0;
  for(int ii=0;ii<N;ii++){
    if(h[ii]!=0)t=1;
  }
  if(t==0)cout << 0 << endl;
  else{
    for(int jj=0;jj<N;jj++){
      int min=INF;
      for(int ii=0;ii<N;ii++){
	if(min>h[ii] && 0<h[ii]){
	  min=h[ii];
	  now=ii;
	}
      }//最小値を探す。
      //    cout << now << endl;
      ans+=h[now];//最小値を足す。
      int tmp=h[now];
      for(int ii=now;ii<N;ii++){
	if(h[ii]>=tmp)h[ii]-=tmp;// cout << ii;}
	else break;
      }//最小値の後ろの島を低くする。
      for(int ii=now-1;ii>=0;ii--){
	//      cout << ii << endl;
	if(h[ii]>=tmp)h[ii]-=tmp;
	else break;
      }//最小値の前の島を低くする。
      /*    for(int ii=0;ii<N;ii++){
	    cout << h[ii] << " ";
	    }cout << endl;*/
      int cnt=0;
      for(int ii=0;ii<N;ii++){
	if(h[ii]>0)cnt=1;
      }
      if(cnt==0)break;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int r = sc.nextInt();
        int D = sc.nextInt();
        int x2000 = sc.nextInt();
        int pre = x2000;
        for (int i = 0; i < 10; i++) {
            int ans = r * pre - D;
            System.out.println(ans);
            pre = ans;
        }
    }
}


Measured memory_bytes: 24020
import sys
input = sys.stdin.readline
N=int(input())
xs = [None]
for _ in range(N):
    xs.append(list(map(int, input().split()))[::-1])
tops = [None] * (N+1)
for i in range(N):
    i += 1
    tops[i] = xs[i].pop()

cc = 0
rr = 0
ns = [i+1 for i in range(N)]
while True:
    vs = set()
    nn = False
    nns = []
    for i in ns:
        j = tops[i]
        if j == None:
            continue
        if i in vs or j in vs:
            continue
        if tops[j] == i:
            nn = True
            if len(xs[i]):
                tops[i] = xs[i].pop()
            else:
                tops[i] = None
                cc += 1
            if len(xs[j]):
                tops[j] = xs[j].pop()
            else:
                tops[j] = None
                cc += 1
            vs.add(i)
            vs.add(j)
            nns.append(i)
            nns.append(j)
    ns = nns
    rr += 1
    if cc == N:
        break
    if not nn:
        rr = -1
        break

print(rr)


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

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

    int buildings[4][3][10] = {};

    for (int i = 0; i < n; i++) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        buildings[b-1][f-1][r-1] += v;
    }
    
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                cout << " ";
                cout << buildings[i][j][k];
            }
            cout << endl;
        }
        if (i != 3) {
            cout << "####################" << endl;
        }
    }
    // cout << endl;
}


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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-6;


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

    int n; cin >> n;
    map<string, bool> mp;
    REP(i, n) {
        string s; cin >> s;
        mp[s] = 1;
    }

    cout << mp.size() << endl;

    return 0;
}


Measured memory_bytes: 19284
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A & a, const B & b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A & a, const B & b) { a = max(a, (A)b); };

ll modpow(ll r, ll n, ll mod) {
	ll ans = 1;
	ll tmp = r;
	while (n > 0) {
		if ((n & 1) > 0) ans = ans * tmp % mod;
		tmp = tmp * tmp % mod;
		n >>= 1;
	}
	return ans;
}


int main() {
	ll N, X, M; cin >> N >> X >> M;
	vector<ll> tbl(2*M + 1);
	unordered_map<ll, ll> mp;
	ll loopstart;
	ll loopend;
	tbl[1] = X % M;
	mp[X % M] = 1;
	REP(i, 2, 2*M+1) {
		ll tmp = tbl[i-1] * tbl[i-1] % M;
		if (mp.count(tmp) > 0) {
			loopstart = mp[tmp];
			loopend = i - 1;
			break;
		}
		tbl[i] = tmp;
		mp[tmp] = i;
	}
	if (N <= loopend) {
		ll ans = 0;
		REP(i, 1, N+1) ans += tbl[i];
		PRI(ans);
		return 0;
	}
	ll looplen = loopend - loopstart + 1;
	ll loopn = (N - loopstart + 1) / looplen;
	ll amari = N - loopstart + 1 - looplen * loopn;
	ll ans = 0;
	REP(i, 1, loopstart) ans += tbl[i];
	REP(i, loopstart, loopend + 1) ans += loopn * tbl[i];
	REP(i, loopstart, loopstart + amari) ans += tbl[i];
	PRI(ans);
	return 0;
}

Measured memory_bytes: 6880
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
bool sortdes(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasc(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;} 
int gcd(int x,int y){return __gcd(x,y);}
// lld fact(lld n);
// lld nCr(lld n,lld r){return fact(n) / (fact(r) * fact(n - r));}
// lld fact(lld n){ lld res = 1; for(lld i = 2; i <= n; i++){res = res * i;}return res;} 
// const int maxi = 1e6+10;
// vector<int> v[maxi];
// long long a[maxi];
// void dfs(int x,int y){
//     a[x]+=a[y];
//     for(int i:v[x]){
//         if(i!=y){
//             dfs(i,x);
//         }
//     }
// }

void test_case(){
    int a,b;
    cin>>a>>b;
    int x=((b-a)*(b-a+1))/2;
    cout<<x-b;
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
		test_case();
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

class UnionFind
{
public:
    vector<int> parent;
    vector<int> rank;
    
    UnionFind(int n): parent(n), rank(n)
    {
        for(int i=0;i<n;i++)
            parent[i] = i,
            rank[i] = 0;
    }

    int root(int x)
    {
        return parent[x]==x ? x : parent[x] = root(parent[x]);
    }

    bool same(int x, int y)
    {
        return root(x)==root(y);
    }

    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (rank[x] < rank[y])
                parent[x] = y;
            else
                parent[y] = x;
            if (rank[x]==rank[y])
                rank[x]++;
        }
    }
};

int main()
{
    int N;
    cin>>N;
    long long D;
    cin>>D;
    vector<long long> A(N);
    for (long long &a: A)
        cin>>a;

    long long ans = 0;
    UnionFind UF(N);
    int n = 0;
    vector<int> C1(N), C2(N);

    while (n<N-1)
    {
        for (int i=0; i<N; i++)
            C1[i] = -1;

        int f1 = -1;
        int f2 = -1;
        for (int i=0; i<N; i++)
        {
            int c = f1 == -1 || UF.root(f1)!=UF.root(i) ? f1 : f2;
            if (c != -1)
            {
                int r = UF.root(i);
                if (C1[r] == -1 ||
                    (i-c)*D + A[c] + A[i] < (C2[r]-C1[r])*D + A[C1[r]] + A[C2[r]])
                {
                    C1[r] = c;
                    C2[r] = i;
                }
            }

            if (f1==-1)
                f1 = i;
            else if (A[i] <= (i-f1)*D+A[f1])
            {
                if (UF.root(i)!=UF.root(f1))
                    f2 = f1;
                f1 = i;
            }

            if (UF.root(i) != UF.root(f1) &&
                (f2==-1 || A[i]<=(i-f2)*D+A[f2]))
                f2 = i;
        }

        int b1 = -1;
        int b2 = -1;
        for (int i=N-1; i>=0; i--)
        {
            int c = b1 == -1 || UF.root(b1)!=UF.root(i) ? b1 : b2;
            if (c != -1)
            {
                int r = UF.root(i);
                if (C1[r] == -1 ||
                    (c-i)*D + A[c] + A[i] < (C2[r]-C1[r])*D + A[C1[r]] + A[C2[r]])
                {
                    C1[r] = i;
                    C2[r] = c;
                }
            }

            if (b1==-1)
                b1 = i;
            else if (A[i] <= (b1-i)*D+A[b1])
            {
                if (UF.root(i)!=UF.root(b1))
                    b2 = b1;
                b1 = i;
            }

            if (UF.root(i) != UF.root(b1) &&
                (b2==-1 || A[i]<=(b2-i)*D+A[b2]))
                b2 = i;
        }

        for (int i=0; i<N; i++)
        if (C1[i] != -1 && UF.root(C1[i])!=UF.root(C2[i]))
        {
            UF.unite(C1[i], C2[i]);
            n++;
            ans += (C2[i]-C1[i])*D + A[C1[i]] + A[C2[i]];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
long long n;
string s = "";
void solve() {
    cin >> n;
    if (n == 0) {
        cout << 0 << endl;
        return;
    }
    while(n) {
        if (n & 1) {
            s = "1" + s;
        } else {
            s = "0" + s;
        }
        if (n > 0) {
            n = -n / 2;
        }  else {
            n = -(n - 1) / 2;
        }
    }
    cout << s << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 256
// 嘘解法を手直しして正しく出力できるようにした
// S="?b??",T="ab",ans="abaa"
// C - Dubious Document 2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
string S, T;

bool match(int k){
	rp(i,0,T.size()) if(S[k+i] != '?' && S[k+i] != T[i]) return false;
	return true;
}

string create(int k){
	string s = S;
	s.replace(k, T.size(), T);
	replace(s.begin(), s.end(), '?', 'a');
	return s;
}

string solve(){
	string ans = "~";
	for(int i=S.size()-T.size(); i>=0; --i) if(match(i)) ans = min(ans, create(i));
	return ans=="~"? "UNRESTORABLE":ans;
}

int main(){
	cin>>S>>T;
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	long long k,a,b;
	cin>>k>>a>>b;
	if(a>=b-1||k<=a) cout<<k+1<<endl;
	else cout<<((k-a+1)/2)*(b-a)+a+((k-a+1)%2)<<endl; 
	return 0;
}

Measured memory_bytes: 256
import sys
n=int(input())

def bin(start):
    ok=0
    ng=n
    while abs(ng-ok)>1:
        mid=(ok+ng)//2
        print(mid)
        sys.stdout.flush()
        s=input()
        if s=='Vacant':exit()
        if mid%2==0 and start==s:
            ok=mid
        elif mid%2!=0 and start!=s:
            ok=mid
        else:
            ng=mid
print(0)
start=input()
sys.stdout.flush()
if start=='Vacant':exit()
bin(start)


Measured memory_bytes: 3660
#include <stdio.h>
#include <stdlib.h>

// 標準入力から改行かスペースまで読み取り、数字として返す
int get_num() {
    // 10文字+区切り文字までしか受け付けられない
    char s[11];
    int i, n;
    for (i = 0; i < sizeof(s); i++) {
        s[i] = getchar();
        if (s[i] == ' ' || s[i] == '\n') {
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}

int is_loop_num(int x) {
    int y0, y1;
    y0 = x;
    y1 = 0;
    
    while(x > 0) {
        y1 = y1 * 10 + x % 10;
        x /= 10;
    }

    if (y0 == y1) {
        return 1;
    } else {
        return 0;
    }
}

int main(void) {
    int A, B, i, count = 0;

    A = get_num();
    B = get_num();
    
    for (i = A; i <= B; i++) {
        count += is_loop_num(i);
    }
    
    printf("%d\n", count);
    
    return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int count = 0;
		List<Integer> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			count += a;
			list.add(a);
		}
		list.sort(Comparator.reverseOrder());
		int c = list.get(m - 1);

		int check = count / (4 * m);
		int check1 = count % (4 * m);
		if (check1 > 0) {
			check += 1;
		}

		if (c >= check) {
			System.out.println("Yes");

		} else {
			System.out.println("No");

		}

		sc.close();
	}

}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

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

    // 個数のmodを取るのであって和のmodを取るわけではない
    // 0からnまでの数の中からk個以上の数を選び和を取る
    // そのときの和の種類の個数のmodを取る

    // kからn+1を全て調べる。i, j in [k, n+1] i != j なら10^100の影響で必ず別の種類になる

    // i個取るとしたとき、最小値は小さい方からi個とった場合で最大値は大きい方からi個とった
    // 場合でその間の数値は全て作ることができる

    // 総和 後で足すたびにmodを取る
    long long ans = 0;

    // 最小値、最大値 あとで消すかも
    long long min_sum;
    long long max_sum;

    // 累積和を計算しておく
    vector<long long> cusum(n + 2, 0);
    rep(i, n + 1) {
        cusum.at(i + 1) = cusum.at(i) + i;
    }

    int right;
    int left;

    // iは選んだ数の個数 (kからn+1まで)
    for (int i = k; i < n + 2; i++) {
        right = i;
        left = 0;
        // 最小値
        min_sum = cusum.at(right) - cusum.at(left);

        right = n + 1;
        left = n - i + 1;
        // 最大値
        max_sum = cusum.at(right) - cusum.at(left);

        ans += max_sum - min_sum + 1;
        // 足すたびにMODを取る
        ans %= MOD;
    }
    cout << ans << endl;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    vector<ll> B(N - 1);
    REP(i, N - 1) cin >> B[i];

    ll ans = B[0] + B[N - 2];
    for(int i = 0; i < N - 2; i++) ans += min({B[i], B[i + 1]});

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<vector<int> > dp(h+1,vector<int>(w+1,0));
  dp[0][0]=1;

  for(int i=0;i<h;i++){
    for(int bit=0;bit<(1<<(w-1));bit++){
      bool f=true;
      for(int j=0;j<w-2;j++){
        if((bit&(1<<j))&&(bit&(1<<(j+1))))f=false;
      }
      if(!f)continue;
      for(int j=0;j<w;j++){
        if(j>0&&(bit&(1<<(j-1)))){
          (dp[i+1][j-1]+=dp[i][j])%=mod;
        }else if(bit&(1<<j)){
          (dp[i+1][j+1]+=dp[i][j])%=mod;
        }else{
          (dp[i+1][j]+=dp[i][j])%=mod;
        }
      }
    }
  }
  cout<<dp[h][k-1]<<endl;
}


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

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

using P = pair<char, int>;
int main(){
	string S, T;
	cin >> S >> T;

	int N = S.size();
	bool is_can = true;
	vector<vector<int>> s_vec(26, vector<int>());	
	for(int i=0; i<N; i++) s_vec[S[i]-'a'].push_back(i);
	for(int i=0; i<26; i++){
		for(int j=1; j<s_vec[i].size(); j++){
			int place1 = s_vec[i][j-1];
			int place2 = s_vec[i][j];
			if(T[place1] != T[place2]) is_can = false;
		}
	}

    vector<vector<int>> t_vec(26, vector<int>());
	for(int i=0; i<N; i++) t_vec[T[i]-'a'].push_back(i);
	for(int i=0; i<26; i++){
		for(int j=1; j<t_vec[i].size(); j++){
			int place1 = t_vec[i][j-1];
			int place2 = t_vec[i][j];
			if(S[place1] != S[place2]) is_can = false;
		}
	}
	// cout << " S: " << S  << "     T: " << T << endl;
	// cout << " t_vec: "; print_vec2(t_vec);

	// vector<P> vec;
	// for(int i=0; i<N; i++){
	// 	if(S[i] == T[i]){
	// 		vec.emplace_back(P(S[i], i));
	// 	}
	// }

	// bool is_can = true;
	// for(int i=0; i<(int)vec.size(); i++){
	// 	char c = vec[i].first;
	// 	int place = vec[i].second;
	// 	for(int j=0; j<N; j++){
	// 		if(j!=place && T[j] == c) is_can = false;
	// 	}
	// }

	if(is_can) cout << "Yes" << endl;
	else cout << "No" << endl; 


}



Measured memory_bytes: 6036
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

signed main() {
	string s, t;
	cin >> s >> t;
	string r = s;
	for (int i = s.size() - t.size(); i >= 0; --i) {
		bool b = true;
		rep(j, t.size()) {
			if (s[i + j] != '?' && t[j] != s[i + j])b = false;
			elif(s[i + j] == '?')s[i + j] = t[j];
		}
		if (b) {
			rep(i, s.size()) {
				if (s[i] == '?')cout << 'a';
				else cout << s[i];
			}
			ggr
		}
		s = r;
	}
	cout << "UNRESTORABLE" << endl;
	ggr

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <bitset>

const int MN = 405, MM = 100005;
const int MC = (MM * 2 + MN) * 2;

int N, M, C;
std::vector<int> V[MN], G[MC], G2[MC];
inline int Alive(int x) { return 2 * x - 1; }
inline int Dead(int x) { return 2 * x; }
inline int T(int x) { return ((x - 1) ^ 1) + 1; }
inline void Insert(int x, int y) {
	G[x].push_back(y);
	G[T(y)].push_back(T(x));
}

int dfn[MC], low[MC], dfc;
int stk[MC], tp, instk[MC];
int bel[MC], scnt;
void Tarjan(int u) {
	dfn[u] = low[u] = ++dfc;
	instk[stk[++tp] = u] = 1;
	for (int v : G[u]) if (!dfn[v]) {
		Tarjan(v);
		low[u] = std::min(low[u], low[v]);
	} else if (instk[v]) low[u] = std::min(low[u], dfn[v]);
	if (low[u] == dfn[u]) {
		++scnt;
		for (int x = 0; x != u; --tp)
			bel[x = stk[tp]] = scnt, instk[x] = 0;
	}
}

int vis[MC], key[MC];
std::bitset<MN> bit[MC];
int bdfs[MN]; // be dead for sure

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; ++i) V[i].push_back(++C);
	for (int i = 1, x, y; i <= M; ++i) {
		scanf("%d%d", &x, &y);
		int u0 = V[x].back(), v0 = V[y].back(), u1, v1;
		V[x].push_back(u1 = ++C);
		V[y].push_back(v1 = ++C);
		Insert(Alive(u1), Alive(u0));
		Insert(Alive(v1), Alive(v0));
		Insert(Alive(u1), Dead(v1));
		Insert(Dead(u0), Dead(v1));
		Insert(Dead(v0), Dead(u1));
	}
	for (int i = 1; i <= 2 * C; ++i) if (!dfn[i]) Tarjan(i);
	for (int i = 1; i <= 2 * C; ++i) {
		for (int x : G[i]) if (bel[x] != bel[i] && !vis[bel[x]])
			G2[bel[i]].push_back(bel[x]), vis[bel[x]] = 1;
		for (int x : G[i]) vis[bel[x]] = 0;
	}
	for (int i = 1; i <= N; ++i) key[bel[Dead(V[i].back())]] = i;
	for (int i = 1; i <= scnt; ++i) {
		if (key[i]) bit[i][key[i]] = 1;
		for (int x : G2[i]) bit[i] |= bit[x];
	}
	int Ans = 0;
	for (int i = 1; i <= N; ++i) bdfs[i] = bit[bel[Alive(V[i].back())]][key[bel[Dead(V[i].back())]]];
	for (int j = 2; j <= N; ++j) if (!bdfs[j])
		for (int i = 1; i < j; ++i) if (!bdfs[i])
			if (!bit[bel[Alive(V[i].back())]][key[bel[Dead(V[j].back())]]]) ++Ans;
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 77852
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,i=0;
    cin >> n;
    string s,t;
    cin >> s >> t;
    
    while(s[i]) {
    	cout << s[i] << t[i];
    	i++;
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for(int i=1; i<n; i++)
    {
        int cnt=0;
        for(char c='a'; c<='z'; c++)
        {
            bool left=false,right=false;
            for(int j=0; j<i; j++)
                if(s[j]==c)
                    left=true;
            for(int j=i; j<n; j++)
                if(s[j]==c)
                    right=true;
            if(left&&right)
                cnt++;
        }
        if(ans<cnt)
            ans=cnt;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,a[5],mi = INF;
	cin >> n;
	for(int i = 0;i < 5;i++) cin >> a[i];
	for(int i = 0;i < 5;i++) mi = min(mi,a[i]);
	cout << 5 + (n - 1) / mi << endl;
	return 0;
	
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

ll n, a, b, mn, mx, h[100000], cnt;

int main() {
	cin >> n >> a >> b;
	mx = 0;
	mn = intmax;
	lp(n) {
		cin >> h[i];
		mx = max(mx, h[i]);
		mn = min(mn, h[i]);
	}
	mn = mn / a;
	mx = mx / b + 1;
	
	while (mn + 1 != mx) {
		cnt = 0;
		lp(n) {
			if (h[i] - ((mn + mx) / 2)*b > 0) {
				cnt += (h[i] - ((mn + mx) / 2)*b - 1) / (a - b) + 1;
			}
		}
		if (cnt <= (mn + mx) / 2)
			mx = (mn + mx) / 2;
		else mn = (mn + mx) / 2;
	}
	cout << mx << endl;
	return 0;
}

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

int main() {
    long long x;
    cin >> x;
    if (x <= 6)
        puts("1");
    else {
        long long unko = x / 11 * 2;
        if (x % 11 > 6)
            unko += 2;
        else if (x % 11 > 0)
            unko += 1;
        printf("%lld\n", unko);
    }
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		long[] a = new long[n];
		for(i=0;i<n;i++) {
			a[i] = parseLong(sc.next()) - i -1;
		}
		sc.close();
		Arrays.sort(a);
		long b0 = 0;
		long b1 = 0;
		if(n%2==1) {
			b0 = a[n/2];
			b1 = a[n/2];
		} else {
			b0 = a[n/2-1];
			b1 = a[n/2];
		}
		long ans0 = 0;
		long ans1 = 0;
		for(i=0;i<n;i++) {
			ans0 += abs(a[i]-b0);
			ans1 += abs(a[i]-b1);
		}
		out.println(ans0<ans1?ans0:ans1);
	}
}


Measured memory_bytes: 59524
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    
    int n; cin >> n;
    vector<long long> v(n);
    long long sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> v[i]; 
        sum = (sum + v[i]) % 1000000007;
    }

    long long ans = 0;
    for(int i = 0; i < n; i++) {
        sum -= v[i];
        if(sum < 0) sum += 1000000007;

        ans += (v[i] * sum);
        ans %= 1000000007;
    }

    cout << ans << "\n";

    return 0;
}

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

int main() {
  int N, cnt_s = 0, cnt_t = 0;
  string S, T;
  cin >> N >> S >> T;
  for(int i = 1; i <= 2*N; i++){
  	if(i % 2 == 1){
    	cout << S[cnt_s];
      	cnt_s++;
    }else{
    	cout << T[cnt_t];
      	cnt_t++;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
 // 	freopen("input.txt","r",stdin);
 // 	freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >> n;
		fn1{
			cin >> ar[i];
		}
		dp[1]=ar[1];
		for(int i=2;i<=n;i++)dp[i] =min(dp[i-1],ar[i]);
		int ans =0;
		for(int i =1;i<=n;i++){
			if(ar[i]<=dp[i])ans++;
		}
		cout << ans << endl;
	
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    if (n % 1000 == 0) {
        cout << 0 << endl;
    } else {
        cout << 1000 - n % 1000 << endl;
    }
}


Measured memory_bytes: 3632
# utf-8:

def main():
    n = raw_input()
    l = [int(x) for x in list(str(n))]
    ct = 0
    before = l[0]
    for v in l:
        if before == v:
            ct = ct + 1
            if ct == 3 or ct == 4:
                print("Yes")
                break
        else:
            before = v
            ct = 1

    if ct != 3 and ct != 4:
        print("No")


if __name__ == '__main__':
    main()


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

const int MAXN = 1e5;
const int INF = 1e9;
vector<int> dp(MAXN+5, INF);

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i < n; i++){
		dp[i] = min( dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]) );
	}
	
	cout << dp[n-1] << endl;
	return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;
int broken[100005], mem[100005];
int n;
int solve(int ind){
    if(ind == n) return 1;
    if(ind > n) return 0;
    if(broken[ind]) return 0;
    int &ret = mem[ind];
    if(~ret) return ret;
    return ret = (solve(ind + 1) + solve(ind + 2)) % mod;
}
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif
    memset(mem, -1, sizeof(mem));
    int m;
    scanf("%d%d", &n, &m);
    for(int i=0; i<m;i++){
        int cur;
        scanf("%d", &cur);
        broken[cur] = true;
    }
    printf("%d\n", solve(0));
    return 0;
}

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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

//CF530F
//CodeChef Persistent Oak
//AOJ GRL5C
template<class E>
struct HLD{
	vvc<E> g;
	int n,rt,cnt;
	vi sub,in,out,par,head,dep;
	int dfs1(int v,int p,int d){
		par[v]=p;
		dep[v]=d;
		g[v].erase(remove(all(g[v]),p),g[v].ed);
		for(auto&e:g[v]){
			sub[v]+=dfs1(e,v,d+1);
			if(sub[g[v][0]]<sub[e])
				swap(g[v][0],e);
		}
		return sub[v];
	}
	void dfs2(int v,int h){
		in[v]=cnt++;
		head[v]=h;
		for(int to:g[v])
			dfs2(to,to==g[v][0]?h:to);
		out[v]=cnt;
	}
	HLD(const vvc<E>&gg,int rr):g(gg),n(g.size()),rt(rr),cnt(0),
		sub(n,1),in(n),out(n),par(n,-1),head(n),dep(n){
		dfs1(rt,-1,0);
		dfs2(rt,rt);
	}
	int lca(int a,int b){
		while(head[a]!=head[b]){
			if(dep[head[a]]>dep[head[b]])
				swap(a,b);
			b=par[head[b]];
		}
		if(dep[a]>dep[b])
			swap(a,b);
		return a;
	}
	int len(int a,int b){
		return dep[a]+dep[b]-dep[lca(a,b)]*2;
	}
	bool asde(int a,int b){
		return in[a]<=in[b]&&out[b]<=out[a];
	}
};

const int nmax=10010;
vi g[nmax];
vvc<int> t;
int par[nmax];

vc<pi> es;

void no(){
	cout<<"No"<<endl;
	exit(0);
}

void yes(){
	cout<<"Yes"<<endl;
	for(auto e:es){
		cout<<e.a+1<<" "<<e.b+1<<"\n";
	}
	exit(0);
}

int buf[nmax][3];
vi idx;

void dfs(int v,int p){
	assert(par[v]==-2);
	par[v]=-3;
	for(auto to:g[v]){
		if(par[to]==-2){
			dfs(to,v);
		}else if(par[to]==-3&&to!=p){
			buf[v][0]++;
			buf[to][0]--;
			es.eb(v,to);
		}
	}
	par[v]=p;
	idx.pb(v);
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n,m;cin>>n>>m;
	rep(i,m){
		int a,b;cin>>a>>b;
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	rep(i,n)par[i]=-2;
	
	dfs(0,-1);
	t.resize(n);
	rng(i,1,n)
		t[par[i]].pb(i);
	auto h=HLD<int>(t,0);
	
	int qs;cin>>qs;
	rep(_,qs){
		int a,b;cin>>a>>b;
		a--;b--;
		int c=h.lca(a,b);
		buf[a][2]++;
		buf[c][2]--;
		buf[b][1]++;
		buf[c][1]--;
	}
	
	for(auto i:idx){
		for(auto j:t[i]){
			rep(k,3)
				buf[i][k]+=buf[j][k];
		}
		if(i){
			if(buf[i][0]){
				es.eb(par[i],i);
			}else{
				if(buf[i][1]&&buf[i][2])
					no();
				if(buf[i][1])
					es.eb(par[i],i);
				else
					es.eb(i,par[i]);
			}
		}
	}
	yes();
}



Measured memory_bytes: 9328
import sys
sys.setrecursionlimit(10 ** 8)

def main():
    N = int(input())

    i = 1
    ans = 15
    while i*i <= N:
        if N%i==0:
            # bのほうが必ず大きくなる
            a = i
            b = N//i
            ans = min(ans,len(str(b)))
        i += 1

    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
struct Node
{
	long long x;
	long long num;
}nn[100005];
bool cmp(Node a,Node b)
{
	return a.x<b.x;
}
int main()
{
	long long n,k;
	scanf("%lld%lld",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%lld%lld",&nn[i].x,&nn[i].num);
	}
	sort(nn,nn+n,cmp);
	long long sum=0;
	for(long long i=0;i<n;i++)
	{
		sum+=nn[i].num;
		if(sum>=k)
		{
			printf("%lld\n",nn[i].x);
			return 0;
		} 
	}
	return 0;
}

Measured memory_bytes: 1792
n,m,z = map(int, input().split())
r = list(map(int, input().split()))
wf=[[10**10 for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c = list(map(int,input().split()))
    wf[a-1][b-1] = c
    wf[b-1][a-1] = c

for i in range(n):
    wf[i][i]=0

for k in range(n):
    for i in range(n):
        for j in range(n):
            wf[i][j] = min(wf[i][j],wf[i][k]+wf[k][j])

from itertools import *
ans=10**10
for vils in list(permutations(r)):
    cnt=0
    for i in range(z-1):
        cnt+=wf[vils[i]-1][vils[i+1]-1]
    if ans>cnt:
        ans=cnt
print(ans)

Measured memory_bytes: 52568
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);

        var list = new List<int>[N + 1];

        for (int i = 0; i < M; i++)
        {
            var AB = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var (A, B) = (AB[0], AB[1]);

            if(list[A] == null)
            {
                list[A] = new List<int>();
            }
            if(list[B] == null)
            {
                list[B] = new List<int>();
            }

            list[A].Add(B);
            list[B].Add(A);
        }

        var ans = new int[N + 1];

        var q = new Queue<int>();
        q.Enqueue(1);

        while (q.Count > 0)
        {
            var a = q.Dequeue();

            foreach (var b in list[a])
            {
                // 未訪問点だった場合
                if (ans[b] == 0)
                {
                    // 訪問
                    ans[b] = a;

                    // 移動可能点をエンキュー
                    q.Enqueue(b);
                }
            }
        }

        WriteLine("Yes");

        for (int i = 2; i <= N; i++)
        {
            WriteLine(ans[i]);
        }

    }
}

Measured memory_bytes: 56464
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    N = I()
    D = LIR(N)

    cnt = 0
    for d1, d2 in D:
        if d1 == d2:
            cnt += 1
            if cnt >= 3:
                break
        else:
            cnt = 0
    else:
        print("No")
        return
    print("Yes")

if __name__ == '__main__':
    main()

Measured memory_bytes: 77124
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

int main(){
  string S; cin>>S;
  int N=S.size();
  string rvS,a,b,rva,rvb;
  rvS=S;
  reverse(rvS.begin(),rvS.end());
  if(rvS!=S){
    cout<<"No"<<endl;
    return 0;
  }
  else{
    a=S.substr(0,(N-1)/2);
    rva=a;
    reverse(rva.begin(),rva.end());
    b=S.substr((N+3)/2-1,(N-1)/2);
    rvb=b;
    reverse(rvb.begin(),rvb.end());
    if(a==rva && b==rvb){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

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

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

//a^b % MOD
long long mod_pow(ll a,ll b){
	long long ret = 1;
	long long c = a;
	for(int i = 0;i <= 60;i++){
		if(b & (1LL << i))ret = (ret * c) % MOD;
		c = (c * c) % MOD;
	}
	return ret;
}

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 2222222
vector<long long> fact(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	if(fact[0] != 1){
		fact[0] = 1;
		for(long long i = 1;i < MAX_K;i++)fact[i] = (fact[i-1] * i) % MOD;
	}
    long long ret = fact[n];
	long long tmp = (fact[r] * fact[n-r]) % MOD;
    return mod_div(ret,tmp);
}

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

	ll n;cin >> n;
	string str;cin >> str;
	ll m = str.size();
	ll ans = 0;
	for(ll i = m;i <= n + m;i++){
		ll seica = combination(i - 1, m - 1);
		seica = seica * mod_pow(25, i - m) % MOD;
		seica = seica * mod_pow(26, n + m - i) % MOD;
		ans = (ans + seica) % MOD;
		//cout << "seica: " << seica << endl;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 21624
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
int gcd(int x, int y)
{
    if(y==0)
        return x;
    return gcd(y, x%y);
}

 long long numbers[500005];

//int a[100005];

 int main(){

  long long a,b,c;
  cin>>a>>b>>c;

  if(a== b && b == c && a%2 == 0){
    cout<<"-1"<<endl;
    return 0;
  }

  long long cnt=0;

  while(a%2 == 0 && b%2 == 0&& c%2 == 0 ){
    long long A = a/2,B=b/2,C=c/2;
    a = B+C;
    b = A+C;
    c = A+B;
   cnt++;
  }

  cout<<cnt<<endl;

 return 0;
 }


Measured memory_bytes: 3616