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

long long C[51][51];
void comb_table(int N) {
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= i; ++j) {
			if (j == 0 || j == i) {
				C[i][j] = (long long)1;
			}
			else {
				C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
			}
		}
	}
}

int main() {
	// 前処理
	int N, A, B;
	cin >> N >> A >> B;
	comb_table(N);
	vector<long long>V(N);
	for (int i = 0; i < N; ++i) {
		cin >> V[i];
	}
	sort(V.rbegin(), V.rend());

	pair<long long, long long>pans;
	long long anscount = 0;
	long long sum = 0;
	{
		for (int i = 0; i < A; ++i) {
			sum += V[i];
		}
		int count0 = 0;
		int count1 = 0;
		for (int i = 0; i < N; ++i) {
			if (V[A - 1] == V[i]) {
				count0++;
				if (i <= A - 1) {
					count1++;
				}
			}
		}
		long long anscountsub = C[count0][count1];
		pans = make_pair(sum, A);
		anscount = anscountsub;
	}
	{
		for (long long i = A + 1; i <= B; ++i) {
			sum += V[i - 1];
			int count0 = 0;
			int count1 = 0;
			for (int j = 0; j < N; ++j) {
				if (V[i - 1] == V[j]) {
					count0++;
					if (j <= i - 1) {
						count1++;
					}
				}
			}
			long long anscountsub = C[count0][count1];
			if ((pans.first*i) < (sum*pans.second)) {
				pans = make_pair(sum, i);
				anscount = anscount;
			}
			else if ((pans.first*i) == (sum*pans.second)) {
				anscount += anscountsub;
			}
		}
	}
	long double dans = (long double)pans.first / (long double)pans.second;
	printf("%.10Lf\n", dans);
	cout << anscount << endl;
	return 0;

}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if (K <= A) cout << K << endl;
    else if (A+B >= K) cout << A << endl;
    else cout << (A - (K-A-B)) << endl;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define RREP1(i, n) for (ll i = n; i >= 1; i--)
#define FOR(i, a, b, c) for (ll i = a; i <= b; i += c)
#define RFOR(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define INF 1145141919
typedef long long ll;

