akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#pragma warning (disable:4996)
//FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 1e9
#define NM 200005
#define MOD 1000000007
#define FOR(i,n,m) for (int i=(n);i<=(m);i++)
#define si(n) fscanf(in,"%d",&n)
#define sd(n) fscanf(in,"%lld",&n)
typedef long long int ll;

int X, Y, n;
int p[NM][2][2], visit[NM];
vector<pair<int,int> > bd;
inline bool isBoundary(int x, int y){
	return x == 0 || y == 0 || x == X || y == Y;
}
inline int convert(int x, int y){
	if (x == 0 && y >= 0) return y;
	if (x > 0 && y == Y) return x + Y;
	if (y < Y && x == X) return (Y - y) + X + Y;
	return Y + X + Y + (X - x);
}
void input(){
	si(X), si(Y), si(n);
	FOR(i, 1, n){
		FOR(j, 0, 1) FOR(k, 0, 1) si(p[i][j][k]);
		if (isBoundary(p[i][0][0], p[i][0][1]) && isBoundary(p[i][1][0], p[i][1][1])){
			int x = convert(p[i][0][0], p[i][0][1]);
			int y = convert(p[i][1][0], p[i][1][1]);
			if (x > y) swap(x, y);
			bd.push_back({ x, i });
			bd.push_back({ y, i });
		}
	}
	sort(bd.begin(), bd.end());
}
#include <stack>
void pro(){
	int flag = 0;
	stack<int> st;
	for (auto& point : bd){
		if (visit[point.second] == 0){
			st.push(point.second);
			visit[point.second] = 1;
		}
		else{
			if (st.top() != point.second){
				flag = 1; break;
			}
			st.pop();
		}
	}
	fprintf(out, "%s", flag == 0 ? "YES" : "NO");
}
int main(){
	input();
	pro();
	return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int a[6],c1=0,c2=0,c3=0,c4=0;
  for(int i=0;i<6;i++){
    cin>>a[i];
    if(a[i]==1) c1++;
    else if(a[i]==2) c2++;
    else if(a[i]==3) c3++;
    else c4++;
  }
  if((c1>2||c2>2)||(c3>2||c4>2)) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  
}


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

static const int N = 100;

