akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

template <class T>
class bsegment_tree {
   public:
    ll size;
    vector<T> data;
    T default_value;

    bsegment_tree(ll n, T default_value_) {
        default_value = default_value_;

        ll siz = 1;
        while (siz < n) {
            siz = siz * 2;
        }
        data.resize(siz * 2, default_value);
        size = siz;
    }

    ~bsegment_tree() {}

    T compare(T& a, T& b) {
        //  ここをカスタム ex) min
        //return min(a, b);
        //return min(a, b);
        return max(a, b);
    }

    void update(ll k, T value) {
        // 葉の節点
        k += size - 1;
        data[k] = value;

        while (k > 0) {
            // 順に親に向かっていく
            k = (k - 1) / 2;
            data[k] = compare(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }

    // [a, b) で compare 最強のもの
    T query_open(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a || b <= l) {  // 共通要素がない
            return default_value;
        }
        if (a <= l && r <= b) {  // 完全に含んでいる
            return data[k];
        }

        // 2つの子の compare で勝つほう
        T vl = query_open(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query_open(a, b, k * 2 + 2, (l + r) / 2, r);
        return compare(vl, vr);
    }

    // [a, b] で compare 最強のもの
    T query(ll a, ll b) {
        return query_open(a, b + 1, 0, 0, size);
    }
};
using segment_tree = bsegment_tree<ll>;
using pll = pair<ll, ll>;
int main() {
    ll N, K;
    cin >> N >> K;
    vector<pll> va(N);
    vector<ll> a(N);
    for (ll i = 0; i < N; i++) {
        ll v;
        cin >> v;
        va[i] = {v, i};
        a[i] = v;
    }

    sort(va.begin(), va.end());

    auto st = segment_tree(N, 0);
    vector<ll> stindex(N, 0);
    for (ll i = 0; i < N; i++) {
        stindex[va[i].second] = i;
    }

    vector<ll> dp(N, 0);
    ll maxlen = 0;
    for (ll i = N - 1; i >= 0; i--) {
        ll v = a[i];
        ll left = lower_bound(va.begin(), va.end(), (pll){v - K, -INF}) - va.begin();
        ll right = upper_bound(va.begin(), va.end(), (pll){v + K, INF}) - va.begin() - 1;
        dp[i] = 1 + st.query(left, right);
        maxlen = max(dp[i], maxlen);
        st.update(stindex[i], dp[i]);
    }
    print(maxlen);
}


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

int main() {
    int n; cin >> n;
    vector<pair<int, int>> ps;
    for (int i = 1; i <= n; i++) {
        int a; cin >> a;
        ps.emplace_back(a, i);
    }
    sort(ps.begin(), ps.end());
    for (auto &p: ps) cout << p.second << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1780
def main():
    n = int(input())
    a = [-1]*(n+2)
    for i in range(1, n+1):
        x = int(input())
        a[x] = i
    x, y = 1, 1
    ans = 0
    while y < n+2:
        if a[y-1] > a[y]:
            buf = y - x
            if buf > ans:
                ans = buf
            x = y
        y += 1
    print(n - ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 10996
#include <bits/stdc++.h>
using namespace std;
long long a,b,c,d,x1,x2;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
    cin>>a>>b>>c>>d;
    x1=a/d;
    x2=c/b;
    if (a%d!=0) x1++;
    if (c%b!=0) x2++;
    if (x2<=x1) cout<<"Yes";
    else
    cout<<"No";
    
}

Measured memory_bytes: 3636
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args){
		new Solution().solve();
	}
}

class Solution{
	public void solve(){
		Scanner scan = new Scanner(System.in);
		while(true){
			int V = scan.nextInt();
			int E = scan.nextInt();
			
			if(V == 0 && E == 0) break;
			
			Edge[] edges = new Edge[E];
			for(int i = 0; i < E; i++){
				edges[i] = new Edge();
				edges[i].from = scan.nextInt();
				edges[i].to = scan.nextInt();
				edges[i].cost = scan.nextInt();
				edges[i].from--;
				edges[i].to--;
			}
			Arrays.sort(edges);
			int ans = -1;
			for(int i = 0; i < E; i++){
				int res = calc(edges, V, i);
				if(res == -1) continue;
				if(ans == -1 || ans > res) ans = res;
			}
			System.out.println(ans);
		}
	}
	
	public boolean one(UnionFind uf, int V){
		int p = uf.findParent(0);
		for(int i = 0; i < V; i++){
			if(uf.findParent(i) != p) return false;
		}
		return true;
	}
	
	public int calc(Edge[] edges, int V, int f){
		UnionFind uf = new UnionFind(V);
		int maxval = 0, minval = (1<<20);
		for(int i = f; i < edges.length; i++){
			Edge e = edges[i];
			if(!uf.hasSameParent(e.from, e.to)){
				uf.unite(e.from, e.to);
				maxval = Math.max(maxval, e.cost);
				minval = Math.min(minval, e.cost);
			}
		}
		
		boolean flg = one(uf, V);
		return (flg?maxval-minval:-1);
	}
}

class Edge implements Comparable{
	public int from, to, cost;

