akhauriyash/Code-Regression huggingface dataset:
n,*l = map(int, open(0).read().split())
 
for i in range(n):
    min = 1001
    min_j = -1
    for j in range(i, n):
        if l[j] < min:
            min = l[j]
            min_j = j
    l[i], l[min_j] = l[min_j], l[i]
    
ans = 0
for i in range(n):
    for j in range(i+1, n):
        big = l[i]+l[j]
        
        if l[i] > l[j]:
            small = l[i] - l[j]
        else:
            small = l[j] - l[i]
        
        ch_max = n
        ch_min = j+1
        
        while ch_min < ch_max:
            ch_i = (ch_min + ch_max) // 2
            if l[ch_i] < big:
                ch_min = ch_i + 1
            else:
                ch_max = ch_i
                
        big_i = ch_max
        
        ch_max = n
        ch_min = j+1
        
        while ch_min < ch_max:
            ch_i = (ch_min + ch_max) // 2
            if l[ch_i] < small:
                ch_min = ch_i + 1
            else:
                ch_max = ch_i
                
        small_i = ch_min
        
        ans += big_i - small_i
 
        if i < big_i and i >= small_i:
            ans -= 1
        if j < big_i and j >= small_i:
            ans -= 1
                
print(ans)

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M,R;
const int MAX_N = 200;
int A [MAX_N];
int minDist [MAX_N] [MAX_N];
const int INF = 1e9;