int main() {
    int n, p[N + 1], m[N + 1][N + 1];
    cin >> n;
    for(int i = 1; i <=n; i++) {
        cin >> p[i -1] >> p[i];
    }
    
    for (int i = 1; i <= n; i++) m[i][i] = 0;
    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n -l + 1; i++) {
            int j = i + l -1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j -1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
    
    cout << m[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main()
{
	string cube;
	stack<char> desk;
	int ans = 0;
	cin >> cube;

	int length = cube.length();
	for (int i = 0; i < length; i++)
	{
		if (desk.empty())
		{
			desk.push(cube[i]);
			continue;
		}
		if (desk.top() == cube[i])
		{
			desk.push(cube[i]);
		}
		else
		{
			desk.push(cube[i]);
			desk.pop();
			desk.pop();
			ans += 2;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 512
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;
using namespace __gnu_pbds;

mt19937_64 gen(time(0));

typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//const int mod = 1e9 + 7;

//const int inf = 1e9;
//const int maxn = 1e6 + 66;



signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif
    char c;
    cin >> c;
    if (isupper(c)) cout << 'A';
        else cout << 'a';
    return 0;
}


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
		}
		inv[n-1]=ppow(fact[n-1],MOD-2);
		for(int i=n-2;i>=0;i--){
			inv[i]=(inv[i+1]*(i+1))%MOD;
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};

Fact fac(1e6);
ll sum(int r,int c){
	ll res=0;
	for(int i=1;i<=r+1;i++){
		(res+=fac.nrC(i,c))%=MOD;
	}
	return res;
}
int main(){
	int r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
	ll A=((sum(r2,c2)+MOD-sum(r1-1,c2))%MOD+MOD-sum(r2,c1-1)+sum(r1-1,c1-1))%MOD;
	cout<<A<<endl;
}

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


int main()
{
    /*
    string s;
    cin>>s;
    if(s=="ABC")
    {
        cout<<"ARC"<<endl;
    }
    else
    {
        cout<<"ABC"<<endl;
    }
    */
   /*
    int n,k;
    cin>>n>>k;
    map <int,int> mp;
    for(int i=1;i<=k;i++)
    {
        int d;
        cin>>d;
        for(int j=1;j<=d;j++)
        {
            int a;
            cin>>a;
            mp[a]++;
        }
    }
    int count=0;
    for(int i=1;i<=n;i++)
    {
        if(mp[i]==0)
        {
            count++;
        }
    }

    cout<<count<<endl;
    */
    /*
    int n,m;
    cin>>n>>m;
    vector <pair<bool,ll>> h(n+1);  //良いか悪いか、標高
    for(int i=1;i<=n;i++)
    {
        int height;
        cin>>height;
        h[i].first=true;
        h[i].second=height;
    }

    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        if(h[a].second<=h[b].second)
        {
            h[a].first = false;
        }
        if(h[a].second>=h[b].second)
        {
            h[b].first=false;
        }
    }

    int count=0;

    for(int i=1;i<=n;i++)
    {
        if(h[i].first)
        {
            count++;
        }
    }

    cout<<count<<endl;
    */

    ll A, B, X;
	cin >> X;
	for (ll i = -1000;i < 1000;i++) {
		for (ll j = -1000;j < 1000;j++) {
			if (i * i * i * i * i - j * j * j * j * j == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
    
    return 0;
}

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

#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define SQ(x)           ((x)*(x))
#define LCM(x,y)        (((x)/gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             printf("Ripon\n")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define SC              scanf
#define PF              printf
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
#define sc(x)           scanf("%d",&x)
#define scl(x)          scanf("%lld",&x)
#define scc(x,y)        scanf("%d %d",&x,&y)
#define sccl(x,y)       scanf("%lld %lld",&x,&y)
#define sccc(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define scccl(x,y,z)    scanf("%lld %lld %lld",&x,&y,&z)
//Grid tour
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int kx[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
int ky[] = { -1, 1, 2, 2, 1, -1, -2, -2 };

#define RW freopen("file.txt","r",stdin); //freopen("out.txt","w",stdout);
#define CPPIO ios_base::sync_with_stdio(0);cin.tie(nullptr);

int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;}

struct DATA{};
#define eps 1e-9
#define inf INT_MAX
#define mx 10000009
int arr[123];
void solve(int T) {

    int k;
    string n;
    cin>>n>>k;
    rep(i,1,k){
        int x;
        sc(x);
        arr[x]++;
    }


    bool larger = 0;

    rep(i,0,SZ(n)){

        int x = n[i] - '0';


        if(arr[x]==0){
            cout<<x;
            continue;
        }else if(larger){
            rep(i,0,9){
                if(!arr[i]){
                    cout<<i;
                    break;
                }
            }

        }else{
            bool got = 0;
            rep(i,x,9){
                if(!arr[i]){
                    cout<<i;
                    larger = 1;
                    got = 1;
                    break;
                }
            }
            if(!got){
                rep(i,0,9){
                    if(!arr[i]){
                        cout<<i<<i;
                        larger = 1;
                        break;
                    }
                }

            }
        }
    }

    cout<<'\n';
}

int main(){
    //CPPIO

    int T=1;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <set>
#include <queue>
#include <stack>

using namespace std;

#define maxN 100

int main(){
  int N;
  double v;
  priority_queue<double, vector<double>, greater<double> > que;
  double res=0;

  cin >> N;
  for(int i=0; i<N;i++){
    cin >> v;
    que.push(v);
  }
  while(que.size() != 1){
    double a,b;
    a = que.top();
    que.pop();
    b = que.top();
    que.pop();
    res = (a+b)/2.0;
    que.push(res);
  }

  cout << res << endl;
  return 0;
}


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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

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

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

int main() { 
vector<int> a(5);
  for (int i = 0; i <= 4; i++) {
  cin >> a.at(i);
}

  for (int i=0; i <= 4; i++) {
  if (a.at(i) == 0) cout << i+1 << endl;
  }
  }


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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


vector<lli> G[200001];
lli cost[200001];
lli ans[200001];


void rec(lli cur, lli cur_cost) {
    ans[cur] = cur_cost;
    REP(i, 0, G[cur].size()) {
        rec(G[cur][i], cur_cost + cost[G[cur][i]]);
    }
}

int main() {
    lli n, q;
    cin2(n, q);

    REP(i, 0, n-1) {
        lli a, b;
        cin >> a >> b;
        G[a].push_back(b);
    }
    lli p[q], x[q];
    REP(i, 0, q) {
        cin >> p[i] >> x[i];
        cost[p[i]] += x[i];
    }




    rec(1, cost[1]);
    REPE(i, 1, n) {
        cout << ans[i] << " ";
    }
    cout << endl;


}


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

int main() {
	long long n, a = 0, b = 1;
	map<int , int> s;
	cin >> n;
	for(int i = 2; i <= n; i++){
		a = 0;
		long k = i, r = 2;
		A:
		for(int j = 2; j <= k ; j++){
			if(k % j == 0){
				s[j]++;
				k /= j;
				r = j;
				break;
			}
		}
		//cout << r << endl;
		for(int j = 2; j <= k; j++){
			if(k % j == 0){
				goto A;
			}
		}
		
	}
	
	for(int i = 2; i <= n; i++){
		//cout <<i << " " << s[i] << endl;
		if(s[i] > 0){
			b *= s[i] + 1;
			b = b % 1000000007;
		}
	}
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
 
const int dx[] = {1,1,0,-1,-1,-1,0,1};
const int dy[] = {0,1,1,1,0,-1,-1,-1};
#define INF 1e+8
#define EPS 1e-10
#define PB push_back
#define fi first
#define se second
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
typedef pair<int,int> Pii;
typedef vector<int> vi;
void solve(int y,int x,int h,int w,int stage[52][52]){
    rep(i,8){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx < 0 || nx > w-1 || ny < 0 || ny > h-1 || stage[ny][nx] == 0)continue;
        stage[ny][nx] = 0;
        solve(ny,nx,h,w,stage);
    }
    return ;
}
int main(){
    int w,h;
    while(scanf("%d%d",&w,&h),w){
        int stage[52][52]={{0}};
        int ans = 0;
        rep(i,h){
            rep(j,w){
                scanf("%d",&stage[i][j]);
            }
        }
        rep(i,h){
            rep(j,w){
                if(stage[i][j] == 1){
                    stage[i][j] = 0;
                    solve(i,j,h,w,stage);
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(ll i=(a);i<ll(b);i++)
#define rep(i,b) loop(i,0,b)

typedef int Capacity;
struct Edge {
    int src, dst;
    Capacity cap;
    Edge(int src_, int dst_, Capacity cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct Dinic {
    int n, s, t;
    vector<int> level, vis, iter;
    vector<vector<Capacity>> cap, flow;
    vector<vector<int>> g;
    Capacity inf;
    Dinic(int n)
        : n(n), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
          g(n, vector<int>()), inf(numeric_limits<Capacity>::max()/8){}
    Dinic(const Graph &graph){
        *this = Dinic(graph.size());
        rep(i,n) for(auto &e : graph[i]) addEdge(e.src, e.dst, e.cap);
    }
    void addEdge(int u, int v, Capacity c){
        cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
        g[u].push_back(v); g[v].push_back(u);
    }
    Capacity solve(int s, int t){
        this->t = t, this->s = s;
        Capacity res = 0, aug = 1;
        while(aug > 0){
            levelize();
            vis.assign(n, false); iter.assign(n, 0); aug = 0;
            Capacity tmp = 1;
            nextState = make_tuple(s, inf);
            while(tmp > 0) aug += (tmp = augment(get<0>(nextState), get<1>(nextState)));
            res += aug;
        }
        return res;
    }
    void levelize(){
        level.assign(n, inf); level[s] = 0;
        queue<int> q; q.emplace(s);
        while(q.size()){
            int v = q.front(); q.pop();
            for(const int &d : g[v]){
                if(level[d] <= level[v] + 1 || cap[v][d] - flow[v][d] == 0) continue;
                level[d] = level[v] + 1; q.emplace(d);
            }
        }
    }
    tuple<int,Capacity> nextState;
    Capacity augment(int v, const Capacity &lim){
        // cout << v << endl;
        vis[v] = true;
        if(v == t) return lim;
        for(int &i = iter[v]; i < (int)g[v].size(); i++){
            const int &d = g[v][i];
            if(vis[d] || flow[v][d] == cap[v][d] || level[v] + 1 != level[d]) continue;
            Capacity aug = augment(d, min(lim, cap[v][d] - flow[v][d]));
            flow[v][d] += aug; flow[d][v] -= aug;
            if(aug > 0){
                if(flow[d][v] == 0){
                    get<0>(nextState) = v;
                    get<1>(nextState) = lim - aug;
                }
                return aug;
            }
        }
        return 0;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    Graph g(N);
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        g[a].emplace_back(a,b,c);
    }
    Dinic dinic(g);
    cout << dinic.solve(0,N-1) << endl;
}

Measured memory_bytes: 1356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_169_Multiplication
    {
        // https://atcoder.jp/contests/abc169/tasks/abc169_a

        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            int A = (int)array[0];
            int B = (int)array[1];

            int result = A * B;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

using namespace std;

// MACROS

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

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    string s;
    cin >> s;
    ll n;
    cin >> n;
    vector<char> beg, end;
    FORE(c, s) end.push_back(c);
    bool rev = false;
    FOR(i, n)
    {
        ll x;
        cin >> x;
        if (x == 1) rev = !rev;
        else
        {
            ll a; char b;
            cin >> a >> b;
            if ((a == 1) != rev) beg.pb(b);
            else end.pb(b);
        }
    }
    ll bs = beg.size();
    ll es = end.size();
    if (rev)
    {
        for (ll i = es - 1; i >= 0; i--) cout << end[i];
        FOR(i, bs) cout << beg[i];
    }
    else
    {
        for (ll i = bs - 1; i >= 0; i--) cout << beg[i];
        FOR(i, es) cout << end[i];
    }
    cout << '\n';
}



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

#define each(i, c) for (auto& i : c)

typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll h, a;
  cin >> h >> a;

  ll ans = 0;
  while(true) {
    ++ans;
    h -= a;
    if (h <= 0) break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 764
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll x;
	cin >> x;

	ll a = x / 500;

	ll b = (x - 500 * a) / 5;


	println(1000 * a + 5 * b);
}



Measured memory_bytes: 256
N,Q = map(int,input().split())
G = [[]for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
C = [0]*(N)
for i in range(Q):
    p,x = map(int,input().split())
    C[p-1] += x
from collections import deque
d=deque()
d.append(0)
t = [False]*(N)
t[0] = True
while d:
    a = d.popleft()
    for b in G[a]:
        if not t[b]:
            t[b] = True
            d.append(b)
            C[b] += C[a]
print(*C)


Measured memory_bytes: 56148
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef complex<double> cdouble;
typedef vector<complex<double>> vcd;
typedef vector<vector<complex<double>>> vvcd;

/*******************************************************/

int main() {
  int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
  double m = 0;
  vi ans = { a * 100, 0 };
  Loop(t1, f / (100 * a) + 1) {
    Loop(t2, (f - a * t1 * 100) / (100 * b) + 1) {
      int water = (t1 * a + t2 * b) * 100;
      if (water == 0) continue;
      Loop(t3, (f - water) / c + 1) {
        Loop(t4, (f - water - d * t4) / d + 1) {
          int sugar = t3 * c + t4 * d;
          if (water + sugar <= f) {
            if (water * e >= sugar * 100) {
              double buf = (double)sugar / (water + sugar);
              if (buf > m) {
                ans = { water + sugar, sugar };
                m = buf;
              }
            }
          }
        }
      }
    }
  }
  cout << ans[0] << " " << ans[1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	for (int i = 1; i < 10000; i++) {
		if (i * (i + 1) / 2 == N) {
			cout << "Yes" << endl;
			i++;
			vector < vector<int> >res(i);
			int x = 0;
			for (int j = 0; j < i; j++) {
				for (int k = 0; k < j; k++) {
					x++;
					res[j].push_back(x);
					res[k].push_back(x);
				}
			}
			cout << res.size() << endl;
			for (int j = 0; j < res.size(); j++) {
				cout << res[j].size();
				for (int k = 0; k < res[j].size(); k++) {
					cout << " " << res[j][k];
				}
				cout << endl;
			}

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

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
  int N; cin>>N;
  for(int i = 1; i <= N; i++) {
    int X = (int)(i * 1.08);
    if(X == N) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


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

int main() {
    string str;
    int q;
    cin >> str >> q;

    int i;
    string order;
    for(i = 0; i < q; i++){
        cin >> order;
        int f, s;
        cin >> f >> s;
        if (order == "print") {
            cout << str.substr(f, s - f + 1) << endl;
        }
        else if (order == "reverse") {
            reverse(str.begin() + f, str.begin() + s + 1);
        }
        else if (order == "replace") {
            string sub;
            cin >> sub;
            int j;
            for(j = f; j < s + 1; j++){
                str[j] = (char)sub[j - f];
            }
        }
    }
}



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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int a, b;
    while (cin >> a >> b, a|b) {
        vi n(4);
        unsigned int mi = 1e9;
        FOR(i, 1, sqrt(a)+1) {
            if (a % i != 0) continue;
            FOR(j, 1, sqrt(b)+1) {
                if (b % j != 0) continue;
                n = {i, a/i, j, b/j};
                SORT(n);
                unsigned int m = 0;
                REP(k, 3) {
                    m += (n[k+1] - n[k]) * (n[k+1] - n[k]);
                }
                mi = min(mi, m);
            }
        }
        cout << mi << endl;
    }
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

const int maxn = 5e8;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int read()
{
	int x;
	scanf("%d", &x);
	return x;
}

int n, m, a[30000000], dp[50000000];
bool b[50000000];

bool cmp(int x, int y)
{
	return x > y;
}

int main()
{
	n = read(), m = read();
	for(int i = 1; i <= m; i ++)
	{
		a[i] = read();
	}
	dp[1] = 1, dp[2] = 2;
	for(int i = 1; i <= m; i ++)
	{
		b[a[i]] = true;
	} 
	if(b[1] == true)
	{
		dp[1] = 0;
		dp[2] = 1;
	}
	if(b[2] == true)
	{
		dp[2] = 0;
	}
	for(int i = 3; i <= n; i ++)
	{
		if(b[i])
		{
			dp[i] = 0;
		}
		else
		{
			dp[i] = dp[i - 1] + dp[i - 2];
			dp[i] %= mod;
		}
	}
	cout << (dp[n] + mod) % mod;
	return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>


int main(){
	int N, i, j;
	char *s = (char *)malloc(sizeof(char) * 100001);
	scanf("%s", s);
	for(N = 0; s[N] != '\0'; N++);
	if(s[0] == '0' || s[N - 2] == '0' || s[N - 1] == '1'){
		printf("-1\n");
		return 0;
	}
	for(i = 0; i < N - 1; i++){
		if(s[i] != s[N - 2 - i]){
			printf("-1\n");
			return 0;
		}
	}
	int *t = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		t[i] = 0;
	}
	int *a = (int *)malloc(sizeof(int) * N);
	for(i = 0, j = 0; i <= N / 2; i++){
		if(s[i] == '1'){
			a[j] = i;
			j++;
			t[i] = 1;
		}
	}
	a[j] = N - 1;
	t[N - 1] = 1;
	j++;
	for(i = 1; i < j; i++){
		printf("%d %d\n", a[i - 1] + 1, a[i] + 1);
	}
	int *next = (int *)malloc(sizeof(int) * N);
//	next[N - 1] = a[j - 1];
	for(i = N - 1; i >= 0; i--){
		if(t[i] == 1){
			next[i] = i;
		}
		else{
			next[i] = next[i + 1];
		}
	}
	for(i = 0; i < N; i++){
		if(t[i] == 0){
			printf("%d %d\n", i + 1, next[i] + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
using namespace std;
int main(void){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if(((x+r) > W)||(x < 0)||((y+r) > H)||(y < 0)){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3100
/*input
11 10 9
*/

#include <bits/stdc++.h>

using namespace std;

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

  int64_t a, b, n;
  cin >> a >> b >> n;

  cout << a * min(b - 1, n) / b << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
Node treeSearch(Node,int);
void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for(i = 0;i < n;i++){
    scanf("%s",com);
    if(com[0] == 'f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t != NIL)printf("yes\n");
      else printf("no\n");

    } else if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    } else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com[0] == 'd'){
      printf("in delete\n");
      scanf("%d",&x);
      
    }
  }
  return 0;
}


 


Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL){
    y = x;
    if(z->key < x->key)x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}
void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

Measured memory_bytes: 19364
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<queue>
using namespace std;
int n;
long long tot,k;
struct node{
	int a,b;
}q[100001];
int cmp(node x,node y)
{
	return x.a<y.a;
}
int main()
{
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		q[i].a=a;q[i].b=b;
	}
	sort(q+1,q+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		tot+=q[i].b;
		if(tot>=k){printf("%d",q[i].a);break;
		}
	}
	return 0;
 }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int i = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int i = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int i = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int n; cin >> n;
    for(int i = 1; i <= n; ++i){
        int sq = sqrt(i), ans = 0;
        for(int x = 1; x <= sq; ++x){
            for(int y = 1; y <= x; ++y){
                for(int z = 1; z <= y; ++z){
                    if(x*x+y*y+z*z+x*y+y*z+z*x == i){
                        if(x == y && y == z) ++ans;
                        else if(x == y || y == z || z == x) ans += 3;
                        else ans += 6;
                    }
                }
            }
        }
        cout << ans << endl;
    }


    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for (int i=n;^i;i--)
#define ALL(v) v.begin(),v.end()
// #define int ll 
#define eps 1e-9
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
typedef long long ll;

signed main(void){
	stack<int> s;
	int a;
	while(cin >> a){
		if(a==0){
			cout << s.top() << endl;
			s.pop();
		}
		else 
			s.push(a);
	}
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    vec prime(0);
    prime.push_back(2);
    reps(i,3,277776){
        bool ins = true;
        for(ll p : prime){
            if(i%p == 0) {
                ins = false;
                break;
            }
            if(p*p > i) break;
        }
        if(ins) prime.push_back(i);
    }
    vec ans(0);
    for(ll p : prime){
        if(ans.size() == N) break;
        if(p%5 == 1) ans.push_back(p);
    }
    rep(i,N){
        cout<<ans[i];
        if(i != N-1) cout<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] a = new int[N];
		for(int i=0;i<N;i++) {
			a[i]=in.nextInt();
		}
		Arrays.sort(a);
		int i = N-1;
		int alice =0;
		int bob =0;
		boolean flag = true;
		while(i>=0) {
			if(flag) {
				alice+=a[i];
				flag = false;
			}else {
				bob += a[i];
				flag = true;
			}
			i--;

		}
	System.out.println(alice-bob);
	}
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
    cin>>n;
    ll a = 0;
    for(ll i=1; i<=n; i++)
        if(i%3 && i%5)
            a+=i;
    cout<<a;
    
    
	return 0;
}

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

using namespace std;

int A[100006];
bool mk[100006];

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

	int N, M; cin >> N >> M;
	fill(A, A + N + 1, 1);
	mk[1]=true;
	while(M--){
		int a, b; cin >> a >> b;
		A[a]--;
		A[b]++;
		if(mk[a])mk[b]=true;
		if(A[a] <= 0)mk[a]=false;

	}
	int cont =0;
	for(int i=1; i <= N; i++)
		if(mk[i])cont++;
	cout << cont << '\n';
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
int main(void){

int c,d,e,f;
int n,m,l,i,j,k;
int a[101][101]={};
int b[101][101]={};
long g[101][101]={};

scanf("%d %d %d",&n,&m,&l);

for(c=1;c<=n;c++){
	for(d=1;d<=m;d++){
	scanf("%d",&e);
	a[c][d]=e;
	//printf("*%d",a[c][d]);
	}
}

for(c=1;c<=m;c++){
	for(d=1;d<=l;d++){
	scanf("%d",&e);
	b[c][d]=e;
	//printf("*%d",b[c][d]);
	}
}
/*////////////////////////////////////////
for(c=1;c<=n;c++){
	for(d=1;d<=m;d++){
	printf("a[%d][%d]=%d\n",c,d,a[c][d]);
	}
}
for(c=1;c<=m;c++){
	for(d=1;d<=l;d++){
	printf("b[%d][%d]=%d\n",c,d,b[c][d]);
	}
}
///////////////////////////////////////*/
for(k=1;k<=n;k++){
	for(j=1;j<=l;j++){
		for(i=1;i<=m;i++){
		g[k][j]+=a[k][i]*b[i][j];
		}
	}
}

for(c=1;c<=n;c++){
	for(d=1;d<=l;d++){
	printf("%ld",g[c][d]);
	if(d<l){printf(" ");}
	}
	printf("\n");
}

return 0;
}

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

using namespace std;

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	vector<string> v(1000);
	for (int i = 0; i<10; i++){
			for (int j = 0; j<10; j++){
				for (int k = 0; k<10; k++){
					int ind = i*pow(10, 2) + j*pow(10, 1) + k;
					v[ind] = to_string(i) + to_string(j) + to_string(k);
				}
		}
	}

	int ans=0;
	for (int i = 0; i<1000; i++){
		int ct =0, point = 0;
		string PIN = v[i];
		for (int j=0; j<N; j++){
			if( PIN[point] == S[j]){
				ct++;
				point++;
			}
		}
		if (ct > 2){
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll X,N; cin>>X>>N;
  map<ll,bool> p;
  rep(i,N)
  {
    ll hoge; cin>>hoge;
    p[hoge]=true;
  }
  rep(i,1000)
  {
    if(!(p.count(X-i)))
    {
      cout<<X-i<<endl; return 0;
    }
    if(!(p.count(X+i)))
    {
      cout<<X+i<<endl; return 0;
    }
  }  
  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(vodo)
{
	int n,a,b,c,d,x,y,s,m,xam,yam;
	scanf("%d",&n);
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	x=n/a;
	y=n/c;
	xam=n%a;
	yam=n%c;
	if(xam!=0){
		x=x+1;
	}
	if(yam!=0){
		y=y+1;
	}
	s=x*b;
	m=y*d;
	if(s<m){
		printf("%d\n",s);
	}
	else{
		printf("%d\n",m);
	}
	return 0;
}


Measured memory_bytes: 2144
<?php
define("MOD", 10 ** 9 + 7);
list($n) = ints();
$a = ints();
for ($i = 0; $i < $n; ++$i) {
    if (isset($c[$a[$i]])) $c[$a[$i]]++;
    else $c[$a[$i]] = 1;
}
if ($n % 2 && $c[0] !== 1) exit('0');
for ($i = 0; $i < intdiv($n, 2); ++$i) {
    $k = abs($i - ($n - $i - 1));
    if ($c[$k] !== 2) exit('0');
}
echo modPow(2, intdiv($n, 2));
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}


Measured memory_bytes: 16884
N,M,R = map(int,input().split())
r = list(map(int,input().split()))
INF = 10**18
d = [[INF for i in range(N)] for j in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c

for i in range(N):
    d[i][i] = 0

# ワーシャルフロイド
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

import itertools
ans = INF
for v in itertools.permutations(r,R):
    anss = 0
    for i in range(R-1):
        anss += d[v[i]-1][v[i+1]-1]
    ans = min(ans,anss)
print(ans)

Measured memory_bytes: 47192
#include<iostream>
#include<vector>
using namespace std;
void numbering(int v, int k, vector<vector<int>>const&graph, vector<int>&id) {
	
	id[v] = k;
	//v????????????????????????
	//id??????????????°?????????????????????
	//k????????????????????????
	for (auto to : graph[v]) {
		//for(int i=0;i<graph[v].size();++i)
		
		if (id[to] != -1) {
			continue;
		}
		numbering(to, k, graph, id);
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>>graph(n);
	for (int i = 0;i < m;++i) {
		int u, v;
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	vector<int>id(n, -1);
	for (int i = 0;i < n;i++) {
		if (id[i] == -1) {
			numbering(i, i, graph, id);
			//numbering(?????????????????????,?????????????????????,graph,id)
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int u, v;
		cin >> u >> v;
		if (id[u] == id[v]) {
			cout <<"yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

}

Measured memory_bytes: 13336
s = int(input())
a = []
a.append(s)
while(True):
    if a[-1]%2 == 0:
        a.append(a[-1]//2)
    else:
        a.append(a[-1]*3 + 1)
    
    if len(set(a)) != len(a):
        print(len(a))
        break

Measured memory_bytes: 3064
import java.util.*

private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

private inline fun <T> T.also(block: (T) -> Unit): T { block(this); return this }

private inline fun <T, R> Collection<T>.scanIndexed(initial: R, operation: (Int, R, T) -> R): List<R> {
    val result = ArrayList<R>(size)
    var prevResult = initial
    forEachIndexed { index, element ->
        val elementResult = operation(index, prevResult, element)
        result.add(elementResult)
        prevResult = elementResult
    }
    return result
}

private inline fun <T> Collection<T>.scanIndexed1(operation: (Int, T, T) -> T): List<T>
        = drop(1).scanIndexed(first(), operation)

private inline fun <T, R> Collection<T>.scan(initial: R, operation: (R, T) -> R): List<R>
        = scanIndexed(initial) {i, list, elem -> operation(list, elem) }

fun main(args: Array<String>) {
    val N = readInts()[0]
    val S = readStrings()[0]
    val initial = S.count { it == 'E' }
    var prevW = false
    val counts = S.toList().scan(initial) { count, direction ->
        when {
            prevW && direction == 'E' -> count
            prevW && direction == 'W' -> count + 1
            !prevW && direction== 'E' -> count - 1
            !prevW && direction== 'W' -> count
            else -> throw Exception()
        }.also {
            prevW = direction == 'W'
        }
    }
    println(counts.min()!!)
}

Measured memory_bytes: 52260
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
const int MAXN = 87;
int a[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    int mn = 0, mx = 0;
    for (int i = 1; i <= N; i++) {
        scanf("%d", &a[i]);
        if (a[i] <= a[mn]) mn = i;
        if (a[i] >= a[mx]) mx = i;
    }
    vector<pii> ans;
    if (a[mx] > 0 && a[mn] < 0) {
       int tg_x = mx;
       if (a[mn] * -1 > a[mx]) tg_x = mn;
       for (int i = 1; i <= N; i++) {
           ans.push_back(make_pair(tg_x, i));
           a[i] += a[tg_x];
       }
    }
    int md = 1;
    for (int i = 1; i <= N; i++) {
        if (a[i] < 0) md = 0;
    }
    if (md == 1) {
       for (int i = 1; i < N; i++)
           ans.push_back(make_pair(i, i + 1));
    } else {
       for (int i = N; i > 1; i--)
           ans.push_back(make_pair(i, i - 1));
    }
    printf("%d\n", (int)ans.size());
    for (auto i : ans) printf("%d %d\n", i.first, i.second);
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second

signed main(){
    int r;
    cin>>r;
    cout<<3*r*r<<endl;
    return 0;
}


Measured memory_bytes: 764
#include<queue>
#include<cstdio>

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

using namespace std;

struct Stat{
	int x;
	int id; // 0: pick a carrot, 1: speed down, 2: other
	bool operator<(const Stat &S)const{ return x>S.x; }
};

int main(){
	int n,k,t,u,v,l; scanf("%d%d%d%d%d%d",&n,&k,&t,&u,&v,&l);

	priority_queue<Stat> pq;
	rep(i,n){
		int d; scanf("%d",&d);
		pq.push((Stat){d,0});
	}
	pq.push((Stat){l,0});

	double time=0;
	int x=0,x_slow=-1,n_carrot=0; // »ÝÌÊu, x­ÈéÊu, ÁÄ¢éjWÌ{
	while(!pq.empty()){
		Stat S=pq.top(); pq.pop();

		time+=(double)(S.x-x)/(S.x<=x_slow?v:u);
		x=S.x;
		if(x==l) break;

		if(S.id==0){
			if(x<=x_slow && n_carrot<k) n_carrot++;
			else{ // immediately eat
				x_slow=x+v*t;
				pq.push((Stat){x_slow,1});
			}
		}
		else{ // S.id==1
			if(x!=x_slow) continue;
			if(n_carrot>0){
				x_slow=x+v*t;
				pq.push((Stat){x_slow,1});
				n_carrot--;
			}
		}
	}

	printf("%.9f\n",time);

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n=5;
ll a[6];
int main(){
	ios::sync_with_stdio(false);
	ll mx=0;
	for(int i=1; i<=n ;i++){
		cin >> a[i];
		
	}
	ll k;cin >> k;
	if(a[5]-a[1]>k) cout << ":(\n";
	else cout << "Yay!";
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    string s; cin>>s;
    int n = s.size();

    reverse(s.begin(), s.end());
    s += '0';

    vector<vector<int>> dp(n+2, vector<int>(2, inf));
    dp[0][0] = 0;

    for(int i=0; i<=n; i++){
        int cur = s[i] - '0';

        // 繰り上げる
        chmin(dp[i+1][1], min(dp[i][1] + 10 - (cur + 1), dp[i][0] + 10 - cur));

        // 繰り上げない
        chmin(dp[i+1][0], min(dp[i][1] + (cur + 1), dp[i][0] + cur));
    }

    cout << chmin(dp[n][0], dp[n+1][0]) << endl;

    return 0;
}

Measured memory_bytes: 55964