	@Override
	public int compareTo(Object o) {
		return new Integer(this.cost).compareTo(new Integer(((Edge)o).cost));
	}
};

class UnionFind{
	private int[] par;
	private int[] rank;
	
	UnionFind(int V){
		par = new int[V];
		rank = new int[V];
		for(int i = 0; i < V; i++){
			par[i] = i;
			rank[i] = 0;
		}
	}
	
	public void unite(int x, int y){
		x = findParent(x);
		y = findParent(y);
		if(x == y) return;
		
		if(rank[x] < rank[y]){
			par[x] = par[y];
		}else{
			par[y] = par[x];
			if(rank[x] == rank[y]) rank[x]++;
		}
	}
	
	public int findParent(int x){
		if(par[x] == x) return x;
		return par[x] = findParent(par[x]);
	}
	
	public boolean hasSameParent(int x, int y){
		return findParent(x) == findParent(y);
	}
}

Measured memory_bytes: 68280
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {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;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(){
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
struct node{
	ll x,y;
}; 
int main(){
	fast;
	ll n;
	ll minv=2147483647;
	cin>>n;
	ll s[n+1]={0};
	for(int i=1;i<=n;i++){
		ll x;
		cin>>x;
		s[i]=s[i-1]+x;
	}
	for(int i=0;i<=n;i++){
		ll a=0,b=0;
		a=s[i];
		b=s[n]-s[i];
		
		minv=min(minv,abs(a-b));
	}cout<<minv<<endl;
}/*『你强归你强，我永不示弱』*/




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

using namespace std;

#define PI 3.14159265358979323846

int main()
{
	double r, area = 0.0, circumference = 0.0;
	scanf("%lf", &r);
	
	area = PI * (r * r);
	circumference = 2 * PI * r;
	
	printf("%.6lf %.6lf\n", area, circumference);
	
	return 0;
}


Measured memory_bytes: 3156
def main():
    N = int(input())
    #N = 5
    a = N - N%2 - 1
    ans = []
    for i in range(N-1):
        for t in range(i+1,N):
            if i+t != a:
                ans += [{i+1,t+1}]
    
    print(len(ans))
    print('\n'.join("{} {}".format(i,t) for i,t in ans))

main()


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int answer = 0;
  for(int i = 1; i <= N; i++) {
    int sum = 0;
    int x = i;
    
    for(int j = 0; j < 5; j++) {
      sum += x % 10;
      x /= 10;
    }  
    
    if(A <= sum && sum <= B) {
        answer += i;
    }
  }
  cout << answer << endl;
}  
     
      


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, l);
    Sort(l);
    ll ans = 0;
    For(i, n) for(int j = i+1; j < n; j ++){
        auto ub = lower_bound(l.begin() + j+1, l.end(), l[i] + l[j]);
        ans += distance(l.begin() + j+1, ub);
    }
    Cout(ans);
}




Measured memory_bytes: 256
n,y=map(int,input().split())

yukichi=y//10000
higuchi=(y-yukichi*10000)//5000
noguchi=(y-yukichi*10000-higuchi*5000)//1000

for i in range(yukichi+1):
    if i!=0:
        yukichi-=1
        higuchi+=2
    for j in range(higuchi+1):
        if j!=0:
            higuchi-=1
            noguchi+=5
        # print("{0} {1} {2}".format(yukichi,higuchi,noguchi))
        if yukichi+higuchi+noguchi == n:
            print("{0} {1} {2}".format(yukichi,higuchi,noguchi))
            quit()
    higuchi+=noguchi//5
    noguchi-=higuchi*5
else:
    print("-1 -1 -1")

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

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

    vector<int> v(n);
    for (int i=0; i<n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    int r = 0;
    for (auto a: v) {
        if (r < min(v.back() - a, a)) {
            r = a;
        }
    }

    cout << v.back() << " " << r << endl;
    return 0;
}


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

long long MOD = 1000000007;

long long power(long long base, long long n)
{
    if (n == 0) return 1;
    if (n==1) return base;
    long long halfn = power(base, n/2);
    if (n % 2 == 0) return (halfn*halfn)%MOD;
    return (((halfn*halfn) % MOD) * base) % MOD;
}