int main()
{
	scanf("%d%d%d",&N,&M,&R);
	FOR(i,0,R){
		scanf("%d",&A [i]);
		A [i]--;
	}
	fill(minDist [0],minDist [MAX_N],INF);
	FOR(i,0,N) chmin(minDist [i] [i],0);
	FOR(i,0,M){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a--;
		b--;
		chmin(minDist [a] [b],c);
		chmin(minDist [b] [a],c);
	}
	FOR(k,0,N) FOR(i,0,N) FOR(j,0,N) chmin(minDist [i] [j],minDist [i] [k] + minDist [k] [j]);

	sort(A,A + R);
	int ans = INF;
	do{
		int sum = 0;
		FOR(i,0,R - 1){
			sum += minDist [A [i]] [A [i + 1]];
		}
		chmin(ans,sum);
	}while(next_permutation(A,A + R));
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 384
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

int main() {
    int n = nxt();
    // IF i tosses, tails = i - heads
    vector<double> dp(n + 1);
    // dp[i] - p-bility that there are i heads so far
    dp[0] = 1;
    for (int coin = 0; coin < n; coin++) {
        double p_heads;
        cin >> p_heads;
        for (int i = coin + 1; i >= 0; --i) {
            dp[i] = (i == 0 ? 0 : dp[i - 1]) * p_heads + dp[i] * (1 - p_heads);
        }
    }
    double answer = 0;
    for (int heads = 0; heads <= n; ++heads) {
        int tails = n - heads;
        if (heads > tails) answer += dp[heads];
    }
    printf("%.10lf\n", answer);
    return 0;
}


Measured memory_bytes: 256
# frozen_string_literal: true

def z_algorithm(s)
  n = s.size
  return [] if n == 0
 
  z = [0]*n
  j = 0
  1.upto(n-1){ |i|
    k = j+z[j] <= i ? 0 : j+z[j]-i < z[i-j] ? j+z[j]-i : z[i-j]
    k += 1 while i+k<n && s[k]==s[i+k]
    j = i if j+z[j] < i+k
    z[i] = k
  }
  z[0] = n
  return z
end

s, t = $<.map &:chomp

ss = s+s
ss << s while ss.size < t.size*2
z = z_algorithm(t+ss)[t.size,s.size].map{ |z| z >= t.size }

vis = [false]*s.size

ans = (0 ... s.size).map{ |u|
  next if vis[u]
  vis[u] = true
  now = u
  cnt = 0
  while z[now]
    now = (now+t.size) % s.size
    vis[now] = true
    cnt += 1
    break if now == u
  end
  now==u && cnt.nonzero? ? 10**9 : cnt
}.compact.max

ans = -1 if ans >= 10**9
puts ans


Measured memory_bytes: 50696
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans;
    if(b<=c || d <= a) {
        ans = 0;
    } else {
        if(a<=c && d <=b) {
            ans = d- c;
        } else if(c<=a && b<=d) {
            ans = b-a;
        } else {
            if(a < c) {
                ans = abs(b-c);
            } else {
                ans = abs(d-a);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/*                  ___
               :                
               ;                
              :                 
              ;                 
             /                  
           o/                   
         ._/\___,                
             \                  
             /                   
             `      
	bug
*/
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

using namespace std;
#define PI 3.14159265359
#define eps 1e-8
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
const int INF = 1<<29;
typedef long long ll;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double tick() { 
	static clock_t oldticks;
	clock_t newticks = clock();
	double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; 
	oldticks = newticks;
	return diff;
}

int P[11],C[11];
int d,g;

int main(){
	ios_base::sync_with_stdio(false); //Fast I/O
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("output.txt","w",stdout);	

	cin >>d >> g;
	g/=100;

	for(int i=0;i<d;i++){
		cin >> P[i] >> C[i];
		C[i]/=100;
	}

	int ans=100*d;

	for(int i=0;i<(1<<d);i++){
		int cc=0,val=0;
		for(int j=0;j<d;j++){
			if((i>>j)&1){
				cc+=P[j];
				val+=(j+1)*P[j]+C[j];
			}
		}
		int rem=g-val,mn=100000;
		if(rem<0){
			mn=0;
		}else{
			for(int j=0;j<d;j++){
				if(!((i>>j)&1)){
					int tmp=(rem+j)/(j+1);
					if(tmp<=P[j])
						mn=min(mn,tmp);
				}
			}
		}
		ans=min(ans,cc+mn);
	}

	cout << ans << endl;

    //cerr << tick();

	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
int main()
{
    std::string S,T;
    std::cin>>S>>T;
    for(int i=0;i<S.size();i++)
    {
        if(S[i]!=T[i]){
        std::cout<<"No"<<std::endl;
        return 0;
        }
    }
    
     if(S.size()+1==T.size())
    {
    std::cout<<"Yes"<<std::endl;
    }
    else 
    std::cout<<"No"<<std::endl;
    
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
    using namespace std;
    const int N = 200005;
    const int MX = 1000005;
    typedef long long ll;
    ll freq[MX];
    ll dp[MX];
    int a[N];
    int n;
    ll mod = 998244353;
    vector<int> divs[MX];
    ll get_p(){
    	char c;
    	ll a = 0;
    	while(!(c >= '0' && c <= '9')) c = getchar();
    	while(c >= '0' && c <= '9') a = 10*a + (c-'0') , c = getchar();
    	return a;
    }
    ll poww(ll a, ll b)
    {
        ll res = 1;
        while (b > 0)
        {
            if(b & 1) res = (res * a)%mod;
            a = (a * a)%mod;
            b >>= 1;
        }
        return res;
    }
    ll ft[MX] , ift[MX] , iv[MX];
    int32_t main(){
    	n = get_p();
    	ft[0] = 1;
    	for(int i = 1 ; i < MX ;i  ++){
    		for(int j = i ; j < MX;  j += i){
    			divs[j].push_back(i);
    		}
    		ft[i] = (i*ft[i-1])%mod;
    	}
    	ift[MX - 1] = poww(ft[MX - 1] , mod - 2);
    	ll ans = 0;
    	for(int i = MX - 2 ; i >= 0 ; i --){
    		ift[i] = (ift[i+1]*(i+1))%mod;
    	}
    	for(int i = 1 ; i < MX ; i ++){
    		iv[i] = (ift[i] * ft[i-1]) % mod;
    	}
    	for(int i = 1 ; i <= n; i++ ){
    		// scanf("%d" , &a[i]);
    		a[i] = get_p();
    		ans -= a[i];
    		for(auto w : divs[a[i]]){
    			freq[w] += a[i];
    			freq[w] %= mod;
    		}
    	}
    	ans %= mod;
    	if(ans < 0){
    		ans += mod;
    	}
    	for(int i = MX - 1 ; i >= 1 ; i --){
    		dp[i] = (ll) (((long long) freq[i] * ((long long) freq[i]))) % mod;
    		for(int j = 2*i ; j < MX ; j += i){
    			dp[i] -= dp[j];
    		}
    		dp[i] %= mod;
    		if(dp[i] < 0) dp[i] += mod;
    		ans += (dp[i]*iv[i]);
    		ans %= mod;
    	}
    	ans = (ans * iv[2]);
    	ans %= mod;
    	printf("%lld\n" , ans);
    }

Measured memory_bytes: 154624
#include <iostream>

using namespace std;

string Str;
bool End = false;

void solve(string s, int n, int x) //xに等しくできるか.
{
	if (!End)
	{
		//	cout << x << endl;
		if (x == 0 && s.size() == 7)
		{
			cout << s << "=7" << endl;
			End = true;
			return;
		}

		else if (s.size() == 7)
		{
			return;
		}
		int a = 0;
		if (n <= s.size() - 1)
			a = s[n] - '0';
		//	else if (s.size() == 6)
		//		a = s[5] - '0';
		//	cout << "a : " << a << endl;
			//cout << n << endl;
		string sp = s, sm = s;
		sp.insert(n, "+");
		//	cout << "sp : " << sp << endl;
		sm.insert(n, "-");
		//	cout << "sm : " << sm << endl;
		solve(sp, n + 2, x - a);
		solve(sm, n + 2, x + a);
	}
}

int main()
{
	cin >> Str;
	solve(Str, 1, 7-(Str[0] - '0'));
	
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 200001

vector<ll>g[MAXN];
vector<ll> groups[2];

void dfs(ll pre, ll now, ll d){
  groups[d].push_back(now);
  for(auto to: g[now]){
    if(to==pre)continue;
    dfs(now, to, (d+1)%2);
  }
}

int main(){
  ll n;cin>>n;
  rep(i, n-1){
    ll a,b;cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<ll>nums[3];
  rep1(i, n) nums[(i)%3].push_back(i);

  dfs(-1, 1, 0);

  vector<ll>result(n+1);
  if(groups[0].size()>groups[1].size())swap(groups[0], groups[1]);

  if(groups[0].size() <= n/3){
    for(auto tmp: groups[0]){
      result[tmp] = nums[0].back();
      nums[0].pop_back();
    }
    for(auto tmp: groups[1]){
      rep(i, 3){
        if(nums[i].empty())continue;
        result[tmp] = nums[i].back();
        nums[i].pop_back();
        break;
      }
    }
    rep1(i, n)cout<<result[i]<<' ';
    return 0;
  }

  rep(i, 2){
    for(auto tmp: groups[i]){
      if( !nums[i+1].empty() ){
        result[tmp] = nums[i+1].back();
        nums[i+1].pop_back();
      }else{
        result[tmp] = nums[0].back();
        nums[0].pop_back();
      }
    }
  }
  rep1(i, n)cout<<result[i]<<' ';

  return 0;
}



Measured memory_bytes: 24680
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (S == "Rainy") {
        cout << "Sunny" << endl;
    } else {
        cout << "Rainy" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

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

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

int range(int x) {
	if (x < -8000) return -8000;
	if (x > 8000) return 8000;
	return x+8000;
}

int main() {
	char s[8000+2];
	scanf("%s", s);
	int gx, gy;
	scanf("%d %d", &gx, &gy);
	int n = strlen(s);
	s[n]='T';s[n+1]='\0';
	bool dpx[8000][8000*2+1], dpy[8000][8000*2+1];
	// bool **dpx = (bool**)malloc(sizeof(bool*) * 8000);
	// bool **dpy = (bool**)malloc(sizeof(bool*) * 8000);
	// for (int i = 0; i < 8000; i++) {
	// 	dpx[i] = (bool*)malloc(sizeof(bool) * 8000*2+1);
	// 	dpy[i] = (bool*)malloc(sizeof(bool) * 8000*2+1);
	// }
	SET_ZERO(dpx);
	SET_ZERO(dpy);
	
	int xi = 0;int yi = 0;
	int x = 0; int y = 0;
	int d = 0;bool isX = true;
	for (int i = 0; i <= n; i++) {
		if (s[i] == 'F') {
			d++;
		} else {
			if (isX) {
				eprintf("xi:%d d=%d\n", xi, d);
				if (xi == 0) {
					dpx[0][range(d)] = true;
					if (yi)dpx[0][range(d)] = true;
				} else {
					for (int x = -n; x <= n; x++) {
						dpx[xi][range(x)] = dpx[xi-1][range(x-d)] || dpx[xi-1][range(x+d)];
					}
				}
				xi++;
			} else {
				eprintf("yi:%d d=%d\n", yi, d);
				if (yi == 0) {
					dpy[0][range(d)] = true;
					dpy[0][range(-d)] = true;
				} else {
					for (int y = -n; y <= n; y++) {
						dpy[yi][range(y)] = dpy[yi-1][range(y-d)] || dpy[yi-1][range(y+d)];
					}
				}
				yi++;
			}
			isX = !isX;
			d = 0;
		}
	}

	if (dpx[xi-1<0?0:xi-1][range(gx)] && (yi-1<0?0==gy:dpy[yi-1][range(gy)])) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}



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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    if(n*a > b) cout << b << endl;
    else cout << n*a << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,c,x,ans;
int main(){
    cin>>a>>b>>c>>x; 
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x) ans++;
            }
        }
    }
    cout<<ans; 
    return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cnt[3];
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    int ans = 1;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        int res = 0,now = -1;
        for(int j = 0; j < 3; j++) {
            if(A[i] == cnt[j]) {
                res++;
                now = j;
            }
        }
        if(now == -1) {
            cout << 0 << endl;
            return 0;
        }
        ans*=res;
        ans%=INF;
        cnt[now]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4060
from collections import deque


class Node:
    def __init__(self, parent=-1, left=-1, right=-1):
        self.parent = parent
        self.left = left
        self.right = right


n = int(input())
pre_lst = deque(map(int, input().split()))
in_lst = list(map(int, input().split()))
post_lst = []


def reconstruction(l, r):
    if l >= r:
        return

    c = pre_lst.popleft()
    m = in_lst.index(c)

    reconstruction(l, m)
    reconstruction(m+1, r)

    post_lst.append(c)
    return


def main():
    reconstruction(0, n)
    print(" ".join([str(i) for i in post_lst]))


if __name__ == '__main__':
    main()



Measured memory_bytes: 6008
h,w,n=map(int,input().split());from itertools import product as p;from collections import Counter as c;I=[list(map(int,input().split()))for i in[0]*n];ans=[0]*9
for k,v in c(c([(a-x)*w+b-y for x,y in p(range(3),repeat=2) for a,b in I if h-1>a-x>0<b-y<w-1]).values()).items():ans[k-1]=v
print((h-2)*(w-2)-sum(ans),*ans,sep='\n')

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

int main()
{
	int a,b,c,d,e;
	cin >> a >> b >> c >> d >> e;
	if (a == 0) cout << "1" << endl;
	if (b == 0) cout << "2" << endl;
	if (c == 0) cout << "3" << endl;
	if (d == 0) cout << "4" << endl;
	if (e == 0) cout << "5" << endl;
	return 0;
}

Measured memory_bytes: 3640
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)


int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	string ans = "No";
	if (s.length() % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	for (auto i = 0; i < s.length(); ++i) {
		if (i % 2 == 1) {
			if (s[i] == s[i - 1])ans = "Yes";
			else { ans = "No"; break; }
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
def 解():
    sS = input().rstrip()
    sT = input().rstrip()
    iS = len(sS)
    iT = len(sT)

    dp = [[0]*(iT+1) for _ in range(iS+1)]
    for i in range(iS):
        for j in range(iT):
            if sS[i] == sT[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
    iC = dp[iS][iT]
    aR = [""]*iC
    i = iS
    j = iT
    while 0 < i and 0 < j:
        if sS[i-1] == sT[j-1]:
            aR[dp[i][j]-1]=sS[i-1]
            i -= 1
            j -= 1
        else:
            if dp[i][j] == dp[i][j-1] :
                j -= 1
            elif dp[i][j] == dp[i-1][j] :
                i -= 1
            else:
                break

    print("".join(aR))
    exit()

    def findS(i,j):
        iC = dp[i][j]
        if iC == 0 or aR[iC-1] != "":
            return False
        if dp[i][j] == dp[i-1][j] + 1 == dp[i][j-1] +1 :
            t = dp[i][j]
            aR[t-1] = sS[i-1]
            findS(i-1,j-1)
        else:
            findS(i-1,j)
            findS(i,j-1)
    findS(i,j)
    print("".join(aR))
解()


Measured memory_bytes: 112604
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <functional>
using namespace std;


int main() {
	long n, h;
	long a[100001] = {}, b[100001] = {};

	cin >> n >> h;
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i];

	sort(a, a + n, greater<long>());
	sort(b, b + n, greater<long>());

	long cnt;
	for (cnt = 0; h > 0 && b[cnt] >= a[0]; cnt++) {
		h -= b[cnt];
	}
	if (h > 0)cnt += (h - 1) / a[0] + 1;

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
typedef string::const_iterator State;
class ParseError
{
};

int main(int argc, char const *argv[])
{
    pair<int, int> d[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}};
    while (true)
    {
        map<pair<int, int>, bool> block;
        map<pair<int, int>, bool> mp;
        deque<pair<int, int>> que;
        ll ans = 0;
        int t, n;
        cin >> t >> n;
        if (t == 0 && n == 0)
            break;
        rep(i, n)
        {
            pair<int, int> p;
            cin >> p.first >> p.second;
            block[p] = true;
        }
        pair<int, int> p;
        cin >> p.first >> p.second;
        que.push_back(p);
        mp[p] = true;
        ans++;
        rep(_, t)
        {
            deque<pair<int, int>> next;
            while (!que.empty())
            {
                pair<int, int> pos = que.back();
                int x = pos.first;
                int y = pos.second;

                que.pop_back();
                rep(i, 6)
                {
                    int nx = x + d[i].first;
                    int ny = y + d[i].second;
                    if (block[{nx, ny}] == false && mp[{nx, ny}] == false)
                    {
                        mp[{nx, ny}] = true;
                        next.push_back({nx, ny});
                        ans++;
                    }
                }
            }
            while (!next.empty())
            {
                que.push_back(next.back());
                next.pop_back();
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3488
n = input()
len_n = len(n)
if n == "1":
    ans = 1
elif int(n[0]) == 1:
    ans = 9 * (len_n - 1)
else:
    ans = (int(n[0]) - 1) + (9 * (len_n - 1))
if ans < sum([int(i) for i in list(n)]):
    ans = sum([int(i) for i in list(n)])
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <limits>
using ll = long long;
using ld = long double;
ll MOD = 1e9 + 7;
using namespace std;
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    ld n;
    cin>>n;
    for(ld i=1;i<=3500;i++){
        for(ld j=1;j<=3500;j++){
            ld k=(n*i*j)/(4*i*j-n*i-n*j);
            if(k<0)continue;
            if(k==(int)k){
                cout<<i<<" "<<j<<" "<<(int)k<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll n;
  string s;
  cin >> n >> s;
  rep(i,sz(s)){
    if('Z'<s[i]+n){
      s[i] += n - 26;
    }
    else{
      s[i] += n;
    }
  }
  print(s);
}

Measured memory_bytes: 256
import sys
import time
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    A.sort(reverse=True)
    ans = 0
    for i in range(N):
        ans += A[2*i +1]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31684
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] v = new int[N];
		int[] odd = new int[100001];
		int[] even = new int[100001];
		for (int i=0;i<N;i++) {
			v[i] = Integer.parseInt(sc.next());
			if (i%2==0) {
				even[v[i]]++;
			} else if(i%2==1) {
				odd[v[i]]++;
			}
		}
		int odd_index = 0;
		int even_index = 0;
		int odd_max = 0;
		int even_max = 0;
		for (int i=0;i<=100000;i++) {
			odd_max = Math.max(odd_max, odd[i]);
			if (odd_max==odd[i]) {
				odd_index = i;
			}
			even_max = Math.max(even_max, even[i]);
			if (even_max==even[i]) {
				even_index = i;
			}
		}
		if (odd_index!=even_index) {
			System.out.println(N-odd[odd_index]-even[even_index]);
		} else {
			Arrays.sort(odd);
			Arrays.sort(even);
			System.out.println(Math.min(N-odd[99999]-even[100000],N-odd[100000]-even[99999]));
		}
	}
}

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



#define int int64_t
signed main()
{
	int n; cin >> n;
	vector<int> a(n+1);
	for(int i = 0, i_len = (int)n+1; i < i_len; ++i) cin >> a[i];
	
	vector<int> b(n);
	for(int i = 0, i_len = (int)n; i < i_len; ++i) cin >> b[i];

	int ans{};
	for(int i = 0, i_len = (int)n; i < i_len; ++i){
		int left = min(a[i], b[i]);
		ans += left;
		a[i] -= left;
		b[i] -= left;

		int right = min(a[i+1], b[i]);
		ans += right;
		a[i+1] -= right;
		b[i] -= right;
	}

	cout << ans << endl;
}

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

int32_t main() {
 
	int n;	cin >> n;
	int a[n];
  	for(int x=0;x<n;x++)	cin >> a[x];
  	int sum = 0;
  	for(int x=0;x<n-1;x++){
      for(int y=x+1;y<n;y++){
        sum += (a[x] * a[y]);
      }
    }
  cout << sum;
 
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.nextLine();
		sc.nextLine();

		int i = 1;
		while( N > (i * K) - (i - 1)) {
			i++;
		}

		System.out.println(i);
	}

}

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

int main(void){
    int n;
    cin >> n;
    int b[n-1];rep(i,n-1)cin >> b[i];
    
    vector<int> a(n,0);
    ll sum = 0;
    a[0] = a[1] = b[0];
    for(int i = 1;i < n-1;i++){
        a[i+1] = b[i];
        if(a[i] > a[i+1])a[i] = a[i+1];
    }
    rep(i,n)sum += a[i];
    
    cout << sum << endl;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;



int main(){
   int n; cin>>n;
   vector<int> a(n);
   rep(i, n) cin>>a[i];
   sort(a.begin(), a.end());
   ll ans = MOD;
   for(int i = a[0]; i <= a[n - 1]; i++){
       ll now = 0;
       rep(j, n) now += (a[j] - i) * (a[j] - i);
       ans = min(ans, now);
   }
   cout<< ans <<endl;
}


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

using namespace std;

typedef long long int ll;

const ll MAXN = 1e5 + 5;

vector < vector < ll > > adj(MAXN, vector < ll > ());

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

  ll n, m;
  cin >> n >> m;
  vector < ll > h(n + 1);
  for(int i = 1; i <= n; i++) cin >> h[i];
  for(int i = 0; i < m; i++){
    ll u , v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  ll ans = 0;
  for(int i = 1; i <= n; i++){
    bool ok = true;
    for(auto to : adj[i]){
      if(h[to] >= h[i]) ok = false;
    }
    if(ok) ans++;
  }

  cout << ans << endl;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int hoge[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

	cout << hoge[K-1] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define ALL(i) (i).begin(),(i).end()
#define RALL(i) (i).begin(),(i).end(),greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005
// #define int long long
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double EPS = 1e9 + 7;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline int in(){int x;std::cin>>x;return x;}

using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int> >;
using vl = vector<long long>;
using vp = vector<pint>;

template <typename T> void print(T x) { std::cout << x << '\n'; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}
signed main(){
  int N;
  int H[104]={0};
  cin>>N;
  int ans=1;
  rep(i,N)cin>>H[i];
  RFOR(i,1,N){
    int count = 0;
    RFOR(j,0,i){
      if(H[j] <= H[i] )count++;
      else break;
    }
    if( count == i )ans++;
  }
  print(ans);
  return 0;
}


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


int main(){



  int n,k;
  cin>>n>>k;
  
  vector<int> x(n);
  
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    x.at(i)=tmp;
  }

  
  int answer=-1;
  
  if (x.at(0)>=0){
    answer=x.at(k-1)-0;

  }
  
  else if (x.at(n-1)<=0){
    answer=0-x.at(n-k);
  }
  
  else {
    int myindex;
    for (int i=0;i<n;i++){
      if (x.at(i)>=0){
        myindex=i;
        break;
      }
    }
    
    int minindex,maxindex;
    
    minindex=max(0,myindex-k);
    maxindex=min(n-k,myindex+1);
    
    for (int j=minindex;j<=maxindex;j++){
      int dis;
      
      int leftend;
      int rightend;
      
      leftend=x.at(j);
      rightend=x.at(j+k-1);
      
      if (leftend>=0){
        dis=rightend;
      
      }
      
      else if (rightend<=0){
        dis=0-leftend;
      }
      
      else {
        dis=min(abs(leftend),abs(rightend))+abs(leftend)+abs(rightend);
      }
      
      if (answer==-1){
        answer=dis;
      }
      
      else {
        answer=min(answer,dis);
      }
    }
  }
  

  
  cout<<answer<<endl;
  
                   
                                 
      
   
    
  
  
  

    
    
    

  
}

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

int main() {
  int N, L;
  cin >> N >> L;
  int M[N],sum=0;
  for(int i=0; i<N; i++) {
    M[i]=L+i;
    sum+=M[i];
  }
  int K,cnt=0;
  for(int i=0; i<101; i++) {
    for(int j=0; j<N; j++) {
      if(abs(M[j])==i) {
        K=M[j];
        cnt++;
        break;
      }
    }
    if(cnt!=0) {
      break;
    }
  }
  cout << sum-K << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int>T(N);
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        cin >> T[i];
        cnt+=T[i];
    }
    int M;
    cin >> M;
    for(int i = 0; i < M; i++) {
        int P,X;
        cin >> P >> X;
        cout << cnt-T[P-1]+X << endl;
    }
}


Measured memory_bytes: 256
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;


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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF;
    string str;
    cin>>a>>b>>c;
    maxi=max(a,b);
    maxi=max(maxi,c);
    if((maxi*3-a-b-c)%2) f=1;
    ll sum=0;
    d=maxi*3-a-b-c;
    if(f==1) d+=3;
    d/=2;
    cout<<d<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int  a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    
    if((a==b && a!=c) || (b==c && a!=c )|| (c==a && c!=b))
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){

  int x, y;
  
  while(1){
    scanf("%d %d",&x, &y);
    if (x==0 && y==0) break;
    if (x >= y){
      printf("%d %d\n",y, x);
    }else{
      printf("%d %d\n",x, y);
    }
  }
    return 0;
  }

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int neededTry(int k, int start)
{
    if(start >= k) {
        return 0;
    }
    int cnt = 0;
    while(1) {
        cnt++;
        if(start * 2 >= k) {
            break;
        }
        else {
            start *= 2;
        }
    }
    return cnt;
}

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

    int i;
    double sum = 0.0;
    for(i=1; i<=n; i++) {
        sum += pow(0.5, neededTry(k, i)) / n;
    }
    cout << setprecision(12) << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string s;
  int len=0,a=0,b=0;
  cin >> s;
  for (len=0;s[len]!='\0';len++){}
  for(int i=0;i<len;i++){
    if (s[i]=='A'){
      a = i;
      break;
    }
  }
  for(int i=len-1;i>0;i--){
    if(s[i]=='Z'){
      b = i+1;
      break;
    }
  }
  cout << b-a;
}

Measured memory_bytes: 640
fn pos(l: i32, rad: f64) -> (f64, f64) {
    let l = l as f64;
    (l * rad.cos(), l * rad.sin())
}

fn run() {
    proconio::input! {
        a: i32,
        b: i32,
        h: f64,
        m: f64,
    }
    let a = pos(a, 2.0 * std::f64::consts::PI * (h / 12.0 + m / 12.0 / 60.0));
    let b = pos(b, 2.0 * std::f64::consts::PI / 60.0 * m);
    let dx = a.0 - b.0;
    let dy = a.1 - b.1;
    let ans = (dx.powi(2) + dy.powi(2)).sqrt();
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 2892
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: str):
    sum = 0
    for d in list(N):
        sum += int(d)

    if sum%9==0:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)  # type: str
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 28932
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 300007;
const LD EPS = 1e-7;

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	LL x, y, cur, ans = 0;
	cin >> x >> y;
	cur = x;
	while (cur <= y)
	{
		++ans;
		cur <<= 1;
	}
	cout << ans;
	//cout << endl; system("pause");
	return 0;
}

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

int main() {
	int n, ll;
	cin >> n >> ll;
	int l[n+1], sum = 0;
	for(int i = 1; i <= n; i++)
	{
		l[i] = i+ll-1;
		sum += l[i];
	}
	int min1 = 1000000, ans;
	for(int i = 1; i <= n; i++)
	{
		int temp = 0;
		for(int j = 1; j < n+1; j++)
		{
			if(i!=j) temp += l[j];
		}
		if( abs(sum-temp) < min1)
		{
			min1 = abs(sum-temp);
			ans = temp;
		}
	}
	cout << ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
from heapq import *
 
N = int(input())
A = list(map(int, input().split()))
B = list(map(lambda x: -x, reversed(A)))

def left_scores(L):
  s = sum(L[:N])
  scores = [s]
  q = L[:N]
  heapify(q)

  for e in L[N:2*N]:
    s -= heappushpop(q, e)
    s += e
    scores.append(s)
  return scores

print(max(map(lambda x: x[0]+x[1], zip(left_scores(A), reversed(left_scores(B))))))

Measured memory_bytes: 38748
#include <iostream>

int min(int a, int b) {
    if (a >= b) {
        return b;
    } else {
        return a;
    }
}

int main()
{
    int n;
    int *b;
    int total = 0;

    std::cin >> n;
    b = new int[n - 1];
    for (int i = 0; i < n - 1; i++) {
        std::cin >> b[i];
    }

    total += b[0];
    for (int i = 1; i < n - 1; i++) {
        total += min(b[i - 1], b[i]);
    }
    total += b[n - 2];
    std::cout << total << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int A;
int B;
int m[3];

scanf("%d %d", &A, &B);
m[0] = A+B;
m[1] = A-B;
m[2] = A*B;

int max;
max = m[0];
int i ;

for(i = 1; i < 3;i++){
if(max < m[i])
max = m[i];
}

printf("%d", max);

return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	string line;
	int r,i,c;
	for(;cin>>line,line!="0";cout<<r<<endl){
		vector<int>v(11);
		for(r=i=0;i<line.size();i++){
			c=line[i]-'0';
			reverse(v.begin()+1,v.end());
			rotate(v.begin(),v.begin()+(11-c),v.end());
			r+=v[0];
			if(c)v[c]++;
		}
	}
}

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

using namespace std;

long long ok(int x, int y){
	return x * 1LL * x + y * 1LL *  y;
}

int main(){
	int n, d;
	scanf("%d %d", &n, &d);
	int ans = 0;
	for (int i = 0; i < n; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		if (ok(x, y) <= d * 1LL * d)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n,m;
vi a;

int main(){
	cin>>n>>m;
	a=vi(n);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		a[u-1]++;a[v-1]++;
	}
	bool B=1;
	for(int i=0;i<n;i++) if(a[i]%2==1) B=0;
	cout<<(B?"YES":"NO")<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int f = 0;
  int c = 0;
  for (int i = 0; i < N - 1; i++) {
    if (f == 1) {
      f = 0;
      continue;
    }
    if (a[i] == a[i+1]) {
      c++;
      f = 1;
      continue;
    }
    f = 0;
  }
  cout << c << endl;
  return 0;
}


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

int main()
{
	ll a[7];
	for(int i = 0;i<7;++i)
	cin >> a[i];
	ll ans = 0;
	ans += a[0]/2*2;
	ans += a[1];
	ans += a[3]/2*2;
	ans += a[4]/2*2;
	if(a[0]%2==1&&a[3]%2==1&&a[4]%2==1)
	{
		ans+=3;
	}
	ll b[7],c[7];
	for(int i = 0;i<7;i++)
	{
		b[i] = c[i] = a[i];
	}
	ll hoge = 0;
	ll foo = min(a[0],min(a[3],a[4]));
	hoge += 3*foo;
	a[0]-=foo;
	a[3]-=foo;
	a[4]-=foo;
	hoge += a[0]/2*2;
	hoge += a[3]/2*2;
	hoge += a[4]/2*2;
	hoge += a[1];

	ll ans2 = 0;
	if(b[0]>0&&b[3]>0&&b[4]>0)
	{
		ans2 += 3;
		b[0]--;
		b[3]--;
		b[4]--;
		ans2 +=b[0]/2*2;
		ans2 += b[3]/2*2;
		ans2 += b[4]/2*2;
		ans2 += b[1];
	}
	cout<<max(ans,max(ans2,hoge))<<endl;
	return 0;
}

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

int main(){
  int n,k;
  cin>>n>>k;
  int h[n],i,ans=0;
  for(i=0;i<n;i++){
    cin>>h[i];
    if(h[i]>=k)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long double ld;

constexpr ld inf = 1e9;
constexpr ld eps = 1e-9;

bool equal(ld x,ld y){
    return abs(x-y)<eps;
}

struct point{
    ld x,y;
    bool operator<(const point& r)const{
        if(x!=r.x) return x<r.x;
        else return y<r.y;
    }
};

struct state{
    int left,right;
    ld dist;
    bool operator<(const state& r)const{
        return dist>r.dist;
    }
};

ld cross_pointx(point& p0,point& p1,ld y0){
    ld a = (p1.y-p0.y)/(p1.x-p0.x);
    if(equal(a,0.0)) return p0.x;
    ld b = -a*p0.x+p0.y;
    return (y0-b)/a;
}

ld d(point& p0,point& p1){
    ld dx = p0.x-p1.x,dy = p0.y-p1.y;
    return sqrt(dx*dx+dy*dy);
}

bool inx(ld l, ld r, ld x){
    if(l>r) swap(l,r);
    return l-eps<x && x<r+eps;
}

ld solve(int N,vector<point>& P){
    vector<point> node;
    for(int i=0;i<N;i++){
        node.push_back(P[i]);
        if(i==N-1) continue;
        set<int> checked;
        for(int j=0;j<N;j++) if(!checked.count((int) P[j].y)){
            if(min(P[i].y,P[i+1].y)<P[j].y && P[j].y<max(P[i].y,P[i+1].y)){
                node.push_back((point){cross_pointx(P[i],P[i+1],P[j].y),P[j].y});
                checked.insert((int) P[j].y);
            }
        }
    }
    int n = node.size();
    auto in = [&](int l,int r){
        return l<=r && 0<=l && r<n;
    };
    sort(node.begin(),node.end());
    priority_queue<state> Q;
    Q.push({0,n-1,0});
    set<pair<int,int>> checked;
    while(!Q.empty()){
        state now = Q.top(); Q.pop();
        if(now.left==now.right) return now.dist;
        if(checked.count({now.left,now.right})) continue;
        checked.insert({now.left,now.right});
        for(int dl=-1;dl<=1;dl++) for(int dr=-1;dr<=1;dr++){
            int nl = now.left+dl,nr = now.right+dr;
            if(in(nl,nr) && equal(node[nl].y,node[nr].y)){
                Q.push({nl,nr,now.dist+d(node[now.left],node[nl])+d(node[now.right],node[nr])});
            }
        }
    }
}

int main(){
    int N;
    while(cin >> N && N){
        vector<point> P(N);
        for(int i=0;i<N;i++){
            ld x,y;
            cin >> x >> y;
            P[i] = {x,y};
        }
        cout << fixed << setprecision(10) << solve(N,P) << endl;
    }
}


Measured memory_bytes: 4520
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    string S, T;
    cin >> S >> T;
    cout << T << S << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,M; cin>>N>>M;
    vector<pair<int,int>> shop(N);
    rep(n,0,N){
        int a,b; cin>>a>>b;
        shop.at(n)=make_pair(a,b);
    }

    sort(ToEnd(shop));
    int buy=0;
    int64_t ans=0;
    for(auto s:shop){
        int64_t num=min(M-buy,s.second);
        ans+=s.first*num;
        buy+=num;
        if(buy>=M) break;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
def selection(l):
	lists = l[:]
	N = len(lists)

	for i in range(N):
		minj = i

		for j in range(i, N):
			if int(lists[j][1]) < int(lists[minj][1]):
				minj = j
		if i == minj:
			continue
		else:
			lists[i], lists[minj] = lists[minj], lists[i]

	return lists


def bubble(l):
	lists = l[:]
	N = len(lists)
	flag = 1

	while flag:
		flag = 0
		for j in range(N - 1, 1 - 1, -1):
			if int(lists[j][1]) < int(lists[j - 1][1]):
				lists[j], lists[j - 1] = lists[j - 1], lists[j]
				flag = 1

	return lists


def output(l):
	count = 0
	leng = len(l)
	for i in l:
		count += 1
		if count < leng:
			print(i, end =' ')
		else:
			print(i)




if __name__ == '__main__':
	n = int(input())
	l = input().split()
	l_1 = bubble(l)
	l_2 = selection(l)

	output(l_1)
	print("Stable")
	output(l_2)
	if l_1 == l_2:
		print("Stable")
	else:
		print("Not stable")



Measured memory_bytes: 5616