int main() {
    char a, b;
    scanf("%c %c", &a, &b);
    
    if (b == 'H') {
        if (a == 'H') puts("H");
        else puts("D");
    }
    else {
        if (a == 'H') puts("D");
        else puts("H");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

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

  int ans = 0;
  int i = 1;
  while (i <= N) {
    if (i == 10) {
      i = 100;
      continue;
    }
    if (i == 1000) {
      i = 10000;
      continue;
    }
    if (i == 100000) {
      break;
    }
    ++ans;
    ++i;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)ull
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("NO"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n,a,b,c,d;
  scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
  ll x = a-b;
  rep(i,n) {
    ll l = ll(i)*c+ll(n-1-i)*(-d);
    ll r = ll(i)*d+ll(n-1-i)*(-c);
    if (l <= x && x <= r) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}






















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

main(){
    int n,k;cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll dp[n];
    dp[0]=0;
    dp[1] = abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        ll temp = INT_MAX;
       for(int j=1;j<=k;j++){
           if((i-j)>=0) temp = min(temp,dp[i-j]+abs(a[i]-a[i-j]));
       }
       dp[i] = temp;
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 4744
#include<cstdio>
#include<cstring>
#define RI register int
#define CI const int&
using namespace std;
const int N=100005;
int n,k;
struct permutation
{
	int a[N];
	inline permutation(void) { memset(a,0,sizeof(a)); }
	inline int& operator [] (CI x) { return a[x]; }
	inline friend permutation operator ~ (permutation A)
	{
		permutation tp; for (RI i=1;i<=n;++i) tp[A[i]]=i; return tp;
	}
	inline friend permutation operator * (permutation A,permutation B)
	{
		permutation C; for (RI i=1;i<=n;++i) C[i]=A[B[i]]; return C;
	}
	inline friend permutation operator ^ (permutation A,int p)
	{
		permutation t; for (RI i=1;i<=n;++i) t[i]=i;
		for (;p;p>>=1,A=A*A) if (p&1) t=t*A; return t;
	}
	inline void print(void)
	{
		for (RI i=1;i<=n;++i) printf("%d ",a[i]);
	}
}a[10],T;
int main()
{
	RI i; for (scanf("%d%d",&n,&k),i=1;i<=n;++i) scanf("%d",&a[1][i]);
	for (i=1;i<=n;++i) scanf("%d",&a[2][i]);
	for (i=3;i<=6;++i) a[i]=a[i-1]*(~a[i-2]);
	int d=k/6,r=k%6; if (!r) --d,r=6; T=a[2]*(~a[1])*(~a[2])*a[1];
	return ((T^d)*a[r]*((~T)^d)).print(),0;
}

Measured memory_bytes: 12276
package main

import (
	"fmt"
)

type Node struct {
	Id int
	Left int
	Right int
	Parent int
	Depth int
	Height int
	Slibing int
	Degree int
}

func main() {
	var n int
	fmt.Scan(&n)

	// init
	nodes := make([]Node, n)
	for i := 0; i < n; i++ {
		nodes[i].Parent = -1
		nodes[i].Depth = -1
		nodes[i].Left = -1
		nodes[i].Right = -1
		nodes[i].Slibing = -1
	}

	// input
	for i := 0; i < n; i++ {
		var id int
		fmt.Scan(&id)
		nodes[id].Id = id
		fmt.Scan(&(nodes[id].Left))
		fmt.Scan(&(nodes[id].Right))
		if nodes[id].Left >= 0 {
			nodes[nodes[id].Left].Parent = nodes[id].Id
		}
		if nodes[id].Right >= 0 {
			nodes[nodes[id].Right].Parent = nodes[id].Id
		}
	}

	// find parent
	parent := -1
	for i := 0; i < n; i++ {
		if nodes[i].Parent == -1 {
			parent = nodes[i].Id
			break
		}
	}

	if parent < 0 {
		panic("invalid parent")
	}
	find(&nodes, parent, 0, -1)

	for i := 0; i < n; i++ {
		node := nodes[i]
		ntype := "leaf"
		if node.Parent == -1 {
			ntype = "root"
		} else if node.Degree > 0 {
			ntype = "internal node"
		}
		fmt.Printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", node.Id, node.Parent, node.Slibing, node.Degree, node.Depth, node.Height, ntype)
	}
}

func find(nodes *[]Node, id int, depth int, slibing int) {
	node := &(*nodes)[id]
	node.Depth = depth
	node.Slibing = slibing
	if node.Left >= 0 {
		node.Degree++
		find(nodes, node.Left, depth + 1, node.Right)
		if node.Height < (*nodes)[node.Left].Height + 1 {
			node.Height = (*nodes)[node.Left].Height + 1
		}
	}
	if node.Right >= 0 {
		node.Degree++
		find(nodes, node.Right, depth + 1, node.Left)
		if node.Height < (*nodes)[node.Right].Height + 1 {
			node.Height = (*nodes)[node.Right].Height + 1
		}
	}
}




Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>

#define INF (1 << 20)
#define MAX 10001
#define WHITE 0
#define BLACK 2
#define GRAY 1

using namespace std;

int n, dist[MAX], color[MAX];
vector<pair<int, int>> arrows[MAX];

void dijkstra(void);

int main() {
	int i, j, u, k, v, c;

	cin >> n;
	

	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> v >> c;
			arrows[u].push_back(make_pair(v, c));
		}
	}

	dijkstra();

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


	return 0;
}

void dijkstra(void) {
	int i;
	pair<int, int> u;
	priority_queue<pair<int, int>> grays;
	vector<pair<int, int>>::iterator itv;
	
	dist[0] = 0;
	for (i = 1; i < n; i++) {
		dist[i] = INF;
		color[i] = WHITE;
	}

	color[0] = GRAY;
	grays.push(make_pair(0, 0));

	while (!grays.empty()) {
		u =  grays.top();
		u.first *= -1;
		grays.pop();
		color[u.second] = BLACK;

		for (itv = arrows[u.second].begin(); itv != arrows[u.second].end(); itv++) {
			if (color[itv->first] == BLACK)continue;
			if (dist[u.second] + itv->second < dist[itv->first]) {
				dist[itv->first] = dist[u.second] + itv->second;
				color[itv->first] = GRAY;
				grays.push(make_pair(((-1) * dist[itv->first]), itv->first));
			}
		}
	}

}

Measured memory_bytes: 7992
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define f find
#define ub upper_bound
#define lb lower_bound
#define in insert
#define bs binary_search   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
int main() 
{ 
    int n;
    cin>>n;
    double arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    double a=0.0;
    double dp[n+1][n+1];
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
        {
            if(i==0 && j==0)
                dp[i][j]=1.0;
            else if(i==0 && j!=0)
                dp[i][j]=dp[i][j-1]*(1.0-arr[j-1]);
            else if(i!=0 && j==0)
                dp[i][j]=0;
            else
                dp[i][j]=dp[i-1][j-1]*arr[j-1]+dp[i][j-1]*(1.0-arr[j-1]);
        }
    for(int i=(n/2)+1;i<=n;i++)
        a=a+dp[i][n];
    cout<<fixed<<setprecision(10)<<a;
    return 0; 
} 

Measured memory_bytes: 70528
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;
    ll n,k,a[100010],now=0;
    cin>>n>>k;
    rep(i,n){
        cin>>a[i];
        if(a[i]==1) now=i;
    }
    ll b=now,c=n-1-now;
    ll ans=0;
    ans+=b/(k-1)+(b%(k-1)!=0);
    c-=((k-1)*ans)-now;
    c=max(c,0ll);
    ans+=c/(k-1)+(c%(k-1)!=0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
open Printf open Scanf
let divisors v = 
	let rec f0 i a =
		if i*i > v then a
		else if i*i = v && v mod i = 0 then i::a
		else if v mod i = 0 then f0 (i+1) (i::(v/i)::a)
		else f0 (i+1) a in f0 1 []
let () = scanf " %d %d" @@ fun n m -> 
	let l = m/n in
	divisors m |> List.sort compare |> List.rev
	|> List.iter @@ fun v ->
		if v <= l then (printf "%d\n" v; exit 0)

Measured memory_bytes: 2432
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		while (k > 0 && b <= a) {
		    b *= 2;
		    k--;
		}
		while (k > 0 && c <= b) {
		    c *= 2;
		    k--;
		}
		if (a < b && b < c) {
		    System.out.println("Yes");
		} else {
		    System.out.println("No");
		}
	}
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int d = 2 * c;

    // pizza C is fixed
    int ans = 2e9;
    REP(i, 1e5 + 1) {
        int xx = x - i, yy = y - i, cost = d * i;
        if(xx > 0) cost += a * xx;
        if(yy > 0) cost += b * yy;
        ans = min(ans, cost);
    }
    cout << ans << endl;

    return 0;
}

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

int T, Q, cn; 
const int inf = 1000000007, mxn = 1000005;
 
string grid[mxn];
int h, w, K, xy[2][2];
vector<vector<int> > lvl;
vector<pair<int, int> > nlvl[mxn];
int cntDir = 4, dirr[] = {1, 0, 0, -1}, dirc[] = {0, -1, 1, 0};
inline bool invalid(int vr, int vc) {
    return vr<0 || vr>=h || vc<0 || vc>=w || grid[vr][vc]=='@';
}
 
static std::function<bool(pair<int, int>, pair<int, int>)> ops[6] = {
    {[](const pair<int, int> &l, const pair<int, int> &r)->bool{return l.first>r.first;}},
    {[](const pair<int, int> &l, const pair<int, int> &r)->bool{return l.second<r.second;}},
    {[](const pair<int, int> &l, const pair<int, int> &r)->bool{return l.second>r.second;}},
    {[](const pair<int, int> &l, const pair<int, int> &r)->bool{return l.first<r.first;}}
};
 
void bfs() {
    lvl[xy[0][0]][xy[0][1]] = 0;
    nlvl[0].push_back({xy[0][0], xy[0][1]});
    for (int i = 0; i < mxn; i++) {
        if (nlvl[i].empty()) return;
        for (int j = 0; j < cntDir; j++) {
            sort(begin(nlvl[i]), end(nlvl[i]), ops[j]);
            for (auto &node : nlvl[i]) {
                int ur = node.first, uc = node.second, vr = ur, vc = uc;
                for (int l = 1; l <= K; l++) {
                    vr += dirr[j], vc += dirc[j];
                    if (invalid(vr, vc) or lvl[vr][vc] <= lvl[ur][uc]) break;
                    if (lvl[vr][vc] == lvl[ur][uc]+1) continue;
                    lvl[vr][vc] = lvl[ur][uc]+1;
                    nlvl[lvl[vr][vc]].push_back({vr, vc});
                }
            }
        }
    }
}
 
signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    cin >> h >> w >> K;
    lvl.resize(h, vector<int>(w, inf));
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> xy[i][j];
            --xy[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        cin >> grid[i];
    }
    bfs();
    if (lvl[xy[1][0]][xy[1][1]] == inf) 
        return cout << "-1\n", 0;
    cout << lvl[xy[1][0]][xy[1][1]] << '\n';
}