long long inverse(long long n)
{
    return power(n, MOD-2);
}
long long binom(long long n, long long m)
{
    long long ans = 1;
    for (int i = 0; i < m; i++)
    {
        ans *= (n-i); ans %= MOD;
        ans *= inverse(m-i); ans %= MOD;
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    int k; cin >> k;
    for (int i = 0; i < k; i++)
    {
        cout << "ACL";
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main() {
    int X; cin >> X;
    int a = X % 100, b = X / 100;

    if (a <= 5 * b) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
/*
 *  Created on: 22 / 8 / 2020
 *  Author:     Eslam Waheed
 */

#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO

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

#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define ld   long double

#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define endl    '\n'

//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ld PI = acos(-1);
//const ll mod = 1e9 + 7;
//const ld EPS = 1e-8;
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
	//stp(0)
	Eslam__Waheed;
	double a, b, c; cin >> a >> b >> c;
	int x = ceil(a / b);
	cout << (ll)c * x;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int a[1000005];

void readin(int &x){
	x=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
}
void solve()
{
	int n;cin>>n;
	int mn=n,mx=0; 
	for(int i=1;i<=n;i++)
	{
		readin(a[i]);
		mn=min(mn,a[i]);
		mx=max(mx,a[i]);
	}
	if(mx-mn>=2)
	{
		puts("No");
		return ;
	}
	if(mn==mx&&mx==n-1)
	{
		puts("Yes");
		return ;
	}
	int cnt1=0,cnt2=0; 
	for(int i=1;i<=n;i++)
		if(a[i]==mx-1) cnt1++;
		else cnt2++;
	int p=mx-cnt1;
	if(p*2>cnt2||p<=0)
	{
		puts("No");
		return ;
	}
	puts("Yes");
}
int main()
{
/*	freopen("hat.in","r",stdin);
	freopen("hat.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--)	*/solve();
	return 0;
}

Measured memory_bytes: 640
Scanf.scanf "%d" (fun i ->
    let rec loop i r =
        if r = 4 then i + 3 else
            if r mod 2 = 0 then loop (i + 1) (r / 2)
                           else loop (i + 1) (r * 3 + 1)
    in
    Printf.printf "%d\n" @@ if i = 1 || i = 2 then 4 else loop 1 i
)

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

int main() {
  int n;
  cin>>n;
  string s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  vector<string> ans;
  sort(s,s+n);
  int res=1;
  int max=1;
  for(int i=0;i<n;i++){
    if(i==0) {
      ans.push_back(s[0]);
      continue;
    }
    if(s[i]==s[i-1]){
      res++;
      if(res==max) ans.push_back(s[i]);
      if(res>max) {
        ans.clear();
        ans.push_back(s[i]);
        max=res;
      }
    }
    if(s[i]!=s[i-1]){
      res=1;
      if(res==max) ans.push_back(s[i]);
    }
  }
  for(int i=0;i<ans.size();i++) cout<<ans.at(i)<<endl;
  return 0;
}


Measured memory_bytes: 15988
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int 
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
#define lb lower_bound
#define ub upper_bound
//hash base 177013

void rmax(ll &a,ll b)
{
	a=max(a,b);
}

ll dp[3002][3002][4];

int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	//ll testcase;
	//cin>>testcase;
	//while(testcase--)
	{
		int n,m,q;
		cin>>n>>m>>q;
		ll mat[n][m];
		memset(mat,0,sizeof(mat));
		fi(0,q)
		{
			ll x,y,c;
			cin>>x>>y>>c;
			--x,--y;
			mat[x][y]=c;
		}
		
		//fi(0,4)
		{
			dp[0][0][0]=0;
			dp[0][0][1]=mat[0][0];
			dp[0][0][2]=0;
			dp[0][0][3]=0;
		}
		fi(0,n)
		{
			fj(0,m)
			{
				fk(0,4)
				{
					ll v=dp[i][j][k];
					if(i+1<n) 
					{
						rmax(dp[i+1][j][0],v);
						rmax(dp[i+1][j][1],v+mat[i+1][j]);
					}
					if(j+1<m)
					{
						rmax(dp[i][j+1][k],v);
						if(k+1<=3) rmax(dp[i][j+1][k+1],v+mat[i][j+1]);
					}
				}
			}
		}
		ll ans=0;
		fi(0,4)
			ans=max(ans,dp[n-1][m-1][i]); 
		
		cout<<ans;
		
	}
}


Measured memory_bytes: 355316
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

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

#define INF 100000000
#define EPS 1e-9

#define MAX_N 50
#define MAX_M 100
#define MAX_K 100

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


vector<int> ans_list;


int main(){

	while (true){

		int t, n;
		cin >> t >> n;

		if (t == 0 && n == 0)
			break;

		map<P, bool> obj;
		map<P, bool> maze;

		for (int i = 0; i < n; i++){
			int x, y;
			cin >> x >> y;
			obj[P(x, y)] = true;
		}
	
		int sx, sy;
		cin >> sx >> sy;

		queue<P> que;
		queue<int> turn;
		que.push(P(sx, sy));
		turn.push(t);
		
		maze[P(sx, sy)] = true;

		int ans = 1;

		while (que.size()){
			P p = que.front();
			int count = turn.front();
			que.pop();
			turn.pop();
			if (count == 0)
				continue;
			for (int i = 0; i < 6; i++){
				int nx = p.first + dx[i];
				int ny = p.second + dy[i];
				if (!obj[P(nx, ny)] && !maze[P(nx, ny)] /*&& nx >= -30 && nx <= 30 && -30 <= ny && ny <= 30*/){
					ans++;
					maze[P(nx, ny)] = true;
					que.push(P(nx, ny));
					turn.push(count - 1);
				}
			}
		}

		ans_list.push_back(ans);

	}


	

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}


	return 0;

}

Measured memory_bytes: 1592
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

#define FOR(i, s, e) for(i = s; i < e; ++i)
#define FOR_INV(i, s, e) for(i = e - 1; i >= s; --i)

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


using pos = std::pair<LONG, LONG>;

LONG i, j, k;


LONG count(string N, int start_pos, int K){
    int keta = N.size() - start_pos;

    if(K == 1){
        if(keta == 0){
            return 0;
        }
        return 9 * (keta - 1) + (N[start_pos] - '0');
    }
    else if(K == 2){
        if(keta < 2){
            return 0;
        }
        else{
            // top 以外
            LONG sum = 9 * 9 *((keta - 2) * (keta - 1)) / 2;
            sum += (N[start_pos] - '0' - 1) * 9 * (keta - 1);

            ++start_pos;
            while(start_pos < N.size() && N[start_pos] == '0'){
                ++start_pos;
            }

            sum += count(N, start_pos, 1);
            return sum;
        }
    }
    else{
        if(keta < 3){
            return 0;
        }
        else{
            LONG sum = 9 * 9 * 9 * ((keta - 1) * (keta - 2) * (keta - 3)) / 6;
            sum += (N[start_pos] - '0' - 1) * 9 * 9 * ((keta - 2) * (keta - 1)) / 2;

            ++start_pos;
            while(start_pos < N.size() && N[start_pos] == '0'){
                ++start_pos;
            }

            sum += count(N, start_pos, 2);
            return sum;
        }
    }
}


int main(){
    string N;
    LONG K;
    cin >> N >> K;

    cout << count(N, 0, K);

}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		String str=in.nextLine();
		char ch1=str.charAt(0);
		char ch2=str.charAt(2);
		//System.out.println(ch1+"=="+ch2);
		
		if(ch1=='H'){
			if(ch2=='H'){
				System.out.println("H");
			}else if(ch2=='D'){
				System.out.println("D");
			}
		}else if(ch1=='D'){
			if(ch2=='H'){
				System.out.println("D");
			}else if(ch2=='D'){
				System.out.println("H");
			}
		}
	}
}

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

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

