akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_set>

using namespace std;

#define INF (1e18)

typedef pair<long long, long long> P;
typedef pair<long long,P> P2;
typedef pair<long long,P2> P3;

int main() {
    long long N,M,X;
    cin >> N >> M >> X;

    vector<long long> H(N);
    vector<long long> nxt_min(N,INF);
    vector<P> to[N]; // dist, tree
    for(int i=0; i<N; ++i) {
        cin >> H[i];
    }
    for(int i=0; i<M; ++i) {
        long long a,b,t;
        cin >> a >> b >> t;
        --a; --b;
        if(H[a]>=t) {
            to[a].push_back(P(b,t));
            nxt_min[a]=min(nxt_min[a],t);
        }
        if(H[b]>=t) {
            to[b].push_back(P(a,t));
            nxt_min[b]=min(nxt_min[b],t);
        }
    }

    priority_queue<P2,vector<P2>,greater<P2> > q; // dist, now_tree, rest_height
    vector<long long> dist(N,INF);
    unordered_set<long long> closed;
    long long ans=-1;

    q.push(P2(0,P(0,X)));
    while(!q.empty()) {
        P2 pp=q.top(); q.pop();
        long long now_dist=pp.first;
        long long now_tree=pp.second.first;
        long long now_rest=pp.second.second;
        if(now_tree==N-1) {
            ans=now_dist+(H[N-1]-now_rest);
            break;
        }
        if(closed.count(now_tree)!=0) continue;
        closed.insert(now_tree);

        for(int i=0; i<(int)to[now_tree].size(); ++i) {
            long long nxt_tree=to[now_tree][i].first;
            long long nxt_dist;
            long long nxt_rest=max(0LL,now_rest-to[now_tree][i].second);
            if(closed.count(nxt_tree)!=0) continue;
            if(nxt_rest>H[nxt_tree]) {
                nxt_dist=now_dist+to[now_tree][i].second+(nxt_rest-H[nxt_tree]);
                nxt_rest=H[nxt_tree];
            } else if(nxt_rest>0) {
                nxt_dist=now_dist+to[now_tree][i].second;
            } else {
                nxt_dist=now_dist+2*to[now_tree][i].second-now_rest;
            }
            dist[nxt_tree]=nxt_dist;
            q.push(P2(nxt_dist,P(nxt_tree,nxt_rest)));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 27776
#include <stdio.h>

int main(){
    int i,N,val,count=0,K;
    
    scanf("%d %d",&N,&K);
    
    for(i=0;i<N;i++){
        scanf("%d",&val);
        if(val>=K){
            count++;
        }
    }
    
    
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (20);

int64_t n;

void read()
{
	cin >> n;
}

int dp[MAXN][2];
int64_t pw10[MAXN];

int rec(int d, int is_less)
{
	if(d == -1) return 0;

	int &memo = dp[d][is_less];
	if(memo != -1) return memo;
	memo = 0;

	int high = (n / pw10[d]) % 10;
	if(is_less) high = 9;
	for(int i = 0; i <= high; i++)
		chkmax(memo, i + rec(d - 1, is_less | (i < high)));

	return memo;
}

void solve()
{
	pw10[0] = 1;
	for(int i = 1; i < MAXN; i++)
		pw10[i] = pw10[i - 1] * 10ll;

	memset(dp, -1, sizeof(dp));

	cout << rec(17, 0) << endl;
}

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

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



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

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

using namespace std;
using lint=long long;

int main(){
	string s; cin>>s;
	int n=s.length();

	lint ans=0;
	vector<int> a;
	rep(i,n+1){
		if     (i<n   && s[i]=='A') a.emplace_back(0);
		else if(i<n-1 && s[i]=='B' && s[i+1]=='C') a.emplace_back(1), i++;
		else{
			int cnt=0;
			rep(j,a.size()){
				if(a[j]==0) cnt++;
				else        ans+=cnt;
			}
			a.clear();
		}
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1532
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if(a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

int mod = 1e9+7;
struct Mint {
  int val;
  Mint inv() const {
    int tmp, a = val, b = mod, x = 1, y = 0;
    while(b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
    return Mint(x);
  }
public:
  Mint() :val(0) {}
  Mint(ll x) :val(x >= 0 ? x % mod : x % mod + mod) {}
  int mtoi() { return this->val; }
  Mint pow(ll t) { Mint res = 1,b = *this; while(t){if(t&1)res *= b;b *= b;t >>= 1;}return res; }
  Mint& operator+=(const Mint& x) { if ((val += x.val) >= mod) val -= mod; return *this; }
  Mint& operator-=(const Mint& x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; }
  Mint& operator*=(const Mint& x) { val = (ll)val * x.val % mod; return *this; }
  Mint& operator/=(const Mint& x) { return *this *= x.inv(); }
  bool operator==(const Mint& x) const { return val == x.val; }
  bool operator!=(const Mint& x) const { return val != x.val; }
  bool operator<(const Mint& x) const { return val < x.val; }
  bool operator<=(const Mint& x) const { return val <= x.val; }
  bool operator>(const Mint& x) const { return val > x.val; }
  bool operator>=(const Mint& x) const { return val >= x.val; }
  Mint operator+(const Mint& x) const { return Mint(*this) += x; }
  Mint operator-(const Mint& x) const { return Mint(*this) -= x; }
  Mint operator*(const Mint& x) const { return Mint(*this) *= x; }
  Mint operator/(const Mint& x) const { return Mint(*this) /= x; }
};
struct factorial {
  vector<Mint> Fact, Finv;
public:
  factorial(int maxx) {
    Fact.resize(maxx+1,Mint(1)),Finv.resize(maxx+1); rep(i,0,maxx)Fact[i+1]=Fact[i]*Mint(i+1);
    Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*Mint(i);
  }
  Mint fact(int n,bool inv) { if(inv) return Finv[n]; else return Fact[n]; }
  Mint nPr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[n-r]; }
  Mint nCr(int n,int r) { if(n<0||n<r||r<0) return Mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; }
};


int main(){
  int n; scanf("%d",&n);
  char c[3010]; scanf("%s",&c); string s=c;
  Mint dp[3010][3010];
  rep(i,0,n)dp[0][i]=1;
  vector<Mint> sum(n+1);
  rep(i,0,n-1){
    sum[0]=0;
    rep(j,0,n-i)sum[j+1]=sum[j]+dp[i][j];
    rep(j,0,n-i-1){
      if(s[i]=='<')dp[i+1][j]=sum[n-i]-sum[j+1];
      else dp[i+1][j]=sum[j+1];
    }
  }
  printf("%d\n",dp[n-1][0].mtoi());
  return 0;
}


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

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

signed main()
{
  int n; cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  deque<int> d;
  rep(i,n){
    int p = lower_bound(d.begin(),d.end(),a[i]) - d.begin(); // a[i]以上の最小値が登場するインデックス
    if(p==0){
      d.push_front(a[i]);
    }else d[p-1]=a[i];
  }
  int ans=d.size();
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Text;
 
class Program
{
    static void Main()
    {
    	var s = Console.ReadLine();
    	
    	StringBuilder sb = new StringBuilder();
    	
    	foreach(var c in s.ToCharArray()) {
    		if(c >= 'a' && c <= 'z')		sb.Append(char.ToUpper(c));
    		else if(c >= 'A' && c <= 'Z')	sb.Append(char.ToLower(c));
    		else sb.Append(c);
    	}
    	
    	Console.WriteLine(sb);
    }
}

Measured memory_bytes: 9072
#include <bits/stdc++.h>
    #define REP(i,n) for (int i=0;i<(n);i++)
    #define FOR(i,s,e) for (int i=s;i<(e);i++)
    #define All(v) (v).begin(),(v).end()
    #define mp(a,b) make_pair(a,b)
    #define pb(a) push_back(a)
    using namespace std;
    typedef long long llint;
    typedef pair<int, int> P;
    const int MOD = (int)1e9 + 7;
    const int INF = 999999999;
     
    int main(){
        cin.tie(0);
        ios::sync_with_stdio(false);
     
        int N;
        cin >> N;
        vector<int> a(N);
        vector<int> b(N);
        vector<int> q(N);
        REP(i, N) cin >> q[i];
        vector<int> p(N);
        REP(i, N){
            p[q[i]-1] = i+1;
        }
        a[0] = p[0];
        REP(i, N-1){
            a[i+1] = a[i] + p[i+1];
        }
        b[N-1] = p[N-1];
        for(int i=N-1; i>0; i--){
            b[i-1] = b[i] + p[i-1];
        }
        REP(i, N){
            cout << a[i] << (i==N-1 ? "\n":" ");
        }
        REP(i, N){
            cout << b[i] << (i==N-1 ? "\n":" ");
        }
     
        return 0;
    }

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



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

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

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	string s;
	cin >> s;
	rep(i,s.size()-1){
		if(s[i]==s[i+1]){
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
	}
	rep(i,s.size()-2){
		if(s[i]==s[i+2]){
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 <<" " << -1 <<  endl;

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}


int n,a[1005],ma,b[1005]={};
int c[1005];
int ans=0;
vector<P> v[1005][1005];
int main() {
	cin>>n;
	rep(i,0,n-1)cin>>a[i];
	rep(i,1,n-1){
		ans+=min(a[i-1],a[i]);
	}
	ans+=a[n-2];
	ans+=a[0];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 23936
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
    double r;

    do {
        cin >> r;
    } while (r <= 0.0 || r >= 10000.0);

    double S = M_PI * r * r;
    double l = 2.0 * M_PI * r;

    cout << fixed << setprecision(6) << S << " " << setprecision(6) << l << endl;

    return (0);
}

Measured memory_bytes: 1288
#include<iostream>

using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

//int L[MAX/2 + 1], R[MAX/2 + 1];
int cnt;

void merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[MAX/2 + 1], R[MAX/2 + 1];
  for(int i = 0; i < n1; i++) L[i] = A[left + i];
  for(int i = 0; i < n2; i++) R[i] = A[mid + i];

  L[n1] = R[n2] = SENTINEL;

  int i = 0, j = 0;
  for(int k = left; k < right; k++) {
    cnt++;
    if(L[i] <= R[j]) A[k] = L[i++];
    else A[k] = R[j++];
  }

}

void mergeSort(int A[], int left, int right) {
  if(left + 1 < right) {
    int mid = (right + left) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;
  for(i = 0; i < n; i++) cin >> A[i];

  mergeSort(A, 0, n);

  for(i = 0; i < n; i++) {
    if(i) cout<<" ";
    cout<<A[i];
  }
  cout <<endl<<cnt<<endl;

  return 0;
}



Measured memory_bytes: 6976
import java.util.*;


class Main {
	
	public static int startX = 0;
	public static int startY = 0;


	public static void main(String args[]) {
		
		Main main = new Main();

		main.mainmain();

	}

	public void mainmain() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int time = 0;
		int x = 0;
		int y = 0;

		boolean result = true;

		List<inner> inners = new ArrayList<>();

		for ( int i = 0; i < N; i++ ) {

			time = sc.nextInt();
			x = sc.nextInt();
			y = sc.nextInt();

			inners.add(new inner(time, x, y));

		}

		Collections.sort(inners, new innerComparator());

		time  = 0;
		int timePlus = 0;
		for ( inner in : inners ) {
			time = in.time - timePlus;
			x = in.x;
			y = in.y;

			if (result) {
				
				result = check(time, x, y);
				startX = x;
				startY = y;

			}
			timePlus = in.time;
		}


		System.out.println( (result) ? "Yes" : "No" );
	}

	public boolean check(int time, int x, int y) {
		int ckX = startX;
		int ckY = startY;
		for ( int i = 0; i < time; i++ ) {
			if ( ckX != x ) {
				ckX = ( ckX < x ) ? ckX + 1 : ckX - 1;
			} else {
				ckY = ( ckY < y ) ? ckY + 1 : ckY - 1;
			}
		}

		return ( ckX == x && ckY == y );
	}

	class inner {

		public int time;
		public int x;
		public int y;

		public inner(int time, int x, int y) {
			this.time = time;
			this.x = x;
			this.y = y;
		}

	}

	class innerComparator implements Comparator<inner> {
		public int compare(inner a, inner b) {
			int no1 = a.time;
			int no2 = b.time;

			if (no1 == no2) {
				return 0;
			} else if (no1 > no2) {
				return 1;
			} else {
				return -1;
			}
		}
	}

}

Measured memory_bytes: 91572
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
	int N;

	cin >> N;

	int A[3] = {0};

	for(int loop = 0; loop < N; ++loop) {
		long long int a;
		cin >> a;

		if (0 == a % 4) {
			++A[0];
		} else if (2 == a % 4) {
			++A[2];
		} else {
			++A[1];
		}
	}

	if (A[0] >= A[1]) {
		cout << "Yes";
	} else if ((A[0] == A[1] - 1) && 0 ==A[2]) {
		cout << "Yes";
	} else {
		cout << "No";
	}

	return 0;
}


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

using namespace std;

#define int long long
const int MOD = 1000000007;

signed main() {
    string n;
    cin >> n;

    for(int i = 0; i < n.size(); i++) {
        if(n[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 3628
import collections
N = int(input())
S = [input() for i in range(N)]
c = collections.Counter(S)
values, counts = zip(*c.most_common())
i = 0
lst = [values[i] for i in range(len(c)) if counts[0] == counts[i]]
lst.sort()
for i in lst:
    print(i)

Measured memory_bytes: 59628
n=int(input())
a=list(map(int,input().split()))
x=[0]*n
cnt=0
while a!=x:
    flag=True
    for i in range(n):
        if x[i]!=a[i]:
            x[i]+=1
            if i==n-1:
              cnt+=1
        else:
            continue
        for j in range(i+1,n):
            if x[j]!=a[j]:
                x[j]+=1
                if j==n-1:
                    cnt+=1
                    flag=False
                
            else:
                cnt+=1
                
                flag=False
                break
        if flag==False:
          break
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(){
  int i, n, t=0, h=0;
  string a, b;
  cin >> n;
  for (i=0; i<n; i++) {
    cin >> a >> b;
    if (a > b) t+=3;
    else if (a < b) h+=3;
    else t++, h++;
  }
  cout << t << " " << h << endl;
}


Measured memory_bytes: 3212
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    vector<vector<int>> F(N, vector<int>(10));
    vector<vector<int>> P(N, vector<int>(11));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            int f; cin >> f; F[i][j] = f;
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 11; j++) {
            int p; cin >> p; P[i][j] = p;
        }
    }


    ll ans = -1e9;
    for (int i = 1; i < pow(2,10); i++) {
        vector<int> openDate(10, 0);

        for (int j = 0; j < 10; j++) {
            openDate[j] = (i / (int)pow(2, j)) % 2;
        }

        ll temp = 0;
        for (int j = 0; j < N; j++) {
            int c = 0;
            for (int k = 0; k < 10; k++) {
                if ( openDate[k] == 1 && F[j][k] == 1 ) {
                    c++;
                }
            }
            temp += P[j][c];
        }
        ans = max(ans, temp);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1000002;
#define all(a) a.begin(),a.end()
bitset<4000000>dp;
 
void solve(int n){
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	dp[0]=true;
	for(int i=0;i<n;i++){
		dp=dp|dp<<a[i];
	
	}
	long long tot=0;
	for(int i=0;i<n;i++){
	    tot = tot + a[i];
	}
	
	if(tot%2){
		tot++;
	}
	tot/=2;
	for(int i=tot;i<=4000000;i++){
		if(dp[i]){
			cout<<i<<endl;
			return;
		}
	}
}
int main(){
int n;
cin>>n;
solve(n);
}

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

using namespace std;

int H, W;
string S;

int main(void)
{
	cin >> H >> W;
	for(int y = 1; y <= H; y++){
		for(int x = 0; x < W; x++){
			cin >> S;
			if(S == "snuke"){
				cout << (char)(x + 'A') << y << endl;
				return 0;
			}
		}
	}
}

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

Measured memory_bytes: 26444
n = int(input())

Data = [input().split() for i in range(n)]

taro = 0
hanako = 0
for a,b in Data:
    if a>b:
        taro += 3
    elif a==b:
        taro += 1
        hanako += 1
    else:
        hanako += 3
print(*[taro, hanako])


Measured memory_bytes: 5712
#include <iostream>

#define n 100

using namespace std;

int N;
int B[n-1] = {};

int ans=0;

int main(){
    cin >> N;
    for (int i = 0; i < N - 1; i++){
        cin >> B[i];
    }

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

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
program B
    implicit none
    integer :: N, L, m = 1000000, mi = 0, sum = 0, i, num
    read*,N, L
    do i = 0 , N - 1, 1
        num = L + i
        sum = sum + num
        if (abs(num) < m) then
            m = abs(num)
            mi = num
        endif
    enddo
    print*, sum - mi
end program B

Measured memory_bytes: 384
w = input()

a = [chr(ord('a') + i) for i in range(26)]
b = []

for i in w:
    b.append(i)

flag = 0

for i in a:
    if b.count(i) % 2 == 1:
        flag = 1
        break

if flag == 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
#!/usr/bin/env python3
import bisect
import collections
n, m = map(int, input().split())
a = [ [ int(s) for s in input().split() ] for _ in range(m) ]
f = collections.defaultdict(list)
for x, y in sorted(a):
    f[x] += [ y ]
for x, y in a:
    z = bisect.bisect(f[x], y)
    print("%06d%06d" % (x, z))


Measured memory_bytes: 41024
import fractions

integer = int(input())
num = list(input().split())
num_0 = list(num[0])
num_1 = list(num[1])

str = num_0[0] + num_1[0]
for i in range(1,integer):
  str = str + num_0[i] + num_1[i]

print(str)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100233;
int n, size[N], fa[N], dep[N];
pair<int, ll> p[N];
map<ll, int> q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &p[i].second);
    p[i].first = i;
    q[p[i].second] = i;
    size[i] = 1;
  }
  sort(p + 1, p + 1 + n, [&](pair<int, ll> a, pair<int, ll> b){return a.second < b.second;});
  for (int i = n; i >= 2; i--) {
    int x = p[i].first;
    ll t = p[i].second + 2 * size[x] - n;
    if (t >= p[i].second) return puts("-1"), 0;
    int y = q[t];
    if (!y) return puts("-1"), 0;
    size[y] += size[x];
    fa[x] = y;
  }
  ll t = 0;
  for (int i = 2; i <= n; i++) {
    int x = p[i].first;
    dep[x] = dep[fa[x]] + 1;
    t += dep[x];
  }
  if (t != p[1].second) return puts("-1"), 0;
  for (int i = 2; i <= n; i++) {
    int x = p[i].first;
    printf("%d %d\n", x, fa[x]);
  }
}


Measured memory_bytes: 10368
#include <iostream>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    string S;
    cin>>S;
    ll n=S.length();
    char s[n];
    for(int i=0;i<n;i++){
        s[i]=S[i];
    }
    ll ans=0;
    char before=s[0];
    for(int i=1;i<n;i++){
        if(before!=s[i]){
            before=s[i];
        }else{
            if(s[i]=='1'){
                s[i]='0';
                before=s[i];
            }else{
                s[i]='1';
                before=s[i];
            }
            ans+=1;
        }
    }
    cout<<ans<<endl;
}

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

int main() {
    int n,a = 0;
    bool f = false;
    cin >> n;
    vector<int> v(2);
    rep(i,n){
        cin >> v.at(0) >> v.at(1);
        if(v.at(0) == v.at(1)){
            a++;
        } else {
            a = 0;
        }
        if(a == 3){
            f = true;
        }
    }
    if(f){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



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

ll mod=1000000007;
ll fact[200002];
ll ncr[200003];

ll power(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res=(res*a)%mod;
        
       b>>=1;
       a=(a*a)%mod;
       
    }

return res;
}

ll solve(ll x, ll y) {
    ll res = fact[x+y];
    res=(res*ncr[x])%mod;
    res=(res*ncr[y])%mod;
return res;
}

int main() {
    fact[0]=1;
    ncr[0]= 1;
    for(int x=1; x<=2e5;x++) {fact[x] = (x*fact[x-1])%mod;
        ncr[x] = power(fact[x],mod-2);
    }

    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    ll y = h-a-1;
    ll ans = 0;
    for(int i=b;i<w;i++) {
        ll r1=solve(y,i);
        ll r2=solve(h-y-2,w-i-1);

        ans+=(r1*r2)%mod;
        ans=ans%mod;
    }

    cout<<ans<<endl;

}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N;
	cin>>N;
	vector<int> h(N);
	FDS(i,N){
		cin>>h[i];
	}
	int ans=0;
	FDS(i,N){
		FDS(j,100){
			int t=0;
			for(int k=i;k<N;k++){
				if(h[k]>0){
					t++;
				}
				else{
					break;
				}
			}
			if(t>0){
				for(int m=i;m<i+t;m++){
					h[m]--;
				}
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: isize = std::isize::MAX;
    
    input!{
        n: usize,
        xy_vec: [(isize, isize); n]
    }

    let z = xy_vec.iter().map(|x| x.0 + x.1).collect::<Vec<isize>>();
    let w = xy_vec.iter().map(|x| x.0 - x.1).collect::<Vec<isize>>();
    let z_max = z.iter().max().unwrap();
    let z_min = z.iter().min().unwrap();
    let w_max = w.iter().max().unwrap();
    let w_min = w.iter().min().unwrap();

    let ans = std::cmp::max(z_max - z_min, w_max - w_min);

    println!("{}", ans)
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 12172
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;
int main(){
    int n,x,l_i,i;
    vector<int> l;
    cin >> n >> x;
    for(i=0;i<n;i++){
        cin>>l_i;
        l.push_back(l_i);
    }
    int count=0, d=0;
    while(d<=x && count < n+1){
        d+=l[count];
        count+=1;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=998244353;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;

struct draw{
    int d,color,when;
};
int n,m,q;
vector<int> G[N];
pii p[N][12];
void bfs(){
    rep2(i,1,n){
        for(int k=10;k>=0;k--){
            rep(j,G[i].size()){
                if(p[i][k].second<p[G[i][j]][k+1].second){
                    p[i][k]=p[G[i][j]][k+1];
                }
            }
            if(p[i][k+1].second>p[i][k].second){
                p[i][k]=p[i][k+1];
            }
        }
    }
}
main(){
    cin>>n>>m;
    rep(i,m){
        int f,t;
        cin>>f>>t;
        G[f].pb(t);G[t].pb(f);
    }
    cin>>q;
    rep2(i,1,q){
        int v,d,c;cin>>v>>d>>c;
        p[v][d]={c,i};
    }
    rep(i,11)bfs();
    rep2(i,1,n){
        cout<<p[i][0].first<<endl;
    }
}

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

int main(){
    int a, b;
    char op;

    while(1){
        cin >> a >> op >> b;
        if(op == '?') break;
        else 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;
    }

    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
int N;
vector<vector<P>> A;
bool judge(int bit){
  rep(i, N){
    //i人目の証言を検証

    //i人目が不親切ならば飛ばす
    if(!(bit & (1 << i))) continue;

    for(P p : A[i]){
      int x = p.first;    //人x_ij
      int y = p.second;   //正直 or 不親切
      if(y == 0 && (bit & (1 << x))) return false; //y = 0なのに正直
      if(y == 1 && !(bit & (1 << x))) return false;//y = 1なのに不親切
    }
  }
  return true;
}


int main(){

  cin >> N;
  A.resize(N);
  rep(i, N){
    int a;
    cin >> a;
    A[i].resize(a);
    rep(j, a){
      cin >> A[i][j].first >> A[i][j].second;
      A[i][j].first--;
    }
  }
  //正直者の固定は2^N通り
  int ans = -9999;
  int cnt;
  for(int bit = 0; bit < (1 << N); bit++){
    if(judge(bit)){
      //bitに含まれる人数
      cnt = 0;
      rep(i, N){
        if(bit & (1 << i)) cnt++;
      }
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  
  vector<int> X(N), Y(N);
  for (int i = 0; i < N; i++){
    cin >> X.at(i) >> Y.at(i);
  }
  double ans = 0;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      int a, b;
      double c;
      a = (X.at(i) - X.at(j))*(X.at(i) - X.at(j));
      b = (Y.at(i) - Y.at(j))*(Y.at(i) - Y.at(j));
      c = sqrt(a+b);
      ans += c;
    }
  }
  cout << fixed << setprecision(10);  
  cout << ans*2/N << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    # N = int(input())
    A, B = [int(a) for a in input().split()]
    # B = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]
    # print(A + B)
    for k in range(1000000000):
        if 1 + (A - 1) * k >= B:
            print(k)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*bc)]

app = [0] * 100001
for num in a:
  app[num] += 1

ans = sum(a)
for i in range(q):
  dif = c[i] - b[i]
  ans += dif * app[b[i]]
  app[c[i]] += app[b[i]]
  app[b[i]] = 0
  print(ans)

Measured memory_bytes: 114364
#include <iostream>
#include <string>
#include <map>

int main(int argc, const char **argv)
{
  	int tried = 0;
  	std::cin >> tried;
  
  	std::map<std::string, long long> result;
  	for ( int loop = 0; loop < tried; loop++ )
    {
      	std::string item{0};
      	std::cin >> item;
      	result[item]++;
    }
  
  	std::cout << result.size() << std::endl;
  	return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  ll x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  int ans = 0;
  rep(i, n) {
    if(i < n-1) {
      if(x >= a[i]) {
        ++ans;
        x -= a[i];
      }
      else break;
    }
    else {
      if(x == a[i]) ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
n=int(input())
h=list(map(int,input().split()))
DP=[0,abs(h[0]-h[1])]
for i in range(n-2):
    DP+=[min(DP[-1]+abs(h[i+1]-h[i+2]),DP[-2]+abs(h[i]-h[i+2]))]
print(DP[-1])

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


int main() {
  ll N, M; cin>>N>>M;
  if(N>=2 && M>=2) cout<<(N-2)*(M-2)<<endl;
  if(N==1 && M==1) cout<<1<<endl;
  else if(N==1 || M==1) cout<<N+M-3<<endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const long long INF = 1LL<<60;
#define rev(s) (string((s).rbegin(), (s).rend())) 

int main () {

    int n;cin>>n;

    P vec[n+10];

    rep(i,n) {
        ll a,b;cin>>a>>b;
        vec[i].first = a + b;
        vec[i].second = a - b;    
    }

    
    sort(vec, vec+n);


    ll last = vec[0].first;
    int ans = 1;
    

    for (int i = 1; i<n;i++) {
        if (last <= vec[i].second) {
            last = vec[i].first;
            ans++;
        }
    }

    cout<<ans<<endl;

}

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

int main(){
    int A, B, C, N, M ,K;
    int sum = 0;
    int t = 0;
    string s, s1;
    vector<int> X;
    cin >> A >> B >> K;
    
    for(int i = 1; i <= 100; i++){
        if(A%i==0 && B%i==0){
            X.push_back(i);
            t++;
        }
        if(i>A || i>B) break;
    }

    cout << X.at(t-K) << endl;
//    vector<int> X();

//    for(int i = 0; i < ; i++){}
//    for(int j = 0; j < ; j++){}

//    cout <<  << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list()
for i in range(n):
	x, y = input().split()
	y = int(y)
	if x == "S":
		a.append(y + 0)
	if x == "H":
		a.append(y + 13)
	if x == "C":
		a.append(y + 26)
	if x == "D":
		a.append(y + 39)
for i in range(1, 53):
	if not (i in a):
		if i <= 13:
			print("S {}".format(i - 0))
		elif i <= 26:
			print("H {}".format(i - 13))
		elif i <= 39:
			print("C {}".format(i - 26))
		else:
			print("D {}".format(i - 39))


Measured memory_bytes: 5596
while 1 :
	n, m = map(int,raw_input().split(" "))
	if (n, m) == (0,0):
		break
	Lon = [0 for i in range(1000 * n + 1)]
	Lat = [0 for i in range(1000 * m + 1)]
	Lon_sum = [0]
	Lat_sum = [0]
	for i in range(0,n):
		h = int(raw_input())
		Lon_sum = [0] + [h + j for j in Lon_sum]
		for j in Lon_sum:
			Lon[j] += 1
	for i in range(0,m):
		w = int(raw_input())
		Lat_sum = [0] + [w + j for j in Lat_sum]
		for j in Lat_sum:
			Lat[j] += 1
		Lat_max = Lat_sum[-1]
	max_width = min(Lon_sum[-1],Lat_sum[-1])
	print sum([Lon[i]*Lat[i] for i in range(1,max_width+1)])

Measured memory_bytes: 98528
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int m, d;
    cin >> m >> d;
    int ans = 0;
    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= d; ++j) {
            if (j%10 < 2 || j/10 < 2) continue;
            if ((j%10) * (j/10) == i) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import random
def p(n):
    r = []
    a, b = 0, 2
    while b * b <= n:
        if n % b == 0:
            n //= b
            r += [b]
        else:
            b += 1 + a
            a = 1
    if n > 1 : r += [n]
    return r
n = int(input())
m = p(n)
ans = n-1
for i in range(2048):
    random.shuffle(m)
    a = 1
    b = n
    for i in m:
        if a >= b : break
        b //= i
        a *= i
    ans = min(ans, a+b-2)
    
print(ans)

Measured memory_bytes: 4208
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long ll;

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

    vector<int> left(n);
    vector<int> mid(n);
    vector<int> right(n);
    for (int i = 0; i < n; i++) {
        cin >> left[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> mid[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> right[i];
    }

    vector<ll> lmemo(n + 1);
    priority_queue<int, vector<int>, std::greater<int>> lq;
    ll lsum = 0;
    for (int i = 0; i < n; i++) {
        lsum += left[i];
        lq.push(left[i]);
    }

    lmemo[0] = lsum;
    for (int i = 0; i < n; i++) {
        if (mid[i] > lq.top()) {
            lsum -= lq.top();
            lq.pop();
            lsum += mid[i];
            lq.push(mid[i]);
        }
        lmemo[i + 1] = lsum;
    }

    vector<ll> rmemo(n + 1);
    priority_queue<int, vector<int>, std::less<int>> rq;
    ll rsum = 0;
    for (int i = 0; i < n; i++) {
        rsum += right[i];
        rq.push(right[i]);
    }

    rmemo[0] = rsum;
    for (int i = 0; i < n; i++) {
        if (mid[n - 1 - i] < rq.top()) {
            rsum -= rq.top();
            rq.pop();
            rsum += mid[n - 1 - i];
            rq.push(mid[n - 1 - i]);
        }
        rmemo[i + 1] = rsum;
    }

    ll ans = lmemo[0] - rmemo[n];
    for (int i = 0; i <= n; i++) {
        ans = max(ans, lmemo[i] - rmemo[n - i]);
    }
    /*

    for(int i = 0; i <= n; i++){
        cout << lmemo[i] << " ";
    }
    cout << endl;

    for(int i = 0; i <= n; i++){
        cout << rmemo[i] << " ";
    }
    cout << endl;

    */
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4216
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 20, INF = 1e9;

int n, m, x, y, c;

int G[MAXN][MAXN], sum[1 << MAXN];
int dp[1 << MAXN][MAXN];

int cost(int x, int y) {
	return sum[x | y] - (sum[x] + sum[y]);
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d%d", &x, &y, &c); x--; y--;
		G[x][y] = c;
		G[y][x] = c;
	}

	for (int i = 0; i < 1 << n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (((i >> j)&1) == 0) continue;
			for (int k = j+1; k < n; ++k) {
				if ((i >> k)&1)	sum[i] += G[j][k];
			}
		}
	}

	for (int i = 0; i < 1 << n; ++i) {
		for (int j = 0; j < n; ++j) {
			dp[i][j] = INF;
		}
	}
	dp[1][0] = 0;

	for (int i = 0; i < 1 << n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (dp[i][j] == INF) continue;
			for (int k = 0; k < n; ++k) {
				if ((i >> k) & 1) continue;
				if (G[j][k] == 0) continue;
				dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], 
						dp[i][j] + cost(i ^ (1 << j), 1 << k));
			}
			for (int k = ((1 << n)-1) & ~i; k > 0; k = (k-1)& ~i) {
				dp[i | k][j] = min(dp[i | k][j], dp[i][j] + cost(i ^ (1 << j), k));
			}
		}
	}

	printf("%d\n", dp[(1 << n)-1][n-1]);


	return 0;
}


Measured memory_bytes: 6400
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
ll countDigit(ll n){
  if(n<=9) return 1;
  else return countDigit(n/10)+1;
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=-1,tmp=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld",&n);
  for(i=1;i<=sqrtl(n);i++){
    if(n%i==0){
      tmp = max(countDigit(i),countDigit(n/i));
      //printf("%lld,%lld\n",i,tmp);
      if(result==-1) result=tmp;
      else result = min(result,tmp);
    }
  }
  printf("%lld",result);
  return 0;
}



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

using namespace std;

int main(){
    int W,H;
    int x,y,r;

    cin >> W >> H >> x >> y >> r;

    if((0 > (x - r)) || ((x + r) > W)){
        cout << "No" << endl;
    }
    if((0 <= (x - r)) && ((x + r) <= W)){
        if((0 > (y - r)) || ((y + r) > H)){
            cout << "No" << endl;
        }
        if((0 <= (y - r)) && ((y + r) <= H)){
            cout << "Yes" << endl;
        }
    }

    return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(((A == 5) && (B == 5) && (C == 7)) || ((A == 5) && (B == 7) && (C == 5))
     || ((A == 7) && (B == 5) && (C == 5))){
    cout << "YES" <<endl;
  }
  else{
    cout << "NO" <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1(x,n) for(int x = 1; x <= n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

long double dp[3001][3001];
int main(){
	IOS

	int n;
	cin>>n;
	std::vector<long double> v(n);
	cin>>v;

	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==0&&j==0)
				dp[i][j]=1;
			else if(j==0)
			{
				dp[i][j] = dp[i-1][j]*(1.0-v[i-1]);
			}
			else if(j>i)
				dp[i][j]=0;
			else
			{
				dp[i][j] = dp[i-1][j-1]*v[i-1] + dp[i-1][j]*(1.0-v[i-1]);
			}
		}
	}

	long double porb=0.0;
	for(int j=n/2+1;j<=n;j++)
	{
		porb +=dp[n][j];
	}
	cout<<setprecision(10)<<porb;
 
	return 0;
}

Measured memory_bytes: 141056
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9

using namespace std;

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int M = max(max(A, B), C);
    int sum = A + B + C;
    
    int diff = M * 3 - sum;
    if (diff % 2 == 0) {
        cout << diff / 2 << endl;
    } else {
        cout << (diff + 3) / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main{
  static int n, m;
  static int[] a, b;

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

    n = sc.nextInt();
    m = sc.nextInt();
    a = new int[m];
    b = new int[m];
    for(int i = 0; i < m; i++){
      a[i] = sc.nextInt() - 1;
      b[i] = sc.nextInt() - 1;
    }

    List< List< Integer > > graph = new ArrayList< >(n);
    for(int i = 0; i < n; i++){
      graph.add(new ArrayList< >());
    }
    for(int i = 0; i < m; i++){
      graph.get(a[i]).add(b[i]);
      graph.get(b[i]).add(a[i]);
    }

    int count = 0;
    for(int i = 0; i < m; i++){
      graph.get(a[i]).remove(new Integer(b[i]));
      graph.get(b[i]).remove(new Integer(a[i]));
      if(connected(graph) >= 2){
        ++count;
      }
      graph.get(a[i]).add(b[i]);
      graph.get(b[i]).add(a[i]);
    }

    System.out.println(count);
  }

  static int connected(List< List< Integer > > graph){
    boolean[] visited = new boolean[n];
    int count = 0;
    for(int v = 0; v < n; v++){
      if(!visited[v]){
        dfs(graph, v, visited);
        ++count;
      }
    }
    return count;
  }

  static void dfs(List< List< Integer > > graph, 
      int v, boolean[] visited){
    visited[v] = true;
    for(int w: graph.get(v)){
      if(!visited[w]){
        dfs(graph, w, visited);
      }
    }
  }
}


Measured memory_bytes: 23892
#include<cstdio>
#include<iostream>
using namespace std;
int n,a[100005],b[100005];
int main()
{
    cin>>n;
    for(int i=1;i<=n/2;i++)
    {
    	cin>>a[i]>>b[i];
    }
    if(n%2==1)
    {
    	cin>>a[n/2+1];
    	for(int i=(n+1)/2;i>0;i--)
    	{
    		cout<<a[i]<<" ";
    	}
    	for(int i=1;i<=n/2;i++)
    	{
    		cout<<b[i]<<" ";
    	}
    	cout<<endl;
    }
    else
    {
    	for(int i=n/2;i>0;i--)
    	{
    		cout<<b[i]<<" ";
    	}
    	for(int i=1;i<=n/2;i++)
    	{
    		cout<<a[i]<<" ";
    	}
    	cout<<endl;
    }
    
}

Measured memory_bytes: 2944
N = int(input())
ans=""
for i in range(1,99):
    if N <= 26**i:
        N -= 1
        for j in range(i):
            ans += chr(ord('a')+ N % 26)
            #print(N, N % 26,ans)
            N //= 26
            
        break
    else:
        N -= 26**i
    #print(N)
print(ans[::-1])

Measured memory_bytes: 9188