Measured memory_bytes: 76848
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    rep(i, N) {
        bool exist[2][26] = {};
        REP(j, 0, i) exist[0][S[j] - 'a'] = true;
        REP(j, i + 1, N - 1)exist[1][S[j] - 'a'] = true;
        int tmp = 0;
        rep(j, 26) if(exist[0][j] && exist[1][j]) tmp++;
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int N, M, V, P, ans = 0;
int A[100000];
ll S[100000];

int findIndex(int current, int val)
{
	int ok = current;
	int ng = -1;

	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (val - A[mid] > M) ok = mid;
		else ng = mid;
	}

	return ok;
}

int main()
{
	cin >> N >> M >> V >> P;
	rep(i, N) cin >> A[i];

	sort(A, A + N, greater<int>());
	rep(i, N) {
		if (i == 0) S[i] = A[i];
		else S[i] = S[i - 1] + A[i];
	}

	if (A[P - 1] == A[N - 1]) {
		cout << N << endl;
		return 0;
	}

	ans = P;
	int index = P;
	int Fmin = A[P - 1];
	while (A[index] == Fmin) {
		ans++;
		index++;
	}

	repc(i, index, N - 1) {
		ll buff, choice, last, sup;
		int ThisMax = A[i] + M;
		int rem = V - (N - i);

		if (A[P - 1] > ThisMax) break;
		else rem -= P - 1;

		if (rem <= 0) {
			ans++;
			continue;
		}

		buff = (ll)ThisMax * (ll)(i - 1 - (P - 1) + 1) - (S[i - 1] - S[P - 2]);
		choice = (ll)M * (ll)rem;
		last = buff - choice;
		if (last < 0) break;

		int j = max(P - 1, findIndex(i, ThisMax));
		sup = (ll)ThisMax * (ll)(i - j) - (S[i - 1] - S[j - 1]);

		if (sup <= last) ans++;
		else break;
	}

	cout << ans << endl;

	return 0;
}


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