Measured memory_bytes: 4364
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

struct Info{
    Info(ll arg_to,ll arg_cost){
        to = arg_to;
        cost = arg_cost;
    }
    bool operator<(const struct Info &arg) const{
            return cost > arg.cost;
    };
    ll to,cost;
};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin>>n>>m;
    cout<<((n-m)*100+1900*m)*modpow(2,m,mod)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	double a;
	double sum;
	int i;
	
	while (~scanf("%lf", &a)){
		sum = a;
		for (i = 2; i <= 10; i++){
			if (i % 2 == 0){
				a *= 2.0;
				sum += a;
			}
			else {
				a /= 3.0;
				sum += a;
			}
		}
		printf("%.8lf\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 652
use proconio::input;

#[allow(unused_imports)]
use std::collections::HashSet;

use std::cmp;


fn main() {
    input! {
        n: usize,
        k: usize,
    }
    solve(n, k);
}


fn prepare(x: usize, p :u64) -> Vec<Vec<u64>> {
    let mut v : Vec<Vec<u64>> = Vec::<Vec<u64>>::with_capacity(x + 1);
    let v0 : Vec<u64> = vec![1; 1];
    v.push(v0);
    for i in 1..x+1 {
        let mut vi : Vec<u64> = vec![0; i+1];
        for j in 0..i+1 {
            vi[j] = 
            if j == 0 || j == i {
                1
            } else {
                (v[i-1][j-1] + v[i-1][j]) % p
            };
        }
        v.push(vi);
        
    }
    return v;
}

fn solve(n: usize, k: usize) {
    let p : u64 = (10u32.pow(9u32) + 7) as u64;

    // 1. Calculate values of combinations
    let x = cmp::max(k-1, n-k+1);
    let c = prepare(x, p);

    // 2. Calculate possible ways
    for i in 1..k+1 {
        let b = c[k-1][i-1];
        let r = if i > n-k+1 { 
            0
        } else {
            c[n-k+1][i]
        };
        let t = b * r % p;
        println!("{}", t);
    }
}


Measured memory_bytes: 17800
#include<bits/stdc++.h>
using namespace std;
int n,dp[1<<17];
int main(){
	cin>>n;
  vector<int>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	reverse(a.begin(),a.end());
  fill(dp,dp+n,1<<30);
	for(int i=0;i<n;i++){
    *upper_bound(dp,dp+n,a[i])=a[i];
	}
	cout<<lower_bound(dp,dp+n,1<<30)-dp<<endl;
 }


Measured memory_bytes: 3996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    int[][] dp = new int[101][10001];
    int N, W;
    int[] v, w;

    void solve() throws IOException {
        N = ni();
        W = ni();
        v = new int[N];
        w = new int[N];
        for (int i = 0; i < N; i++) {
            v[i] = ni();
            w[i] = ni();
        }
        for (int[] a : dp) Arrays.fill(a, -1);

        out.println(calc(0, W));
    }

    int calc(int i, int x) {
        if (dp[i][x] >= 0) return dp[i][x];

        int ans;
        if (i == N) {
            ans = 0;
        } else if (x < w[i]) {
            ans = calc(i + 1, x);
        } else {
            ans = Math.max(calc(i + 1, x), calc(i + 1, x - w[i]) + v[i]);
        }

        return dp[i][x] = ans;
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 29984
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <vector>
#include <stack>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;


const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


 
bool cmp(const string& lhs,const string& rhs)
{
  int lsize=lhs.size();
  int rsize=rhs.size();
  if(lsize!=rsize)
    return lsize<rsize;
  
  for(int i=0;i<lsize;i++)
    if(lhs[i]!=rhs[i])
      return lhs[i]-'0'<rhs[i]-'0';
  return false;
}
 
int main()
{
  const int cost[]={0,2,5,5,4,5,6,3,7,6};
  const string num[]={"0","1","2","3","4","5","6","7","8","9"};
 
  int N,M;
  int A[10]={};
 
  cin >> N >> M;
  for(int i=1;i<=M;i++)
    cin >> A[i];
  
  sort(A+1,A+M+1,greater<int>());
 
  string dp[10010]={};
  for(int i=0;i<=N;i++)
    dp[i]="";
  for(int i=1;i<=N;i++)
  {
    for(int j=1;j<=M;j++)
    {
      if(i-cost[A[j]]<0)
        continue;
      if(dp[i-cost[A[j]]]=="" && i-cost[A[j]]!=0)
        continue;
      string nxt1=dp[i-cost[A[j]]]+num[A[j]];
      string nxt2=num[A[j]]+dp[i-cost[A[j]]];
      if(cmp(dp[i],nxt1))
        dp[i]=nxt1;
      //if(cmp(dp[i],nxt2))
        //dp[i]=nxt2;
    }
  }
  
  cout << dp[N] << endl;
  return 0;
}











Measured memory_bytes: 45568
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;
string Taro,Hanako;
int n,iTaro,iHanako;
int main() {
	cin>>n;
	while(n--)
	{
		cin>>Taro>>Hanako;
		if(Taro<Hanako)	iHanako+=3;
		else if(Taro==Hanako) iTaro++,iHanako++;
		else iTaro+=3;
		
	}
	cout<<iTaro<<" "<<iHanako<<endl;
	return 0;
}



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

int main() {
	int n, m, r[10] = {-1, -1, -1, -1, -1};
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int s, c;
		cin >> s >> c;
		s--;
		if (r[s] == -1 || r[s] == c) {
			r[s] = c;
		} else {
			cout << -1 << endl;
			return 0;
		}
	}
	for(int i = 0; i < n; i++) {
		int k;
		if (r[i] == -1) {
			if (i > 0 || n == 1)
				k = 0;
			else
				k = 1;
		} else {
			k = r[i];
			if (k == 0 && i == 0 && n > 1) {
				cout << -1 << endl;
				return 0;
			}
		}
		cout << k;
	}
	cout << endl;
}


Measured memory_bytes: 256
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
#define wis(x) "[" << #x << " : " << x << "] " << 
typedef long long ll;

const int MAXN = 2e5 + 10, MOD = 1e9 + 7, INF = 1e9 + 5;

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s, t;
	int ans = 0;
	cin >> s >> t;
	int n = s.size();
	for(int i = 0; i < n; i++){
		ans += s[i] != t[i];
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3828
let g=print_newline;;let rec f()=Scanf.scanf"%d %d
"(fun h w->if h<>0&&w<>0then(for i=1to h do for j=1to w do print_char(if i<>1&&i<>h&&j<>w&&j<>1then '.'else '#')done;g()done;f(g())));;f()

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

#define ll long long int
#define ld long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl


int main(){
    ld N,P,M;
    vector<ll> v(100,0);
    int ans = 0;
    ld sum = 0;
    ld temp;
    while(cin>>N>>M>>P,N+M+P){
        ans = 0;
        sum = 0;
        rep(i,N){
            cin>>v[i];
            sum += v[i];
        }
        if( v[M -1] != 0){
            temp = (ld)(((ld)sum * 100) * ( 100.0 - (ld)P) * 0.01) / (ld)v[M-1];
            ans=(int)(temp);
        }
        else{ 
            ans = 0; 
        } 
        
        cout<<ans<<endl; 
    } 
    
    return 0; 
}

Measured memory_bytes: 3192
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    
    String year = S.substring(0, 4);
    String month = S.substring(5, 7);
    String day = S.substring(8);
    
    int yearInt = Integer.parseInt(year);
    int monthInt = Integer.parseInt(month);
    int dayInt = Integer.parseInt(day);
    
    if (yearInt <= 2018) {
      System.out.println("Heisei");
    } else if (yearInt == 2019 && monthInt <= 4) {
      System.out.println("Heisei");
    } else {
      System.out.println("TBD");
    }
  }
}

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

int main() {
    int N;
    cin >> N;
    int x[N], y[N];
    for(int i = 0; i < N; i++){
        cin >> x[i];
        cin >> y[i];
    }

    for(int i = 0; i < N; i++){
        for(int j = N - 1; j >= i + 1; j--){
            if(x[j] < x[j - 1]){
                swap(x[j], x[j - 1]);
                swap(y[j], y[j - 1]);
            }
        }
    }

    for(int i = 0; i < N; i++){
        for(int j = N - 1; j >= i + 1; j--){
            if(x[j] == x[j - 1] && y[j] < y[j - 1]){
                swap(x[j], x[j - 1]);
                swap(y[j], y[j - 1]);
            }
        }
    }

    int xx[N * (N - 1) / 2], yy[N * (N - 1) / 2];
    
    int k = 0;

    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            xx[k] = x[j] - x[i];
            yy[k] = y[j] - y[i];
            k++;
        }
    }

    int count_max = 1;

    for(int i = 0; i < N * (N - 1) / 2 - 1; i++){
        int count = 1;
        for(int j = i + 1; j < N * (N - 1) / 2; j++){
            if(xx[i] == xx[j] && yy[i] == yy[j]){
                count++;
            }
        }
        if(count > count_max){
            count_max = count;
        }
    }

    /*
    for(int i = 0; i < N * (N - 1) / 2; i++){
        cout << xx[i] << " " << yy[i] << endl;
    }
    */
    
    if(N == 1){
        cout << 1 << endl;
    }else{
        cout << N - count_max << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int x,y;
  while(1){
    scanf("%d%d",&x,&y);
    if(x==0 && y==0) break;
    else if(x>y)printf("%d %d\n",y,x);
    else if(x==y||x<y)printf("%d %d\n",x,y);
    
  }
  return 0;
}

