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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

ll pres[1000001];
ll freq[1000001];

int main()
{
    // Fast_IO();
    ll n; cin >> n;
    ll a[n]; f(i,0,n-1) cin >> a[i];
    f(i,0,1000000) pres[i] = freq[i] = 0;
    f(i,0,n-1) freq[a[i]]++;
    if(freq[1]) {
    	if(freq[1] > 1) cout << 0;
    	else cout << 1;
    	return 0;
    }
    sort(a,a+n);
    for(ll i = 2; i <= 1000000; i++) {
    	if(pres[i] == 0) {
    		for(ll j = i * i; j <= 1000000; j += i) {
    			if(freq[i] > 0 || freq[j/i] > 0) {
    				pres[j] = 1;
    			}
    		}
    	}
    }
    ll ans = 0;
    f(i,0,n-1) if(freq[a[i]] == 1 && pres[a[i]] == 0) ans++;
    cout << ans;
    return 0;
}

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

vector<string> field(11);

int main() {
    string s;
    while (cin >> s) {
        field[0] = "000" + s + "000";
        for (int i = 1; i < 8; i++) {
            cin >> s;
            field[i] = "000" + s + "000";
        }
        for (int i = 8; i < 11; i++) {
            field[i] = "00000000000000";
        }
        int x, y;
        for (int i = 0; i < 8; i++) {
            for (int j = 3; j < 11; j++) {
                if (field[i][j] == '1') {
                    y = i, x = j;
                    goto end;
                }
            }
//            cout << endl;
        } 
end:

//        for (int i = 0; i < 8; i++) {
//            for (int j = 3; j < 11; j++) {
//                cout << field[i][j] << ' ';
//            }
//            cout << endl;
//        }

        char ans;
//        cout << x << ' ' << y << endl;
        if (field[y][x+1] == '1') {
            if (field[y][x+3] == '1') ans = 'C';
            else if (field[y+1][x-1] == '1') ans = 'G';
            else if (field[y+1][x+2] == '1') ans = 'E';
            else if (field[y+1][x] == '1') ans = 'A';
        } else {
            if (field[y+3][x] == '1') ans = 'B';
            else if (field[y+1][x-1] == '1') ans = 'D';
            else ans = 'F';
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    cost = float('inf')

    for z in range(-100, 100 + 1):
        tmp_cost = sum(((x - z) ** 2 for x in a))
        cost = min(cost, tmp_cost)

    print(cost)


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m;
string s,t;
vll a;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s;
	ll l=0, r = s.length()-1;
	ll cou = 0;
	while(l<r) {
		cou+=(s[l] != s[r]);
		l++;
		r--;
	}
	cout<<cou;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

#define MOD 1000000007
#define INF 1000000000

ll N, A, B, C, D;

int main()
{
    cin >> N >> A >> B >> C >> D;

    REP(m, N) {
        ll low_case = C * (N - 1 - m) - (D * m);
        ll high_case = D * (N - 1 - m) - (C * m);
        if(abs(A-B) >= low_case && abs(A-B) <= high_case) {
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,a,ans=0;
    map<lli,lli> m;
    lli i;
    cin>>n;
    rep(i,0,n){
        cin>>a;
        m[a]++;
    }
    for(auto itr=m.begin();itr!=m.end();itr++){
        if(itr->second>=itr->first){
            ans+=itr->second-itr->first;
        }
        else{
            ans+=itr->second;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;

void solve(){
  int n, m, ans = 0; cin >> n >> m;
  vector<int> h(n), c(n, 0);
  vector<vector<int> > v(n);
  for(int i = 0; i < n; i++) cin >> h[i];
  for(int i = 0; i < m; i++){
    int a, b; cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }

  for(int i = 0; i < n; i++){
    if(c[i] == 1) continue;
    int cnt = 0;
    for(int j = 0; j < v[i].size(); j++){
      int n = v[i][j];
      if(h[i] > h[n]){
        c[n] = 1;
        cnt++;
      }
    }
    if(cnt == v[i].size()) ans++;
    c[i] = 1;
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 9000
#include <bits/stdc++.h> 
#include<cmath>
#include<string>
#define pb push_back
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern


const int mod = 1e9+7;

signed main() {    
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> v(n);
	
	int s = 0;
	vector<int> sum;
	for(int i =0 ; i < n; i++){
		cin >> v[i];
		s += v[i];
		s = s%mod;
		sum.pb(s);
	}
	
	int ans =0 ;
	for(int i =0 ; i < n-1; i++){
		ans = (ans + (((s - sum[i] + mod)%mod)*v[i])%mod)%mod;
	}
	cout<<ans;
	
	 
	return 0;
}


Measured memory_bytes: 6864
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
eat = A[0]
ans = B[eat - 1]
for i in range(1, N):
    eat = A[i]
    ans += B[eat - 1]
    if A[i - 1] == eat - 1:
        ans += C[eat - 2]
print(ans)

Measured memory_bytes: 3064
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

long long max_rectangle(const std::vector<long long>& hist){
  using ll=long long;
  using P=std::pair<ll,ll>;

  ll w=hist.size();
  ll ret=0;
  std::stack<P> sta;
  for(ll i=0;i<w;i++){
    ll left=i;
    while(!sta.empty()&&sta.top().first>=hist[i]){
      auto e=sta.top();sta.pop();
      left=e.second;
      if((i-e.second)*e.first>ret)ret=(i-e.second)*e.first;
    }
    sta.push(P(hist[i],left));
  }
  while(!sta.empty()){
    auto e=sta.top();sta.pop();
    if((w-e.second)*e.first>ret)ret=(w-e.second)*e.first;
  }
  return ret;
}

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

  ll n;
  std::cin>>n;

  std::vector<ll> hist(n);
  for(auto&& e:hist)std::cin>>e;

  std::cout<<max_rectangle(hist)<<"\n"; 

  return 0;
}


Measured memory_bytes: 5464
#include <iostream>
using namespace std;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC138();
}

void ABC138(){
    int a;
    string s;
    cin>>a>>s;
    if(a>=3200)cout<<s<<endl;
    else cout<<"red"<<endl;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int maxt = min(b, d);
	int mint = max(a, c);
	if (maxt >= mint) {
		cout << maxt - mint << endl;
	} else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
h,w = map(int,input().split())
a=[0 for i in range(h)]
for i in range(h):
    a[i]=list(input())

ans=[["0" for _ in range(w+2)] for _ in range(h+2)]
for i in range(w+2):
    ans[0][i]="#"
    ans[h+1][i]="#"
    
for i in range(w):
    for j in range(h):
        ans[j+1][i+1]=a[j][i]
        
for i in range(h):
    ans[i+1][0]="#"
    ans[i+1][w+1]="#"
for i in range(h+2):
    print(''.join(ans[i]))

Measured memory_bytes: 3188
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int b=scan.nextInt();
	int c=scan.nextInt();
	long bis=1;
	int money=0;
	for(int i=0;i!=a;i++) {
		if(i<a-money-1&&b+1<c&&bis>=b){
			money++;
			bis-=b;
		}
		else if(money>0) {
			bis+=c;
			money--;
		}
		else {
			bis++;
		}
	}
	System.out.println(bis);
}
}

Measured memory_bytes: 24020
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);


int main(){
  string S;
  bool dif = false;
  ll cnt = 1, ans0 = 0, ans1 = 0, ans2 = 0;
  cin >> S;
  ll N;
  cin >> N;
  bool NG = false;
  int difi, breaki;
  string A = S+S;
  const int K = S.size();
  if(S[0] == S[K-1])  NG = true;
  if(NG){rep(i, K-1){
     if(S[i] == S[i+1])
      cnt ++;
    if(S[i] !=S[i+1]){
      ans0 += cnt/2;
      cnt = 1;
      dif = true;
      difi = i;
      break;
    }
  }
  if(dif){
    for(int i=difi+1; i<2*K; i++){
      if(A[i] == A[i+1])
        cnt ++;
      if(A[i] != A[i+1]){
        ans1 += cnt/2;
        cnt = 1;
        if(i>=K-1){
          breaki = i;
          break;
      }
    }
  }
  }
  ans1 *= (ll)((K*N)-(difi+1))/(breaki - difi);
  for(int i=difi+1; i<K; i++){
     if(S[i] == S[i+1])
      cnt ++;
    if(S[i] !=S[i+1]){
      ans2 += cnt/2;
      cnt = 1;
    }
  }
  ll ans = ans0 + ans1 + ans2;
  if(dif) cout << ans <<  endl;
  else cout << (ll) (K*N)/2 << endl;
}
if(!(NG)){ll ans=0; rep(i, K){
  if(S[i] == S[i+1]) cnt++;
  else if(S[i] != S[i+1]) {ans += cnt/2; cnt = 1;}
}
          ans *= N;
     cout << ans << endl;
     }
}


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

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    p.push_back(x - n - 2);
    p.push_back(x + n + 2);
    sort(p.begin(), p.end());
    
    int li = -1, ri;
    for (int i = 0; i < n + 2; ++i) {
        if (p[i] == x) {
            li = i;
            ri = i;
        }
    }
    
    if (li == -1) {
        cout << x << "\n";
        return 0;
    }
    
    while (true) {
        --li;
        if (p[li] + 1 != p[li + 1]) {
            cout << p[li + 1] - 1 << "\n";
            break;
        }
        ++ri;
        if (p[ri] - 1 != p[ri - 1]) {
            cout << p[ri - 1] + 1 << "\n";
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3648
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    N, *A = map(int, read().split())
    A.sort()
    if not N % 2:
        Al = A[:N // 2]
        Ah = A[N // 2:]
        ans = 0
        ans += 2 * sum(Ah)
        ans -= Ah[0]
        ans -= 2 * sum(Al)
        ans += Al[-1]
        print(ans)

    else:
        # ans1
        Al = A[:N // 2]
        Ah = A[N // 2:]
        #print(Al, Ah)
        ans1 = 0
        ans1 += 2 * sum(Ah)
        ans1 -= sum(Ah[:2])
        ans1 -= sum(Al) * 2

        # ans2
        Al = A[:N // 2 + 1]
        Ah = A[N // 2 + 1:]
        #print(Al, Ah)
        ans2 = 0
        ans2 += 2 * sum(Ah)
        ans2 -= sum(Al) * 2
        ans2 += sum(Al[-2:])
        print(max(ans1, ans2))

if __name__ == "__main__":
    run()


Measured memory_bytes: 18424
/* D - Replacing */

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

int main(){
  int N, A, Q, B, C;
  long long S = 0;
  vector<int> num(100001);
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A;
    num.at(A)++;
    S += A;
  }
  cin >> Q;
  while(Q-- > 0){
    cin >> B >> C;
    S += (C - B) * num.at(B);
    num.at(C) += num.at(B);
    num.at(B) = 0;
    cout << S << endl;
  }
}


Measured memory_bytes: 3704
#include<stdio.h>

double t, sum;

int main()
{
	int n, k, m, num;
	scanf("%d %d", &n, &k);
	
	for(int i=1; i<=n; i++)
	{
		num=0;
		m=i;
		t=1;
		while(m<k)
		{
			m=m*2;
			num++;
		}
		for(int j=1; j<=num; j++)
			t=t/2;
		sum=sum+t;
	}
	
	printf("%.12f", (sum/n));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, ans;
  cin >> N;
  vector<ll> T(N);
  for(ll i = 0; i < N; i++) {
    cin >> T.at(i);
    if(i == 0) ans = T.at(0);
    else ans = lcm(ans, T.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.*;

class Cnt {
	public int number,
	           count = 1;
	Cnt(int a){this.number = a;}
}

public class Main {
	
	private static ArrayList<Cnt> list = new ArrayList<Cnt>();
	
	public static void main(String[] args) {

		//input
		Scanner sc = new Scanner(System.in);
		
		Cnt cnt;
		boolean find_flg;	
		while(sc.hasNext()){
			cnt = new Cnt(sc.nextInt());

			find_flg = false;
			for(Cnt c:list){
				if(c.number == cnt.number){
					c.count++;
					find_flg = true;
					break;
				}
			}
			if(!find_flg){list.add(cnt);}
		}

		//calculate frequency of appearance.
		int freq_max = 0;
		ArrayList<Integer> freq_number = new ArrayList<Integer>();
		for(Cnt c:list){
			if(c.count == freq_max){
				freq_number.add(c.number);
			}
			if(c.count > freq_max){
				freq_max = c.count;
				freq_number.clear();
				freq_number.add(c.number);
			}
		}

		//output
		for(int num:freq_number){System.out.println(num);}
	}
}

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

signed main(void)
{
	int x, n, ans, mn;
	cin >> x >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	ans = mn = 1e9;
	sort(p.begin(), p.end());
	for(int i = -1000; i <= 1000; i++)
	{
		bool ok = true;
		rep(j, n)
		{
			if (p[j] > i) 
				break;
			else if (p[j] == i)
				ok = false;
		}
		if (ok)
		{
			if (mn > abs(x - i))
			{
				mn = abs(x - i);
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char[] c = s.toCharArray();
        if (c.length < 26) {
            int[] a = new int[26];
            for (int i = 0 ; i < c.length ; i++) {
                a[c[i] - 'a']++;
            }
            for (int i = 0 ; i < 26 ; i++) {
                if (a[i] == 0) {
                    char p = (char) ('a' + i);
                    System.out.println(s + p);
                    return;
                }
            }
        } else {
            int p = 0;
            for (int i = 25; i >= 1 ; i--) {
                if (c[i] - c[i - 1] > 0) {
                    p = i;
                    break;
                }
            }
            if (p == 0) {
                System.out.println(-1);
                return;
            }
            char ch = c[p - 1];
            char t = 'a';
            for (int i = 25 ; i >= p ; i--) {
                if (c[i] > ch) {
                    t = c[i];
                    break;
                }
            }

            System.out.println(s.substring(0, p - 1) + t);
        }

    }

}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int res = 0;
  for (int i = 0; i < N - 1; i++) {
    if (A[i] == A[i + 1]) {
      A[i + 1] = -1;
      res++;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

struct Info{
	Info(int arg_node,int arg_dist){
		node = arg_node;
		dist = arg_dist;
	}
	bool operator<(const struct Info &arg) const{

		return dist > arg.dist;
	}
	int node,dist;
};

int N;
int max_dist[SIZE];
int number;
vector<int> G[SIZE];
vector<Info> children[SIZE];

void dfs(int node_id,int pre){

	int tmp_max = 0;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i];
		if(child == pre)continue;

		dfs(child,node_id);

		children[node_id].push_back(Info(child,max_dist[child]+1));
		tmp_max = max(tmp_max,max_dist[child]+1);
	}
	max_dist[node_id] = tmp_max;
}

void dfs2(int node_id,int pre){

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i];
		if(child == pre){

			if(node_id == children[pre][0].node){ //自分が親の最大方向

				if(children[pre].size() == 1){ //親の子が自分しかいない

					children[node_id].push_back(Info(pre,1));
				}else{

					children[node_id].push_back(Info(pre,children[pre][1].dist+1));
				}

			}else{

				children[node_id].push_back(Info(pre,children[pre][0].dist+1));
			}
			break;
		}
	}

	int value;

	if(children[node_id].size() > 2){

		sort(children[node_id].begin(),children[node_id].end());

		if(children[node_id][0].dist == children[node_id][2].dist){

			value = children[node_id][0].dist + children[node_id][2].dist;
		}else{

			value = children[node_id][0].dist+children[node_id][2].dist+1;
		}

		//printf("node_id:%d\n",node_id);
		/*for(int i = 0; i < 3; i++){

			printf("child[%d]:%d dist:%d\n",i,children[node_id][i].node,children[node_id][i].dist);
		}*/

		number = max(number,value);
	}

	//親を先に処理
	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i];
		if(child == pre)continue;

		dfs2(child,node_id);
	}
}

int main(){

	scanf("%d",&N);

	int from,to;
	for(int i = 0; i < N-1; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;
		G[from].push_back(to);
		G[to].push_back(from);
	}

	if(N <= 2){

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

			printf("1");
		}
		printf("\n");
		return 0;
	}

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

		max_dist[i] = 0;
	}

	dfs(0,-1);

	number = -1;
	dfs2(0,-1);

	if(number <= 2){

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

			printf("1");
		}
		printf("\n");
		return 0;
	}

	printf("11");
	for(int i = 3; i <= number-1; i++){

		printf("0");
	}
	for(int i = number; i <= N; i++){

		printf("1");
	}
	printf("\n");

	return 0;
}



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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef pair <int, int> pii;
typedef long double ld;
typedef vector <int> vi;

const int N = 2e6 + 1;
const ll INF = 1e18 + 9;
const int B = 1e9 + 7;

int n;
vi g[N];

int dfs(int x) {
    if (!g[x].size()) return 0;
    vi v;
    for (auto to : g[x])
        v.pb(dfs(to));
    sort(v.begin(), v.end(), greater <int> ());
    int ans = 0;
    forn(i, 1, v.size())
        ans = max(ans, v[i - 1] + i);
    return ans;
}

int main() {
    #ifdef black
    freopen("in", "r", stdin);
    #endif // black
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    forn(i, 2, n) {
        int p;
        cin >> p;
        g[p].pb(i);
    }
    cout << dfs(1) << "\n";

    return 0;
}


Measured memory_bytes: 58112
#include<iostream>
using namespace std;
int n;
int t[12];
int u[12];

bool check(){
  for(int i=0;i<n;i++){
    if(t[i]!=u[i])return false;
  }
  return true;
}

int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>t[i];

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

      for(int j=0;j<n;j++){u[j]=t[j];t[j]=0;}
      
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  if(u[j]==u[k])t[j]++;
	}
      }      
      if(check()){
	cout<<i<<endl;
	break;
      }
    }

    for(int i=0;i<n;i++){
      if(i)cout<<' ';
      cout<<t[i];
    }
    cout<<endl;
  }
  return 0;
}

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

int main(void)
{
    int n, l;
    cin  >> n >> l;
    vector <string> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++)
    {
        cout << a.at(i);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

vector<int> ord;
vector<int> vis;
vector<vector<int>> G;

void dfs(int s){
    if(vis[s]) return;
    vis[s] = true;
    for(int t : G[s]){
        dfs(t);
    }
    ord.push_back(s);
}

int main(){
    int N, M;
    cin >> N >> M;
    G.resize(N);
    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
    }

    vis.resize(N);
    for(int i=0; i<N; i++)
        dfs(i);

    reverse(ord.begin(), ord.end());
    vector<int> dp(N);

    for(int s : ord){
        for(int t : G[s]){
            dp[t] = max(dp[t], dp[s] + 1);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;


    return 0;
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int k;
    string s;
    cin >> k >> s;
    string ans;
    if(k >= s.size()){
        ans = s;
    }else{
        ans = s.substr(0, k) + "...";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f[200009],pas,m[200009];
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    for(b=1; b<=a; b++) cin>>f[b];
    sort(f+1,f+a+1);
    for(b=1; b<=a; b++){
        m[b]=b;
    }
    for(b=3; b<=a; b++){
        for(c=b-1; c>=2; c--){
            d=lower_bound(f+1,f+a+1,f[b]-f[c]+1)-f;
            if(d<m[c]){
                pas+=m[c]-d;
            }
        }
    }
    cout<<pas;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pi 3.14159
#include <map>
#include <iterator>
using namespace std;
int main()
 {
 	long long int n,i,j,f=0;
 	cin>>n;
 	int a[n];
 	for(i=0;i<n;i++)
 		cin>>a[i];
 	map<int,int>arr;
 	map<int, int>::iterator itr;
 	for(i=0;i<n;i++)
 	{
 		arr[a[i]]++;
	 }
	 for( itr=arr.begin();itr!=arr.end();itr++)
	 	{
	 		if(itr->second>1)
	 			{
	 				f=1;
	 				break;
				 }
		 }
		if(f==0)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
 	
 }


Measured memory_bytes: 13756
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional;

void main() {
  auto S = readln.chomp;

  auto res = true;
  foreach(i, c; S) {
    auto odd = i % 2;
    if(!odd && !c.among('R', 'U', 'D')) res = false;
    if(odd && !c.among('L', 'U', 'D')) res = false;
  }

  writeln(res ? "Yes" : "No");
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            a,b,c = l[i],l[j],l[k]
            if a != b and b != c and c != a:
                if abs(b-c) < a < (b + c):
                    count += 1
print(count)

Measured memory_bytes: 9156
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<climits>
#include<set>
#include<map>
#include<stack>
#define ll long long
using namespace std;

int main() {
	ll n;
    cin>>n;
    vector<ll>x(n),y(n);
    for(ll i=0;i<n;i++){
        cin>>x[i];
    }
    y=x;
    sort(y.begin(),y.end());
    for(ll i=0;i<n;i++){
        if(y[n/2]<=x[i]){
            cout<<y[n/2-1]<<endl;
        }
        else{
            cout<<y[n/2]<<endl;
        }
    }

    
    

}

Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int a[100005];
  int amax = -INF, amin = INF;
  a[0] = 0;
  REP(i,N){
    cin >> a[i + 1];
  }
  N += 2;
  a[N-1] = 0;
  ll def = 0;
  REP(i,N - 1){
    def += abs(a[i] - a[i + 1]);
  }
  for(int i = 0; i < N - 2; i++){
    ll ans = def;
    ans -= abs(a[i + 1] - a[i]) + abs(a[i + 2] - a[i + 1]);
    ans += abs(a[i + 2] - a[i]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2168
N = int(input())
p = list(map(int, input().split()))

nP = []
for i in range(N):
    nP.append(i+1)
nP = sorted(nP)

temp = 0

for i, j in enumerate(p):
    if nP[i] != j:
        temp += 1

if temp == 0 or temp == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 38612
using System;
using System.Linq;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            var a = s[0];
            var b = s[1];
            var c = s[2];

            if(b - a == c - b){
                Console.WriteLine("YES");
            }else{
                Console.WriteLine("NO");
            }
        }
    }
}


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


using namespace std;


template<long long M>
class modint {
    public:
        long long a;
        modint(const long long x = 0LL) : a(x % M) {}
        long long &value() { return a; }
        modint operator+(const modint rhs) const {
            return modint(*this) += rhs;
        }
        modint operator-(const modint rhs) const {
            return modint(*this) -= rhs;
        }
        modint operator*(const modint rhs) const {
            return modint(*this) *= rhs;
        }
        modint operator/(const modint rhs) const {
            return modint(*this) /= rhs;
        }
        modint &operator+=(const modint rhs) {
            a += rhs.a;
            if (a >= M) {
                a -= M;
            }
            return *this;
        }
        modint &operator-=(const modint rhs) {
            if (a < rhs.a) {
                a += M;
            }
            a -= rhs.a;
            return *this;
        }
        modint &operator*=(const modint rhs) {
            a = a * rhs.a % M;
            return *this;
        }
        modint pow(long long n) const {
            modint ret(1);
            modint x = *this;
            while (n) {
                if ((n & 1) == 1) {
                    ret *= x;
                }
                n >>= 1;
                x *= x;
            }
            return ret;
        }
        modint inv() const {
            return pow(M - 2);
        }
        modint &operator/=(const modint rhs) {
            return *this *= rhs.inv();
        }
};


using mint = modint<1000000007>;


using ll = long long;


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() {
    ll N;
    cin >> N;

    vector<ll> A(N + 1);
    ll ma = 0;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        ma = max(ma, A[i]);

    }
    vector<ll> max_primes(ma + 1, 0);

    for (auto a : A) {
        auto primes = prime_factorize(a);
        for (auto p : primes) {
            max_primes[p.first] = max(max_primes[p.first], p.second);
        }
    }

    mint L(1);
    for (int i = 1; i <= ma; i++) {
        if (max_primes[i] != 0) {
            L *= mint(i).pow(max_primes[i]);
        }
    }

    mint ans(0);
    for (int i = 0; i < N; i++) {
        ans += L / mint(A[i]);
    }
    cout << ans.a << endl;
}


Measured memory_bytes: 8192
#include <iostream>
using namespace std;
int main(){
	int x , y ;
	while ( 1 )
	{
		cin >> x >> y ;
		if ( x == 0 && y == 0 ) break ;
		if ( x > y )
			swap ( x , y ) ;
		cout << x <<" "<< y << endl;
	}
}

Measured memory_bytes: 1160
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
count = 0
for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range(j,N+1):
            if i == j == k:
                count += gcd(i,j,k)
            elif i != j != k:
                count += gcd(i,j,k)*6
            else:
                count += gcd(i,j,k)*3

print(count)

Measured memory_bytes: 9636
#include<stdio.h>
#include<string.h>
int main(){
    int i, r, n, n2, z, x;
    char moji1[201] = {}, tmp1, tmp2;

    for(;;){
        scanf("%s",moji1);
        if( moji1[0] == '-'){
            break;
        }
        scanf("%d", &n);

        for( i = 0; i < n; i++ ){
            scanf("%d", &n2);
            for( r = 0; r < n2; r++ ){
                for( z = 0; z < strlen( moji1 ); z++ ){
                   if( z == 0 ){
                    tmp1 = moji1[z];
                   }else if( z == strlen(moji1) - 1 ){
                        moji1[z - 1] = moji1[z];
                        moji1[z] = tmp1;
                    }else{
                        moji1[z - 1] = moji1[z];
                        tmp2 = moji1[z];
                   }
                }
            }
        }

        printf("%s\n", moji1);
        x = strlen( moji1 );
        memset( moji1, '\0', x );
    }
    return 0;
}

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

int main() {
int n,m;
cin>>n>>m;
string res="";
   if(n<m)
   {
       for(int i=0;i<m;i++)
       {
           res+=to_string(n);
       }
   }
   else
   {
      for(int i=0;i<n;i++)
       {
           res+=to_string(m);
       } 
   }
cout<<res;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
Max_l = 0
Min_r = float('inf')

for i in range(M):
    l,r = map(int,input().split())
    Max_l = max(Max_l,l)
    Min_r = min(Min_r,r)
ans = 0
if Max_l<=Min_r:
    ans = Min_r-Max_l+1
    

   
print(ans)


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  int exist = 0;
  rep(ly,n)rep(lx,n) {
    if (ly+m-1>=n or lx+m-1>=n) continue;

    bool match = true;
    rep(y,m) rep(x,m) {
      if (a[ly+y][lx+x] != b[y][x]) match = false;
    }
    if (match) exist = true;
  }

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

  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define N             (int)(1e6+5)
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000
 
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
 
int n,m,ans; string str;
 
int solve(){
    int m,n; cin>>m>>n;
    if(m*500>=n) cout<<"Yes";
    else cout<<"No";
    return 0;
}
 
signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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

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

int solve() {
  string s; cin >> s;
  int step = 0;
  for (; s.size() > 1; ++step) {
      int a = s[0] - '0';
      int b = s[1] - '0';
      int sum = a + b;
      if (sum >= 10) {
          s[0] = '1';
          s[1] = '0' + sum - 10;
      } else {
          s.erase(s.begin());
          s[0] = sum + '0';
      }
  }
  return step % 2;
}

int main() {
  int T; cin >> T;
  for (;T--;) {
      int res = solve();
      cout << (!res ? "Audrey wins." : "Fabre wins.") << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = j; i < n; ++i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;



int main() {
	int n, m, a, b; cin >> n >> m;
	vector<vector<int>> g(n, vector<int>());
	rep(i, 0, m) {
		cin >> a >> b;
		--a, --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	vector<i64> dist(n, INF);
	queue<int> q;
	dist[0] = 0;
	q.push(0);
	while (q.size()) {
		int v = q.front(); q.pop();
		for (int nv : g[v]) {
			if (dist[nv] == INF) {
				dist[nv] = dist[v] + 1;
				q.push(nv);
			}
		}
	}

	if (dist[n - 1] == 2) {
		cout << "POSSIBLE";
	}
	else {
		cout << "IMPOSSIBLE";
	}
	return 0;
}

Measured memory_bytes: 16868
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

char alpha[38][3];
char in[99];
int n,d[38][38];

int main()
{
  char ex[][3]={"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw","ts"};
  rep(i,26)alpha[i][0]='a'+i;
  rep(i,12)strcpy(alpha[i+26],ex[i]);

  scanf("%d ",&n);
  rep(i,n){
    fgets(in,100,stdin);
    int prev=-1,cur;
    for(int j=0;in[j];j++){
      if(in[j]==' '){
	prev=-1; continue;
      }
      for(cur=37;cur>=26;cur--){
	if(alpha[cur][0]==in[j]&&alpha[cur][1]==in[j+1])break;
      }
      if(cur==25)cur=in[j]-'a';
      if(prev>=0&&cur>=0)d[prev][cur]++;
      prev=cur; if(26<=cur&&cur<38)j++;
    }
  }
  rep(i,38){
    int mx=max_element(d[i],d[i]+38)-d[i];
    printf("%s %s %d\n",alpha[i],alpha[mx],d[i][mx]);
  }
  return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
const ll inf = pow(2, 31) - 1;
int main()
{
	double n, m, s = 0;
	int cnt = 0;
	cin >> n >> m;
	vector<double> a(n);
	rep(i,n){
		cin >> a[i];
		s += a[i];
	}
	rep(i,n)if(a[i] >= s/(4*m))cnt++;
	cout << ((cnt >= m)?"Yes":"No") << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000003;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n;
ll h[e3],p[e3];
ll idx[e3];
ll dp[5002][5002];

int main(){
  cin >> n;
  for(ll i = 0;i < n;i++) cin >> h[i]  >> p[i];
  iota(idx,idx+n,0ll);
  sort(idx,idx+n,[](ll a,ll b){
    return h[a]+p[a] < h[b]+p[b];
  });
  for(ll i = 0;i <= n;i++){
    for(ll j = 0;j <= n;j++){
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  for(ll i = 0;i < n;i++){
    for(ll j = 0;j < n;j++){
      if(dp[i][j] <= h[idx[i]]){
        dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+p[idx[i]]);
      }
      dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
    }
  }
  for(ll j = n;j >= 0;j--){
    if(dp[n][j] < INF){
      cout << j << endl;
      return 0;
    }
  }


}


Measured memory_bytes: 195840
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define N 100005
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
const int mod = 1e9 + 7;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
LL read(){
	LL x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
int a[N], s[N], v[N * 2], n;
void add(int i){
	for(; i < 200009; i += i&-i) v[i]++;
}
LL sum(int i){
	LL s = 0;
	for(; i > 0; i -= i&-i) s += v[i];
	return s;
}
int ok(int x){
	int i, j;
	LL ans = 0;
	memset(v, 0, sizeof(v));
	for(i = 1; i <= n; i++){
		if(a[i] < x) s[i] = s[i - 1] - 1;
		else s[i] = s[i - 1] + 1;
	}
	for(i = 0; i <= n; i++){
		ans += sum(s[i] + N);
		add(s[i] + N);
	}
	return ans >= z * n * (n + 1) / 4;
}
int main(){
	int i, j, m, l = 0, r = 0, mid;
	n = read();
	for(i = 1; i <= n; i++) a[i] = read(), r = max(r, a[i]);
	while(l < r){
		mid = l + r + 1 >> 1;
		if(ok(mid)) l = mid;
		else r = mid - 1;
	}
	printf("%d", l);
	return 0;
}


Measured memory_bytes: 1792
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

ll N;
vvi dpx;
vvi dpy;
vi ans;

void f(ll i, ll dx, ll dy)
{
    if (i == N)
    {
        ll k = 0;
        ll cost = 0;
        REP(j, N)
        {
            k += ((dx >> j) & 1) | ((dy >> j) & 1);
            cost += min(dpx[dx][j], dpy[dy][j]);
        }
        CH(min, ans[k], cost);
        return;
    }
    f(i + 1, dx, dy);
    f(i + 1, dx | (1 << i), dy);
    f(i + 1, dx, dy | (1 << i));
}

int main()
{
    cin >> N;
    vi X(N), Y(N), P(N);
    REP(i, N)
    {
        cin >> X[i] >> Y[i] >> P[i];
    }
    dpx.assign(1 << N, vi(N));
    dpy.assign(1 << N, vi(N));
    REP(p, 1 << N)
    {
        REP(i, N)
        {
            dpx[p][i] = P[i] * abs(X[i]);
            dpy[p][i] = P[i] * abs(Y[i]);
            REP(j, N)
            {
                if ((p >> j) & 1)
                {
                    CH(min, dpx[p][i], P[i] * abs(X[j] - X[i]));
                    CH(min, dpy[p][i], P[i] * abs(Y[j] - Y[i]));
                }
            }
        }
    }
    ans.assign(N + 1, INF);
    f(0, 0, 0);
    REP(i, N + 1)
    {
        OUT(ans[i]);
    }
}

Measured memory_bytes: 13024