typedef long long ll;
///vector<pair<string, int>>;

int main(){
 ll n, begin;
 cin >> n >> begin;
 vector<ll> x;
 rep(i, n) {
   ll y;
   cin >> y;
   x.push_back(y);
 }
 x.push_back(begin);
 sort(x.begin(), x.end());

 ll ans = x[1]-x[0];
 ll size = x.size();
 
 for(int i = 1; i < size-1; i++){
   ans = gcd(ans, x[i+1]-x[i]);
 }

 cout << ans << endl;
}


Measured memory_bytes: 4324
#include<bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)

signed main(){
    int a, b, n;
    cin >> a >> b >> n;

    int x = min(b-1, n);
    cout << (a*x)/b - a*(x/b) << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
const int INF = 1001001001;

int main() {
	long long int n;
	cin >> n;
	vector<long long int> a(n);
	long long int b;
	long long int c = 0;
	rep(i,n){
		cin >> a[i];
		c = c ^ a[i];
	}
	rep(i,n){
		b = c ^ a[i];
		cout << b << " ";
	}
	return 0;
}

Measured memory_bytes: 4704
import sys
data = sys.stdin.readline().replace('\n', '')

indexes = []
def csum(a):
    return (a + 1) * a / 2
prev = 0
for element in range(1, len(data)):
    if data[element - 1] == '>' and data[element] == '<':
        indexes.append((prev, element - 1))
        prev = element
indexes.append((prev, len(data) - 1))
ans = 0
for x, y in indexes:
    fnd = False
    len = y - x + 1
    for i in range(x, y):
        if data[i] == '<' and data[i + 1] == '>':
            a = i - x + 1
            b = y - i
            if a > b:
                ans += csum(a)
                ans += csum(b - 1)
            else:
                ans += csum(b)
                ans += csum(a - 1)

            fnd = True
            break
    if not fnd:
        ans += csum(len)
print ans


Measured memory_bytes: 31868
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int n;
std::vector<int> a;

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int b;
		scanf("%d", &b);
		a.push_back(b);
	}
	std::sort(a.begin(), a.end());
	int bas = a[n-1];
	int crit = 0;
	for(int i = 0; i < n-1; i++){
		if(a[i] < bas/2){
			crit = i;
		}else{
			break;
		}
	}
	if(std::abs(bas - a[crit]*2) <= std::abs(bas - a[crit+1]*2)){
		printf("%d %d\n", bas, a[crit]);
	}else{
		printf("%d %d\n", bas, a[crit+1]);
	}
	return 0;
}