Measured memory_bytes: 1028
import java.util.*;

public class Main{
    static int H;
    static int[] A;
    static Scanner sc = new Scanner(System.in);
    static StringBuilder sb  = new StringBuilder();
    static String crlf = System.getProperty("line.separator");

    public static void main(String[] args){
        H = sc.nextInt();
        A = new int[H];
        for(int i=0; i<H; i++){
            A[i] = sc.nextInt();
        }
        for(int i=1; i<=H; i++){
            sb.append("node " + i + ": key = " + A[i-1] + ", ");
            if(i != 1){
                sb.append("parent key = " + A[i/2-1] + ", ");
            }
            if(2*i <= H){
                sb.append("left key = " + A[2*i-1] + ", ");
            }
            if(2*i+1 <= H){
                sb.append("right key = " + A[2*i] + ", ");
            }
            if(i < H){
                sb.append(crlf);
            }
        }
        System.out.println(sb.toString());
    }
}


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

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


#define F first
#define S second

#define ERR 1e-9

#if !ONLINE_JUDGE && !EVAL
    #define dbg_var(x) cerr << #x << ": " << x << "\n";
    #define dbg_iter(x, y) cerr  << #x << ": " << print_iterable(x, y) << "\n";
#else
    #define dbg_var(x)
    #define dbg_iter(x, y)
#endif // ONLINE_JUDGE

template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
    bool first = true;
    stringstream res;
    res << "[ ";
    for(; begin_iter != end_iter; ++begin_iter){
        if(!first) res << ", ";
        first = false;
        res << *begin_iter;
    }
    res << " ]";
    return res.str();
}

void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }

int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }

// constraints
#define MAXN 1000000

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;

    int res = 0, i;
    for(i=1; i<int(s.size()); i++){
        if(s[i] == s[i-1]){
            res++;
            s[i] = (s[i] == '0') ? '1' : '0';
        }
    }

    cout << res << "\n";
}


Measured memory_bytes: 512
N, Y = map(int, input().split())
for x in range(N+1):
    if x * 10000 > Y:
        break

    for y in range(N+1-x):
        z = N - x - y
        if Y == x*10000+y*5000+z*1000:
            print("{} {} {}".format(x, y, z))
            exit()

print("-1 -1 -1")


Measured memory_bytes: 2940
#include<iostream>

int main(){
	int n;
	int a[100];
	int i,j;
	int bf;
	int counter=0;

	std::cin >> n;
	for(i=0;i<n;i++){
		std::cin >> a[i];
	}

	for(i=0;i<n;i++){
		for(j=n-1;j>=i+1;j--){
			if(a[j] < a[j-1]){
				bf = a[j];
				a[j] = a[j-1];
				a[j-1] = bf;
				counter++;
			}
		}
	}

	for(i=0;i<n;i++){
		if(i>0){
			std::cout << " ";
		}
		std::cout << a[i];
	}
	std::cout << "\n";
	std::cout << counter << "\n";

	return (0);
}