Measured memory_bytes: 892
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi v(n);
	REP(i, n)cin >> v[i];

	int p = 0, cnt = 0;
	vi b(n, 0);
	while (1) {
		if (p == 1) {
			cout << cnt << endl;
			return 0;
		}
		if (b[p]) {
			cout << -1 << endl;
			return 0;
		}
		b[p] = 1;
		p = v[p] - 1;
		cnt++;
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RFOR(i, a, b) for (int i=a;i>=b;--i)
#define ll long long
#define all(a) a.begin(),a.end()
#define ull unsigned long long
#define pb(x) push_back(x)
#define dbg(x) cout<<#x<<" : "<<(x)<<endl;
using namespace std;
const int INF = 1500000000;
const double PI = 3.14159265359;
const int mod = 1000000000 + 7;

const int MAX_N = 50, MAX_P = 50;
int n, p, res, v[MAX_N];

void solve() {
  rep(i, n) v[i] = 0;
  int c = 0;
  while(true) {
    if (p == 0) {
      p = v[c];
      v[c] = 0;
    } else {
      p--;
      v[c]++;
      if (p == 0) {
        bool flg = true;
        rep(i, n) if (i != c && v[i] > 0) flg = false;
        if (flg) break;
      }
    }
    c = (c == n-1) ? 0 : c + 1;
    res = c;
  }
}

int main() {
  while(true) {
    cin >> n >> p;
    if (!n && !p) break;
    solve();
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3024
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int Max = 10 + 1e8;
int main()
{
	int a, b;
	cin >> a >> b;
	rep(i, 1001) {
		int egt = i * 0.08;
		int ten = i * 0.10;
		if (egt == a and ten == b) {
			cout << i;
			return 0;
		}
	}
	cout << "-1";
}

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

inline void read(int&x){
	char c11=getchar();x=0;while(!isdigit(c11))c11=getchar();
	while(isdigit(c11))x=x*10+c11-'0',c11=getchar();
}

const int N=101000;
struct Edge{int v,nxt;}a[N];
int head[N],n,k,_,ans;

int dfs(int x){
	int res=1,t;
	for(int i=head[x];i;i=a[i].nxt){
		t=dfs(a[i].v);
		if(t>=k&&x!=1)++ans,t=-1;
		res=std::max(res,t+1);
	}
	return res;
}

int main(){
	read(n),read(k);
	int x;read(x);if(x!=1)++ans;
	for(int i=2;i<=n;++i)
		read(x),a[++_].v=i,a[_].nxt=head[x],head[x]=_;
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

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

int main(){
     int n,x;
     while(true){
         int cnt=0, r;
         cin >> n >> x;
         if (n==0 && x ==0) break;
         for (int i=1; i< n+1; i++){
             r = x - i;
             for (int j =i+1; j<n+1; j++){
                 if (r-j >j && r-j <n+1){
                     cnt+=1;
                 }
             }
         }
         cout << cnt <<endl;
     }

}



Measured memory_bytes: 3092
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
const int INF32 = numeric_limits<int>::max();
const Int INF64 = numeric_limits<Int>::max();
double const PI = acos(-1);
#define END {cout<<(ans)<<'\n'; return 0;}
#define ALL(vec) vec.begin(),vec.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,s,n) for(int i=s; i<n; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define fi first
#define se second
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,(n)-1)cout<<a[i]<<' '; cout<<a[(n)-1]<<'\n';
#define prip(p) cout<<(p).first<<' '<<(p).second<<'\n'
template<class T> inline bool cmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool cmax(T& a, T b) { if (a < b) { return a = b; } return false; }

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > bellman_ford(Edges< T > &edges, int V, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(V, INF);
  dist[s] = 0;
  for(int i = 0; i < V - 1; i++) {
    for(auto &e : edges) {
      if(dist[e.src] == INF) continue;
      dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
    }
  }
  for(auto &e : edges) {
    if(dist[e.src] == INF) continue;
    if(dist[e.src] + e.cost < dist[e.to]) return vector< T >();
  }
  return dist;
}

int n,m,q,_,x,y;
string s,sb;
bool ok;
char ch;

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

  cin>>n>>m; Edges<int>ed;
  rep(i,m){
    cin>>x>>y>>q; ed.eb(x,y,q);
  }
  V(int)ans[n];
  rep(i,n){
    auto b=bellman_ford(ed,n,i);
    if(b.empty()){pri1("NEGATIVE CYCLE"); return 0;}
    ans[i]=b;
  }
  rep(i,n){
    rep(j,n){
      if(ans[i][j]==INF32)cout<<"INF";
      else cout<<ans[i][j];
      cout<<(j==n-1?'\n':' ');
    }
  }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 102;
int W[N], V[N];
int n, w;
ll dp[N][100005];
ll F(int pos, int rem){
  if (rem <= 0){
    return 0;
  }
  if (pos >= n){
    return 1e12;
  }
  if (dp[pos][rem] != -1){
    return dp[pos][rem];
  }
  ll x = F(pos + 1, rem);
  ll y = F(pos + 1, rem - V[pos]) + W[pos];
  return dp[pos][rem] = min(x, y);
}

int main(){
  memset(dp, -1, sizeof dp);
  cin >> n >> w;
  int sum = 1e5 + 2;
  for (int i = 0; i < n; i++){
    cin >> W[i] >> V[i];
    //sum += V[i];
  }
  int ans = 0;
  for (int i = sum; i >= 0; i--){
    if (F(0, i) <= w){
      ans = max(i, ans);
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 80000
#include<stdio.h>
#include<queue>
using namespace std;
int p[131072],q[131072];
int num=0;
int tp[131072],tq[131072];
int head[262144],last[262144],to[262144],c[262144],cnt=1;
void add(int u,int v,int cc)
{
	cnt++;
	last[cnt]=head[u];
	head[u]=cnt;
	to[cnt]=v;
	c[cnt]=cc;
}
int now[262144];
int d[262144];
queue<int> qq;
void bfs()
{
	for(int i=1;i<=num;i++)
	{
		d[i]=-1;
		now[i]=head[i];
	}
	d[num-1]=0;
	qq.push(num-1);
	while(!qq.empty())
	{
		int u=qq.front();
		qq.pop();
		for(int i=head[u];i;i=last[i])
		{
			if(!c[i])
			{
				continue;
			}
			int v=to[i];
			if(d[v]<0)
			{
				d[v]=d[u]+1;
				qq.push(v);
			}
		}
	}
}
int dfs(int u,int a)
{
	if(u==num||a==0)
	{
		return a;
	}
	int flow=0;
	for(int& i=now[u];i;i=last[i])
	{
		int v=to[i];
		if(d[v]<=d[u])
		{
			continue;
		}
		int flow2;
		if(c[i]<a)
		{
			flow2=dfs(v,c[i]);
		}
		else
		{
			flow2=dfs(v,a);
		}
		a-=flow2;
		flow+=flow2;
		c[i]-=flow2;
		c[i^1]+=flow2;
		if(a==0)
		{
			break;
		}
	}
	return flow;
}
int dinic()
{
	int ans=0;
	while(1)
	{
		bfs();
		if(d[num]<0)
		{
			break;
		}
		ans+=dfs(num-1,1000000000);
	}
	return ans;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&p[i]);
	}
	for(int i=0;i<n;i++)
	{
		scanf("%d",&q[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(tp[i])
		{
			continue;
		}
		num++;
		tp[i]=num;
		for(int j=p[i];j!=i;j=p[j])
		{
			tp[j]=num;
		}
	}
	for(int i=0;i<n;i++)
	{
		if(tq[i])
		{
			continue;
		}
		num++;
		tq[i]=num;
		for(int j=q[i];j!=i;j=q[j])
		{
			tq[j]=num;
		}
	}
	num+=2;
	int ans=n;
	for(int i=0;i<n;i++)
	{
		if(p[i]==i&&q[i]==i)
		{
			ans--;
		}
		else if(p[i]==i)
		{
			add(num-1,tq[i],1);
			add(tq[i],num-1,0);
		}
		else if(q[i]==i)
		{
			add(tp[i],num,1);
			add(num,tp[i],0);
		}
		else if(p[i]==q[i])
		{
			add(tp[i],tq[i],1);
			add(tq[i],tp[i],1);
		}
		else
		{
			add(tp[i],tq[i],1);
			add(tq[i],tp[i],0);
		}
	}
	ans-=dinic();
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8960
#include<iostream>
#include<algorithm>

using namespace std;

bool notprime[1080000];

int main(){
	notprime[1] = true;
	notprime[0] = true;
	for(int i = 2;i * i < 1080000;i++){
		if(notprime[i])continue;
		for(int j = i * i;j < 1080000;j += i){
			notprime[j] = true;
		}
	}
	int a, d, n;
	while(cin >> a >> d >> n, a | d | n){
		for(int i = a;i < 1080000;i += d){
			if(!notprime[i])n--;
			if(n == 0){
				cout << i << endl;
				break;
			}
		}
	} 
	return 0;
}

Measured memory_bytes: 2212
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T inf = numeric_limits<T>::max();
template<class T>
const T sinf = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

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

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

#pragma endregion

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

using Graph = vector<vector<edge>>;

vector<int64_t> dijkstra(Graph G, int64_t s){
    // int64_t inf = numeric_limits<int64_t>::max();
    using Pi = pair<int64_t, int64_t>;
    vector<int64_t> dist(G.size(), inf<int64_t>);
    dist[s] = 0;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    que.emplace(0, s);
    while(!que.empty()){
        int64_t cost, idx;
        tie(cost, idx) = que.top(); que.pop();
        if(dist[idx] < cost) continue;
        for(edge e : G[idx]){
            int64_t next_cost = cost + e.cost;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

int main() {
    int64_t n;
    cin >> n;
    Graph G(n);
    for(int i = 0; i < n - 1; ++i){
        int64_t u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        G[u].emplace_back(u, v, w);
        G[v].emplace_back(v, u, w);
    }
    auto d = dijkstra(G, 0);
    for(int i = 0; i < n; ++i){
        if(d[i] % 2) cout << 1 << endl;
        else cout << 0 << endl;
    }
}

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

#include <utility>
using namespace std;

#define REP(i, n) for ( int i = 0; i < (n); i++ )
const int INF = 1e9;
using Pii = pair<int, int>;

const int con_type = 26;
int D = 365;
int C[con_type];
int S[365][con_type];
vector<int> ans;
int last[con_type];

struct State {
  int cost;
  vector<int> ans;
  vector<int> last;

  State() {
    cost = 0;
    last = vector<int>(26, -1);
  }

  State(int cost, vector<int> ans, vector<int> last):
    cost(cost), ans(ans), last(last) {};

  bool operator<( const State& s ) const {
    return cost < s.cost;
  }

  bool operator>( const State& s ) const {
    return cost > s.cost;
  }
};

void solve() {
  priority_queue<State> Q;
  Q.push(State());
  REP(d, D) {
    priority_queue<State> nQ;
    while ( !Q.empty() ) {
      State now = Q.top(); Q.pop();
      vector<Pii> add_cost;
      REP(i, con_type) {
        add_cost.emplace_back(Pii(S[d][i]+(d-now.last[i])*C[i], i));
      }
      sort(add_cost.begin(), add_cost.end(), greater<Pii>());
      REP(i, 8) {
        int id = add_cost[i].second;
        State next = now;
        next.cost += S[d][id];
        REP(j, con_type) {
          if ( j == id ) continue;
          next.cost -= (d-next.last[j])*C[j];
        }
        next.ans.emplace_back(id);
        next.last[id] = d;
        nQ.push(next);
      }
    }
    Q = priority_queue<State>();
    REP(i, min(800, (int)nQ.size())) {
      Q.push(nQ.top()); nQ.pop();
    }
  }

  ans = Q.top().ans;
}

void input() {
  cin >> D;
  REP(i, con_type) {
    cin >> C[i];
    last[i] = -1;
  }
  REP(i, D) REP(j, con_type) cin >> S[i][j];
}

void output() {
  REP(i, D) cout << ans[i]+1 << endl;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  input();
  solve();
  output();

  return 0;
}


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

int main(){
  int n,k,x,sum=0;
  cin >> n >> k;
  for(int i = 0;i<n;i++){
    cin >> x;
    if(x>k)sum+=2*(x-k);
    else if(k<2*x)sum+=2*(k-x);
    else sum+= 2*x;
  }
  cout << sum << endl;
  
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
count = 0
ans = [0]*n
for i in range(n-1):
    if h[i] >= h[i+1]:
        count += 1
    else:
        ans[i] = count
        count = 0
ans[n-1] = count
print(max(ans))

Measured memory_bytes: 63856
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define ff first
#define se second
#define MAX 1000001
#define MAXN 100005
#define mod 1000000007 
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,ans1,ans2;
    cin>>n>>m;
    if(n==0 && m==0){
        cout<<0;
    }
    else{
        if(n>0){
            n--;
        }
        if(n%4==0){
            ans1=n;
        }
        if(n%4==1){
            ans1=1;
        }
        if(n%4==2){
            ans1=n+1;
        }
        if(n%4==3){
            ans1=0;
        }
        if(m%4==0){
            ans2=m;
        }
        if(m%4==1){
            ans2=1;
        }
        if(m%4==2){
            ans2=m+1;
        }
        if(m%4==3){
            ans2=0;
        }
        ans1=ans1^ans2;
        cout<<ans1;
    }
}

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

al = ['a','b','c','d','e','f','g','h','i','j']
w = ['a']

for num in range(n-1):
    x = []
    for i in range(len(w)):
        x.append(w[i] + 'a')
        for num in range(num+1):
            if al[num] in w[i]:
                x.append(w[i] + al[num+1])
    w = x

for _ in range(len(w)):
    print(w[_])

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

using namespace std;
typedef long long ll;

int main()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a > k)cout << k << endl;
	else if (a + b >= k) cout << a << endl;
	else cout << a - (k - a - b) << endl;
	return 0;
}

Measured memory_bytes: 3168
from heapq import heappop,heappush
n,h=map(int,input().split())
a=[]
for i in range(n):
  x,y=map(int,input().split())
  heappush(a,(-x,1))
  heappush(a,(-y,0))
ans=0
while h>0:
  x,y=heappop(a)
  if y:
    ans+=(h-x-1)//(-x)
    break
  else:
    h+=x
    ans+=1
print(ans)

Measured memory_bytes: 94836
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
readInput :: IO [Int]
readInput = map (either error fst . T.decimal) . T.words <$> T.getLine

main = do
  [n, m] <- readInput
  print $ div (n * (n - 1)) 2
    + div (m * (m - 1)) 2

Measured memory_bytes: 508
#include <iostream>
#include<list>
#include<vector>
#include<stack>
using namespace std;

int main()
{
    int n,q;cin>>n>>q;
    stack<int> sta[n];
    int tp1,tp2,a;
    while(q--){
        cin>>tp1;
        switch(tp1){
        case 0:
            cin>>tp2>>a;
            sta[tp2].push(a);
            break;
        case 1:
            cin>>tp2;
            if(!sta[tp2].empty())cout<<sta[tp2].top()<<"\n";
            break;
        case 2:
            cin>>tp2;
            if(!sta[tp2].empty())sta[tp2].pop();
            break;
        }
    }
}


Measured memory_bytes: 4336
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX=100000;
static const int NIL=-1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c){
  stack<int> S;
  S.push(r);
  color[r]=c;

  while(!S.empty()){
    int u=S.top();
    S.pop();
    int i;

    for(i=0;i<G[u].size();i++){
      int v;
      v=G[u][i];
      if(color[v]==NIL){
	color[v]=c;
	S.push(v);
      }
    }
  }
}

void ass(){
  int id=1;
  int i,u;

  for(i=0;i<n;i++)
    color[i]=NIL;
  for(u=0;u<n;u++){
    if(color[u]==NIL)
      dfs(u,id++);
  }
}

int main(){
  int s,t,m,q;

  cin>>n>>m;

  int i;
  for(i=0;i<m;i++){
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  ass();

  cin>>q;

  for(i=0;i<q;i++){
    cin>>s>>t;
    if(color[s]==color[t]){
      cout<<"yes"<<endl;
    }
    else{
      cout<<"no"<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 9008
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "yes";
            for (int i = 0; i < sS.Length; i++)             //    3
            {                                               // 0123456
                string sOne = sS.Substring(i, 1);           // abcdefg
                string sZan = sS.Substring(0, i) + ((i >= sS.Length - 1) ? "": sS.Substring(i + 1, sS.Length - (i + 1)));
                if (sZan.Contains(sOne)) { sOut = "no"; break; }
            }

            //出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 11220
N = gets.chop.to_i
P = gets.split.map(&:to_i)
ans = 0
(1..N-2).each do |num|
  if P[num-1] < P[num] && P[num] < P[num+1]
    ans += 1
  elsif P[num+1] < P[num] && P[num] < P[num-1]
    ans += 1
  end
end
print ans

Measured memory_bytes: 1788
import java.util.*;
class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        long X = sc.nextLong();
        long n500 = X/500;
        long n5 = (X%500)/5;
        System.out.println(n500*1000+n5*5);
    }
}

Measured memory_bytes: 21844
P,L="+<"
p=print
r=range
p(6484,P,0,1,3,L,2,3,3)
for x in 0,1:p(P,x,3,x);[p(P,v:=x+4,v,v,P,v,3,6,*[P,6,6,6]*(29-t),L,6,x,T:=x*60+9+t,P,v,T,v)for t in r(30)]
for t in r(60):p(P,2,2,2);[p(P,8+t-s,69+s,5,L,3,5,6,P,2,6,2)for s in r(t)]

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

using namespace std;

int main() {
	int d, n;
	cin >> d >> n;
	int ans = 1;
	for (int i = 0; i < d; i++)ans *= 100;
	if (n == 100)cout << ans * n + 1*ans << endl;
	else cout << ans * n << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

ll ans;
int N, M;
int edge[10][10];
vector<int> x;

void solve() {
	for (int i = 2; i <= N; i++) {
		x.push_back(i);
	}
	do {
#if 0
		rep(i, x.size()) {
			cout << x[i] << " ";
		}
		cout << endl;
#endif
		int prev = 1, plus = 1;
		rep(i, x.size()) {
			int cur = x[i];
			if (edge[prev][cur] == 0) {
				plus = 0;
				break;
			}
			prev = cur;
		}
		ans += plus;
	} while (next_permutation(x.begin(), x.end()));
	cout << ans << endl;
}

int main() {
	cin >> N >> M;
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		edge[a][b] = edge[b][a] = 1;
	}
	solve();
	return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll gcd(ll n,ll m){
    n = max(n,m);
    m = min(n,m);
    if(n%m == 0)return m;
    return gcd(m,n%m);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
double kai(int n){
    if(n == 0)return 1;
    return n*kai(n-1);
}
int main(){
    int n;cin >> n;
    double x[8],y[8];
    double sum=0;
    rep(i,n)cin>>x[i]>>y[i];
    vector<int> a;
    rep(i,n)a.push_back(i);
    do{
        rep(i,n-1)sum += sqrt((x[a[i]]-x[a[i+1]])*(x[a[i]]-x[a[i+1]])+(y[a[i]]-y[a[i+1]])*(y[a[i]]-y[a[i+1]]));
    }while(next_permutation(a.begin(),a.end()));
    cout << setprecision(10)<<sum/kai(n) <<endl;   
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>;
vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
using P = pair<ll, ll>;

static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;

struct verticle {
    double theta;
    ll x, y;
    bitset<4> pattern;
};

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll hn, wn; cin >> hn >> wn;
    vector<string> b(hn); rep(i, hn) cin >> b[i]; reverse(all(b));

    vector<verticle> vs;
    rep(h, hn+1) rep(w, wn+1) if (h || w) {
        verticle v;
        v.x = h;
        v.y = w;
        v.theta = atan2(h, w);

        // 10 
        // 23
        auto f = [&](ll h, ll w){ return h >= 0 && w >= 0 && h < hn && w < wn; };
        v.pattern[2] = f(h, w-1) && b[h][w-1] == '#';
        v.pattern[0] = f(h-1, w) && b[h-1][w] == '#';
        v.pattern[1] = f(h-1, w-1) && b[h-1][w-1] == '#';
        v.pattern[3] = f(h, w) && b[h][w] == '#'; 
        vs.pb(v);
    }
    sort(all(vs), [](const verticle& a, const verticle& b){ return a.theta < b.theta; });

    ll ret = 0;
    ll cut = 0;
    ll i = 0;
    while (i < vs.size()) {
        double th = vs[i].theta;
        vector<verticle> p;
        while (i < vs.size() && vs[i].theta < th + EPS) {
            p.pb(vs[i]);
            i++;
        }

        rep(j, p.size()) {
            // +1
            if (!p[j].pattern[0] && !p[j].pattern[1] && p[j].pattern[2] && !p[j].pattern[3]) cut++;
            if (p[j].pattern[0] && p[j].pattern[1] && !p[j].pattern[2] && p[j].pattern[3]) cut++;
            // -1
            if (p[j].pattern[0] && !p[j].pattern[1] && !p[j].pattern[2] && !p[j].pattern[3]) cut--;
            if (!p[j].pattern[0] && p[j].pattern[1] && p[j].pattern[2] && p[j].pattern[3]) cut--;
        }
        chmax(ret, cut); 
    }
    cout << ret + 1 << endl;
    return 0;
}

Measured memory_bytes: 20124
N,A,B = gets.chomp.split.map(&:to_i)
allsum = 0;sum = 0
(1..N).each do |i|
sum = 0
log = 0; log += i
  loop do
    sum += log % 10
    log = log / 10
    if log == 0 then
      if A <= sum && sum <= B then
        allsum += i
      end
      break
    end
  end
end

print("#{allsum}\n")

Measured memory_bytes: 1788