Measured memory_bytes: 3080
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int ok=1;
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define RED 3
  

int main(void){
	vector<int> start(26,-1);
	vector<int> goal(26,-1);
	string s,t;
	cin>>s>>t;
    
    for(int i=0; i<s.length();i++){
		if(start[s[i]-'a']!=-1 || goal[t[i]-'a']!=-1){
			if(start[s[i]-'a']!=t[i]-'a' || goal[t[i]-'a']!=s[i]-'a'){
			  std::cout<<"No"<<std::endl;
			  return 0;
			}
		}
		else{
     	start[s[i]-'a']=t[i]-'a';
		goal[t[i]-'a']=s[i]-'a';
	   }
   }
   std::cout<<"Yes"<<std::endl; 
   return 0;
}

Measured memory_bytes: 776
class Solution
    def initialize(target, inputs)
        @target = target
        @inputs = inputs
    end

    def dfs(depth, value, form)
        if depth == @inputs.count
            if value == @target
                return true, form + '=' + @target.to_s
            else
                return false, form
            end
        end

        result1, form1 = dfs depth + 1, value + @inputs[depth],
            (depth > 0 ? form + '+' : '') + @inputs[depth].to_s
        if result1 == true
            return result1, form1
        end

        result2, form2 = dfs depth + 1, value - @inputs[depth],
            (depth > 0 ? form + '-' : '') + @inputs[depth].to_s
        if result2 == true
            return result2, form2
        end

        return false, ''
    end

    def solve
        result, form = dfs 0, 0, ''
        if result == true
            return form
        else
            return 'No solution'
        end
    end
end

def main
    #inputs = '1222'.split('').map(&:to_i)
    inputs = STDIN.gets.chomp.split('').map(&:to_i)
    solution = Solution.new(7, inputs)
    puts solution.solve
end

main


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define ll long long
 
int main() {
	int n, w;
	cin >> n >> w;
	vector<int> sw(n), v(n);
	for(int i = 0;i < n;i++)
		cin >> sw[i] >> v[i];
	ll dp[110][110000] = { 0 };
	for(int i = 0; i < n;i++){
		for (int j = 0; j <= w; j++){
			if (j - sw[i] >= 0)
				dp[i + 1][j] = max(dp[i][j - sw[i]] + v[i], dp[i][j]);
			else
				dp[i + 1][j] = dp[i][j];
		}
	}
	/*for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= w; j++) {
			cout << dp[i][j] << ' ';
		}
		cout << '\n';
	}*/
	cout << dp[n][w];
}

Measured memory_bytes: 94848
from collections import namedtuple
Node = namedtuple('Node', ['parent', 'children'])
   
class my_binary_tree:
    def __init__(self, preorderList, inorderList):
        self.T = {}
        self.reconstruction(preorderList,inorderList)
   
    def reconstruction(self, preorderList, inorderList, parent=-1):
        i = preorderList[0]
        p = parent
        j = inorderList.index(i) 
        llen = len(inorderList[:j])
        rlen = len(inorderList[j+1:])
        if llen > 0: c0 = self.reconstruction(preorderList[1:llen+1],inorderList[:llen],i)
        else       : c0 = -1
        if rlen > 0: c1 = self.reconstruction(preorderList[llen+1:],inorderList[llen+1:],i)
        else       : c1 = -1
        self.T[i] = Node(p,[c0,c1])
        return i
   
    def getRoot(self, i=1):
        p = self.T[i].parent
        if p == -1: return i 
        return self.getRoot(p)
   
    def getPostorderList(self, i, L=[]):
        c0 = self.T[i].children[0]
        c1 = self.T[i].children[1]
        if c0 != -1: self.getPostorderList(c0, L)
        if c1 != -1: self.getPostorderList(c1, L)
        L.append(i)
        return L
   
    
if __name__=='__main__':
    n = int(input())
    preorderList = list(map(int,input().split()))
    inorderList  = list(map(int,input().split()))
    tree = my_binary_tree(preorderList,inorderList)
        
    r = tree.getRoot()
    print(*tree.getPostorderList(r))

Measured memory_bytes: 8164
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
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; }
using namespace std;

ll dp[4][4][4][101];

int main(){
  ll MOD = 1000000007;
  ll N;
  cin >> N;

  dp[3][3][3][0] = 1;
  
  rep(n,N)rep(m1,4)rep(m2,4)rep(m3,4){
    rep(c,4){
      if(dp[m1][m2][m3][n]==0)continue;
      
      if(c==1 and m3==2 and m2==0)continue;
      if(c==2 and m3==1 and m2==0)continue;
      if(c==2 and m3==0 and m2==1)continue;
      if(c==2 and m3==1 and m1==0)continue;
      if(c==2 and m2==1 and m1==0)continue;
      
      dp[m2][m3][c][n+1] = (dp[m2][m3][c][n+1] + dp[m1][m2][m3][n]) % MOD;
    }
  }

  ll ans = 0;
  rep(m1,4)rep(m2,4)rep(m3,4){
    ans = (ans + dp[m1][m2][m3][N]) % MOD;
  }
  
  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
ans = 0
cnt = 0

if K == 0:
    print(N ** 2)
    exit()

for b in range(K+1, N+1, 1):
    cnt += 1
    tmp = (N - (K + cnt - 1)) // b
    ans += cnt * (tmp + 1)
    if (tmp + 1) * b + K <= N:
        ans += N - ((tmp + 1) * b + K) + 1
    ##print(b, ans)

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    map<string,int> m;
    long long ans=0;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        sort(s.begin(),s.end());
        ans+=m[s];
        m[s]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  int sum=0;
  cin>>n;
  vi t(n);
  rep(i,n){
    cin>>t[i];
    sum+=t[i];
  }
  cin>>m;
  vi p(m),x(m);
  rep(i,m)
    cin>>p[i]>>x[i];
  rep(i,m)
    cout<<sum-(t[p[i]-1]-x[i])<<endl;

}


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

template <class T>
using V = vector<T>;

template <class T>
using VV = V<V<T>>;

template <class T>
using P = pair<T, T>;

int main() {
    string S, T;
    cin >> S >> T;
    VV<int> DP(S.size() + 1, V<int>(T.size() + 1, 0));
    for (int i = 0; i < S.size(); ++i) {
        for (int j = 0; j < T.size(); ++j) {
            int m = DP[i][j];
            DP[i + 1][j] = max(DP[i + 1][j], DP[i][j]);
            DP[i][j + 1] = max(DP[i][j + 1], DP[i][j]);
            if (S[i] == T[j]) DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i][j] + 1);
            DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i][j + 1]);
            DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i + 1][j]);
        }
    }
    // 経路復元
    string res = "";
    int y = S.size(), x = T.size();
    while (y > 0 && x > 0) {
        // (y-1, x) -> (y, x)
        if (DP[y][x] == DP[y - 1][x]) {
            --y;
        }
        // (y,x-1) -> (y,x)
        else if (DP[y][x] == DP[y][x - 1]) {
            --x;
        }
        // (y-1, x-1) -> (y, x)
        else {
            res = S[y - 1] + res;
            --y, --x;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 38812
n, a, b = map(int, input().split())
s = input()
a_n = 0
b_n = 0
for i in range(len(s)):
  m = s[i:i+1]
  if(m == "a"):
    if(a_n + b_n < a + b):
      print("Yes")
      a_n += 1
    else:
      print("No")
  elif(m == "b"):
    if((a_n + b_n < a + b) and (b_n < b)):
      print("Yes")
      b_n += 1
    else:
      print("No")
  else:
    print("No")

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,m,k; cin >> n >> m >> k;
  vector<ll> a(n+1), b(m+1);
  rep(i, n) cin >> a[i+1];
  rep(i, n) a[i+1] += a[i];
  rep(i,m) cin >> b[i+1];
  rep(i,m) b[i+1] += b[i];
  int ans =0;
  int ptr = m;
  rep(i, n+1) {
    int num = i;
    int rest = k-a[i];
    while (ptr >=0 && rest < b[ptr]) ptr--;
    if (ptr < 0) break;
    num += ptr;
    chmax(ans, num);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6388
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)
ab = m.times.map { gets.split.map(&:to_i) }

# Disjoint Set Union
class DSU
  def initialize(n = 0)
    # root node: -1 * component size
    # otherwise: parent
    @n = n
    @parent_or_size = Array.new(n, -1)
  end

  def merge(a, b)
    x = leader(a)
    y = leader(b)
    return x if x == y

    x, y = y, x if -@parent_or_size[x] < -@parent_or_size[y]
    @parent_or_size[x] += @parent_or_size[y]
    @parent_or_size[y] = x
    x
  end

  def same(a, b)
    leader(a) == leader(b)
  end

  def leader(a)
    @parent_or_size[a].negative? ? a : (@parent_or_size[a] = leader(@parent_or_size[a]))
  end

  def size(a)
    -@parent_or_size[leader(a)]
  end

  def groups
    leader_buf = Array.new(@n, 0)
    group_size = Array.new(@n, 0)
    (0...@n).each do |i|
      leader_buf[i] = leader(i)
      group_size[leader_buf[i]] += 1
    end
    result = Array.new(@n) { [] }
    (0...@n).each do |i|
      result[leader_buf[i]].push i
    end
    result.delete_if(&:empty?)
    result
  end

  alias root leader
  alias find leader
  alias unite merge
  alias same? same
end

UnionFind        = DSU
UnionFindTree    = DSU
DisjointSetUnion = DSU
u = UnionFind.new(n)

ab.each do |a, b|
  u.merge(a - 1, b - 1)
end
puts u.groups.size - 1


Measured memory_bytes: 27476