akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int n, s, pos[N], num[N];
signed main() {
	scanf("%lld%lld", &n, &s);
	for (int i = 1; i <= n; ++i) scanf("%lld%lld", pos + i, num + i);
	int lp = 1, rp = n, ans = 0;
	while (1) {
		if (s > pos[rp]) { ans += s - pos[lp]; break; }
		if (s < pos[lp]) { ans += pos[rp] - s; break; }
		ans += pos[rp] - pos[lp]; 
		if (num[lp] >= num[rp]) { 
			while (lp < rp && num[lp] >= num[rp]) num[lp] += num[rp--];
		} else {
			while (lp < rp && num[lp] < num[rp]) num[rp] += num[lp++];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


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

#define int long long
int n, k;
int W[100000+1];
int v[100000+1];

int dp[100000+1][100];
int ant(int w, int i)
{
    if(w<0 || i<0) return 0;
    if(dp[w][i]!=-1)   return dp[w][i];
    dp[w][i]=0;
    if(W[i] > w){dp[w][i]= ant(w,i-1); return dp[w][i];}
    dp[w][i]= max(ant(w-W[i], i-1)+ v[i], ant(w, i-1));
    return dp[w][i];
}

signed main()
{
    IOS
    cin >> n >> k;
    REP(i, n)
        cin >> W[i] >> v[i];
    REP(i,k+1)
        REP(j,n)
        dp[i][j]=-1;
    cout << ant(k, n-1);
    
}

Measured memory_bytes: 78336
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N; cin >> N;
    vvl A(N, vl(N));
    ll sum = 0;
    REP(i, N) {
        REP(j, N) {
            cin >> A[i][j];
            sum += A[i][j];
        }
    }
    sum /= 2;

    bool ok = true;
    REP(i,N){
        FOR(j,i+1,N){
            bool equal = false;
            REP(k,N){
                if (k == i || k == j) continue;

                if (A[i][k] + A[k][j] < A[i][j]) {
                    ok = false;
                    break;
                } else if (A[i][k] + A[k][j] == A[i][j]) {
                    equal = true;
                }
            }            
            if (!ok) break;
            if (equal) sum -= A[i][j];
        }
        if (!ok) break;
    }

    ll ans = ok ? sum : -1;
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

namespace flow {

struct edge {
  int to, cap, rev;
  edge(int t, int c, int r): to(t), cap(c), rev(r) {}
};

class dinic {

private:

  vector<vector<edge>> G;
  vector<int> level;
  vector<int> iter;

  void bfs(int s) {
    fill(level.begin(), level.end(), -1);
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while(!q.empty()) {
      int v = q.front(); q.pop();
      for(auto& e: G[v]) {
        if(e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          q.push(e.to);
        }
      }
    }
  }

  int dfs(int v, int t, int flow) {
    if(v == t) return flow;
    for(int& i = iter[v]; i < G[v].size(); i++) {
      auto& e = G[v][i];
      if(e.cap > 0 && level[v] < level[e.to]) {
        if(int d = dfs(e.to, t, min(flow, e.cap))) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

public:

  dinic(int N) : G(N), level(N), iter(N) {}

  void add_edge(int from, int to, int cap) {
    G[from].emplace_back(to, cap, G[to].size());
    G[to].emplace_back(from, 0, G[from].size()-1);
  }

  int max_flow(int s, int t) {
    int flow = 0;
    for(;;) {
      bfs(s);
      if(level[t] < 0) return flow;
      fill(iter.begin(), iter.end(), 0);
      int f;
      while((f = dfs(s, t, inf)) > 0) {
        flow += f;
      }
    }
  }

};
}

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

int main() {

  int TC; cin >> TC;
  rep(tc, TC) {

    int W, H; cin >> W >> H;

    vector<vector<int>> G(H);
    rep(i, H) G[i].resize(W);
    int total = 0;
    rep(i, H) rep(j, W) cin >> G[i][j], total += G[i][j];

    flow::dinic dn(H * W + 2);
    const int SRC = H * W, SINK = H * W + 1;
    rep(i, H) rep(j, W) {
      if((i + j) % 2) {
        dn.add_edge(SRC, i * W + j, G[i][j]);
        rep(k, 4) {
          int ni = i + dy[k], nj = j + dx[k];
          if(!in_range(ni, nj, H, W)) continue;
          dn.add_edge(i * W + j, ni * W + nj, inf);
        }
      } else {
        dn.add_edge(i * W + j, SINK, G[i][j]);
      }
    }

    cout << "Case " << tc + 1 << ": " << total - dn.max_flow(SRC, SINK) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3104
import java.util.*;
import java.math.*;

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

class Solver {

    private List<int[]> prime_factorize(int N) {
        List<int[]> res = new ArrayList<int[]>();
        for (int a = 2; a * a <= N; a++) {
            if (N % a != 0) continue;
            int ex = 0;

            while (N % a == 0) {
                ++ex;
                N /= a;
            }

            res.add(new int[]{a, ex});
        }

        if (N != 1) res.add(new int[]{N, 1});
        return res;
    }

    private boolean check(List<int []> list) {
        for (int[] a : list) {
            if (a[1] % 2 != 0) {
                return false;
            }
        }
        return true;
    }

    private int dist2(int[][] X, int N, int D, int i, int j) {
        int sum = 0;
        for (int k = 0; k < D; k++) {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        }
        return sum;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] X = new int[N][D];
        int[][] M = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = sc.nextInt();
            }
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(prime_factorize(s))) {
                        cnt++;
                    } else {
                    }
                }
            }
        }
        System.out.println(cnt);

        return;
    }

}

Measured memory_bytes: 22996
// AOJ 2155: Infected Computer
// 2017.10.20 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { int t, s, d; } T;
T tbl[20002];
char f[20002];

int cmp(T *a, T *b) { return a->t - b->t; }

char buf[102], *p;
int getInt(void)
{
	int n = 0;
	if (*p == ' ') p++;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}
int main()
{
	int n, m, i, ans;
	register T *t;

	while (fgets(p=buf, 100, stdin) && *p != '0') {
		n = getInt(), m = getInt();
		memset(f, 0, n+1);
		for (t = tbl, i = m; i--; t++) {
			fgets(p=buf, 100, stdin);
			t->t = getInt(), t->s = getInt(), t->d = getInt();
		}
		qsort(tbl, m, sizeof(T), cmp);
		for (f[1] = 1, t = tbl, i = m; i--; t++) f[t->d] |= f[t->s];
		for (ans = 0, i = 1; i <= n; i++) ans += f[i];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long n,x,y,s;
	s=0;
	cin>>n;
	for (int i=0;n>i;i++) {
		cin>>x;
		y=0;
		while (x%2==0){
			y++;
			x=x/2;
		}
		if (i==0){
			s=y;
		}
		else{
			if(s>y){
				s=y;
			}
		}

	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
n = int(input())
hs = list(map(int, input().split()))
hs.insert(0, 0)
hs.append(0)
res = lh0 = lh1 = hs[0]
for h in hs:
    if lh0 <= lh1 > h:
        res += lh1
    elif lh0 > lh1 <= h:
        res -= lh1
    lh0, lh1 = lh1, h

print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main(){
	ll n, k;
    cin >> n >> k;
    cout << min(n % k, k - (n % k));
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int c[3][3],a;
int main(){
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
cin >> c[i][j];
a=max(a,c[i][j]);
}
for(int i1=0;i1<=a;i1++)
for(int i2=0;i2<=a;i2++)
for(int i3=0;i3<=a;i3++)
for(int i4=0;i4<=a;i4++){
if(i1+i4==c[0][0] and i2+i4==c[1][0] and i3+i4==c[2][0]){
for(int i5=0;i5<=a;i5++){
if(i1+i5==c[0][1] and i2+i5==c[1][1] and i3+i5==c[2][1]){
for(int i6=0;i6<=a;i6++){
if(i1+i6==c[0][2] and i2+i6==c[1][2] and i3+i6==c[2][2])
{
cout << "Yes";
return 0;
}}}}}}
cout << "No";
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;
const LL MOD = 1e9 + 7;
const int MAX_C = 2100;
LL com[MAX_C][MAX_C];
void calc_com() {
    memset(com, 0, sizeof(com));
    com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i) {
        com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j) {
            com[i][j] = (com[i-1][j-1] + com[i-1][j]) % MOD;
        }
    }
}

int main() {
    int n, k;
    cin >> n >> k;
    calc_com();
    loop(i, 1, k + 1) {
        cout << (com[k - 1][i - 1] * com[n - k + 1][i]) % MOD << endl;
    }
    return 0;
}


Measured memory_bytes: 34688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    int A[N], x[N][N];
    fill(x[0], x[N], -1);
    rep(i, N){
        cin >> A[i];
        rep(j, A[i]){
            int a, b;
            cin >> a >> b; a--;
            x[i][a] = b;
        }
    }
    int ans = 0;
    rep(i, 1<<N){
        bool able = true;
        rep(j, N){
            if(!(i & (1<<j))) continue;
            rep(k, N){
                if(x[j][k] == -1) continue;
                int l = x[j][k];
                int m = (i >> k) & 1;
                if(m != l) able = false;
            }
        }
        if(able) chmax(ans, __builtin_popcount(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N,A,B,C,D=map(int,input().split())
if N%A==0:
    N1=N//A
else:
    N1=N//A+1

if N%C==0:
    N2=N//C
else:
    N2=N//C+1

if (N1*B)>=(N2*D):
    print(N2*D)
else:
    print(N1*B)


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100005;
vector<int> v[maxn];

int dfs(int root, int fa) {
    int ret = 0;
    for (int i = 0;i < v[root].size();i++) {
        int to = v[root][i];
        if (to == fa) continue;

        ret ^= 1 + dfs(to, root);
    }
    return ret;

}
int main() {
    
    int n;
    cin >> n;
    for (int i = 1, xi, yi;i < n;i++) {
        scanf("%d %d", &xi, &yi);
        v[xi].push_back(yi);
        v[yi].push_back(xi);
    }
    if (dfs(1, 0) != 0) {
        printf("Alice\n");
    }
    else {
        printf("Bob\n");
    }
    return 0;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    string w[n];
    rep(n) cin >> w[i];

    rep(n){
        if(i && w[i][0] != w[i-1][w[i-1].length()-1]){
            cout << "No" << endl;
            return 0;
        }
        repp(j, i){
            if(w[j] == w[i]){
                cout << "No" << endl;
                return 0;
            }
        }
    }

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


Measured memory_bytes: 256
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

N = 0
x = 0
y = 0
flag = False
res = []
tmp_x = 0
tmp_y = 0

for i in range(H*W):
    if flag:
        res.append([tmp_x + 1, tmp_y + 1, x + 1, y + 1])
        A[y][x] += 1
        N += 1
        
    if A[y][x]%2 == 1:
        flag = True
    else:
        flag = False
        
    tmp_x = x
    tmp_y = y
    if x == W - 1 and y%2 == 0:
        y += 1
        
    elif x == 0 and y%2 == 1:
        y += 1
        
    elif y%2 == 0:
        x += 1
    else:
        x -= 1

            
print(N)

for r in res:
    print(r[1], r[0], r[3], r[2])

Measured memory_bytes: 30264
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n, t, sum = 0;
	int a, gen = 0;
	vector<int>list1, list2;
	cin >> n >> t;

	//list2.push_back(0);

	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		list1.push_back(num);
		list2.push_back(num + t);
	}

	sum = t;

	for (int i = 1; i < n; i++) {
		if (list2[i-1] > list1[i]) {
			sum -= abs(list2[i - 1] - list1[i]);
			sum += t;
		}
		else {
			sum += t;
		}
	}

	////cin >> a;
	//sum = t;
	//gen = t;

	//for (int i = 0; i < n; i++) {
	//	int num;
	//	cin >> num;
	//	if (num <= gen) {
	//		sum -= abs(gen - num);
	//		sum += t;
	//		gen = sum;
	//	}
	//	else if (num > gen) {
	//		sum += t;
	//		gen = sum;
	//	}
	//}

	cout << sum << endl;






	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,k;cin>>n>>k;
    vin v(n);rep(i,n)cin>>v[i];
    int sum,tmp;int m=0;
    rep(i,k+1){//i回取り出す→最大でmin(i,k-i)個しまう→l個しまうとするとi-l個残る
        rep(j,i+1){//左端からj個取り出す
            vin jew;
            rep(l,min(j,n))jew.push_back(v[l]);
            for(int l=n-1;l>=max(j,n-i+j);l--)jew.push_back(v[l]);
            sort(all(jew),greater<int>());
            tmp=jew.size();
            rep(l,min(i,k-i)+1){
                sum=0;
                rep(h,min(i-l,tmp))sum+=jew[h];
                m=max(m,sum);
            }
        }
    }
    cout<<m<<endl;
}

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

ll s[10];
char c[10];

int main(){
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)cin>>s[i]>>c[i];
	
	if(n==1){
		for(int i=0;i<10;i++){
			string x=to_string(i);
			bool f=1;
			for(int j=0;j<m;j++){
				if(x[s[j]-1]!=c[j])f=0;
			}
			if(f){
				cout<<i;
				return 0;
			}
		}
	}else{
		ll num=pow(10,n-1);
		for(int i=num;i<num*10;i++){
			string x=to_string(i);
			bool f=1;
			for(int j=0;j<m;j++){
				if(s[j]==1&&c[j]==0)f=0;
				if(x[s[j]-1]!=c[j])f=0;
			}
			if(f){
				cout<<i;
				return 0;
			}
		}
	}
	cout<<-1;
	return 0;
}


Measured memory_bytes: 256
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

import System.IO

------------------------------------------

data Tr = Em | Br Tr Tr
  deriving (Show, Eq)

parse :: String -> (Tr, String)
parse "" = (Em, "")
parse ('(':xs) =
  let (lt, ',':xs') = parse xs
      (rt, ')':xs'') = parse xs' in (Br lt rt, xs'')
parse xs = (Em, xs)

unparse :: Tr -> String
unparse Em = ""
unparse (Br lt rt) = "(" ++ unparse lt ++ "," ++ unparse rt ++ ")"

uni :: Tr -> Tr -> Tr
uni Em Em = Em
uni lt Em = lt
uni Em rt = rt
uni (Br llt lrt) (Br rlt rrt) = Br (uni llt rlt) (uni lrt rrt)

intersec :: Tr -> Tr -> Tr
intersec Em Em = Em
intersec lt Em = Em
intersec Em rt = Em
intersec (Br llt lrt) (Br rlt rrt) = Br (intersec llt rlt) (intersec lrt rrt)

main :: IO ()
main = do
  eof <- isEOF
  if eof then return ()
  else do
  [cmd, xs, ys] <- words <$> getLine
  let (xt, _) = parse xs
      (yt, _) = parse ys
      ans = if cmd == "i" then intersec xt yt else uni xt yt
  putStrLn $ unparse ans
  main

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"

Measured memory_bytes: 4148
#abc081 b-shift only
n=int(input())
a=list(map(int,input().split()))
ans=0
flag=True
while True:
    for x in range(len(a)):
        if(a[x]%2==0):
            a[x]=int(a[x]/2)
        else:
            flag=False
    if flag==False:
        break
    ans+=1
print(ans)

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


/********************************************************************/
#define M1 1000000007	//Standard primes used in modulo operations
#define M2 998244353
#define PI 3.1415926536
const int INF = INT_MAX;
#define ll long long
#define pll pair<ll,ll>
#define REP(i, a, b) for(ll i=a;i<b;i++)
#define REPR(i, a, b) for(ll i=b-1;i>=a;i--)
#define forr(i, n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define space ' '
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl

void FAST() {	//FAST Input Output, DONT use both scnaf,printf / cin,cout , Use any ONE system
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll gcd(ll x, ll y) {	//returns gcd of two long long ints
	if (x == 0) return y;
	return gcd(y % x, x);
}

ll powM(ll x, ll y, ll m) {	//returns (a^b)%m ( ^ is exponent )
	ll ans = 1, r = 1;
	x %= m;
	while (r > 0 && r <= y)
	{
		if (r & y)
		{
			ans *= x;
			ans %= m;
		}
		r <<= 1;
		x *= x;
		x %= m;
	}
	return ans;
}

map<long long, long long> factorize(long long n) {	//returns map containing factor and multiplicity, Eg: 60 = {{2,2},{3,1},{5,1}}
	map<long long, long long> ans;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ans[i]++;
			n /= i;
		}
	}
	if (n > 1) {
		ans[n]++;
		n = 1;
	}
	return ans;
}
/* **********END OF TEMPLATE*********** */

int main() {
	/*  Codeforces #595 Div.3 :)*/
	FAST();
	int n,x,t;
	cin>>n>>x>>t;
	if(n%x==0){
		cout<<t*(n/x)<<endl;
	}
	else{
		cout<<t*((n/x)+1)<<endl;
	}
	}

		


Measured memory_bytes: 3660
/*  ex9_2
    kosaq   */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100001

typedef struct node{
    char elem;
    struct node *next;
} node;//リストのノード（スタック内）の定義

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new -> elem = elem;
    new ->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp -> elem;
    *first = tmp -> next;
    //取り出したノードのメモリを確保
    free(tmp);
    return elem;
}

int main(void){
    char cube_input[SIZE];//入力する配列を定義
    int count = 0;//取り除く個数を定義
    scanf("%s", cube_input);
    //最初のノードはNULL
    node *first = NULL;

    for(int i = 0; i < strlen(cube_input); i++){
        if(first == NULL || cube_input[i] == first -> elem){
            push(&first, cube_input[i]);
        }//NULLのとき、ノードをスタックに追加する。要素が一致するときはノードをスタックに追加する。
        else{
            pop(&first);//異なる場合は取り除き、カウントを２増やす
            count = count + 2;
        }
    }

    printf("%d\n", count);//答えを出力
    return 0;
}

Measured memory_bytes: 4896
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,a,b,c;
    cin>>N;
    a = N/100;
    b = (N/10)-10*(N/100);
    c = N%(N/10);
    if( a == 7 || b == 7 || c == 7 )
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3624
#include <cstdio>

int n;
int x[1000000];
int ans[1000000];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &x[i]);
	}
	if (n & 1)
	{
		for (int i = 1; i <= n; i++)
		{
			if (i & 1)
			{
				ans[(n + 1) / 2 - (i + 1) / 2 + 1] = x[i];
			}
			else
			{
				ans[(n + 1) / 2 + i / 2] = x[i];
			}
		}
	}
	else
	{
		for (int i = 1; i <= n; i++)
		{
			if (i & 1)
			{
				ans[n / 2 + (i + 1) / 2] = x[i];
			}
			else
			{
				ans[n / 2 - i / 2 + 1] = x[i];
			}
		}
	}
	for (int i = 1; i < n; i++)
	{
		printf("%d ", ans[i]);
	}
	printf("%d\n", ans[n]);
	return 0;
}


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

using namespace std;
const int N = 1e5+100;
long long dp[N];
struct node{
	long long d,w;
}s[N];
bool operator<(node a,node b){
	return a.w<b.w;
}
bool cmp(node a,node b){
	return a.d<b.d;
}
int main(){
	long long n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>s[i].d>>s[i].w;
	}
	sort(s+1,s+n+1,cmp);
	priority_queue<node> q;
	long long ans=0;
	int now=1;
	for(int i=m;i>=1;i--){
		while(s[now].d<=m-i+1&&now<=n){
			q.push(s[now]);
			now++;
		}
		if(q.empty()) continue;
		ans+=q.top().w;
		q.pop();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3956
A,B,C = map(int, input().split())

five = 0
seven = 0
if A==5:
  five += 1
elif A==7:
  seven += 1
if B==5:
  five += 1
elif B==7:
  seven += 1
if C==5:
  five += 1
elif C==7:
  seven += 1
if five == 2 and seven == 1:
  print("YES")
else:
  print("NO")

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

int main(){
  long long a;
  double b;
  cin >> a >> b;
  long long nb = (long long)(100.0*b+0.2);
  long long ans = (a*nb)/100;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3720
from collections import Counter
a,b=list(map(int,input().split()))
m=list(map(int,input().split()))
#m.sort()
c=[]
for i in range(b):
    c.append(abs(m[i]-a))
c=Counter(c)

if b>0:
    i=0
    while i<=b:
        if i not in c:
            print(a-i)
            break
        
        elif c[i]<2 and i!=0:
            if a-i in m:
                print(i+a)
            else:
                print(-i+a)
            break
        i+=1
else:
    print(a)

     
    

Measured memory_bytes: 9444
/*input
10 4
40 10 20 70 80 10 20 70 80 60
*/
#include<bits/stdc++.h>
using namespace std;

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t;cin>>t;while(t--)
#define X first
#define Y second
#define pb push_back
#define all(s) s.begin(),s.end()

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

const int MOD = 1e9+7;

void solve(){
    int n,k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i=0;i<n;i++) cin >> arr[i];

    int dp[n];
    // memset(dp,INT_MAX,sizeof dp);
    dp[0] = 0;

    for(int i=1;i<n;i++){
        dp[i] = INT_MAX;
        for(int j=i-1;j>=max(0,i-k);j--){
            // cout << i << " ";
            dp[i] = min(dp[i],dp[j]+abs(arr[i]-arr[j]));
        }
        // cout << dp[i] << "\n";
    }
    cout << dp[n-1];
}

int main(){
    FIN;   
    // test
    solve();
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int X;
  vector<int> D(1000);
  vector<int> L(1000);

  cin >> N >> X;

  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }

  D.at(0) = 0;
  int i = 0;
  while(D.at(i)<=X){
    D.at(i+1) = D.at(i) + L.at(i);
    i++;
    if(i==N+1){
      break;
    }
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] A = new int[5];
		int amari = 1000;
		int ans = 0;
		for(int i = 0; i < 5; i++) {
			A[i] = sc.nextInt();
			if(A[i] % 10 != 0) {
				amari = Math.min(A[i] % 10, amari);
				A[i] += 10 - A[i] % 10;
			}			
		}
		for(int i = 0; i < 5; i++) {
			ans += A[i];
		}
		if(amari != 1000)
			ans += amari - 10;
		System.out.println(ans);

	}

}

Measured memory_bytes: 21712
#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>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

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) cout << fixed << setprecision(10) << s << endl;


int main()
{
	vector<ll> a(3);
	for (ll i = 0; i < 3; i++)
	{
		cin >> a[i];
	}

	sort(all(a));

	println(a.back() - a.front());
}


Measured memory_bytes: 3604
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

map<string, int> res;
int d[4] = {1, -1, 4, -4};

void bfs() {
  queue<string> que;
  que.push("01234567");
  res["01234567"] = 0;
  while (!que.empty()) {
    string s = que.front();
    que.pop();
    int pos = 0;
    while (s[pos] != '0') pos++;
    for (int i = 0; i < 4; i++) {
      int npos = pos + d[i];
      if (0 <= npos && npos < 8 && !(pos == 3 && i == 0) &&
          !(pos == 4 && i == 1)) {
        string ns = s;
        swap(ns[pos], ns[npos]);
        if (res.find(ns) == res.end()) {
          res[ns] = res[s] + 1;
          que.push(ns);
        }
      }
    }
  }
}
int main() {
  bfs();
  string line;
  while (getline(cin, line)) {
    line.erase(remove(line.begin(), line.end(), ' '),
               line.end());  // remove white spaces
    cout << res[line] << endl;
  }
  return 0;
}


Measured memory_bytes: 5240
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)

vector<int> v[100000], V;
int l[100001], x[100000];

void NO() {
	printf("No\n");
	exit(0);
}

int main() {
	int n, m, q;
	scanf("%d%d%d", &n, &m, &q);
	f(i, 0, q)scanf("%d", x + i);
	for (int i = q - 1; i >= 0; --i) {
		int &d = l[x[i]];
		if (d == n)continue;
		if (!d)V.push_back(x[i]);
		if (V[v[d].size()] != x[i])continue;
		v[d].push_back(x[i]);
		++d;
	}
	int i = V.size();
	int j = 1;
	while (l[j])++j;
	for (--j; j && i; --j)if (V[i - 1] == j)--i;
	f(j, 0, n)f(k, 0, V.size()) {
		if (k >= v[j].size()) {
			if (k < i)NO();
			break;
		}
		if (v[j][k] != V[k])NO();
	}
	printf("Yes\n");
}

Measured memory_bytes: 6144
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;

int n;
string s[1024];

int rec(int a,int b,int c){ //a -> 参照する文字列 b->式の階層 c-> 演算の形式
  //cout << "call(a,b,c)" << a << "," << b <<"," << c << endl;
	int res=0;
	if(c)res=1;
	for(int i=a;i<n&&b<s[i].size();i++){
		if(s[i][b]=='.')continue;
		int x=s[i][b]-'0'; //ASCII code の性質 char -> int
		if(s[i][b]=='*')x=rec(i+1,b+1,1);
		if(s[i][b]=='+')x=rec(i+1,b+1,0);
		if(c)res*=x;
		else res+=x;
	}
	return res;
}

int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		REP(i,n)cin>>s[i];
		cout<<rec(0,0,0)<<endl;
	}
}



Measured memory_bytes: 3152
#include <cstdio>
#include <unordered_map>
using namespace std;

const int MOD = 1000000007;

unordered_map<int, int> cnt;

int main(){
  int N; scanf("%d", &N);

  for(int n = 1; n <= N; n++){
    int n_ = n;
    for(int i = 2; i * i <= n_; i++){
      int c = 0;
      while(n_ % i == 0){ c++; n_ /= i; }

      if(c > 0) cnt[i] += c;
    }

    if(n_ > 1) cnt[n_]++;
  }

  int ans = 1;
  for(auto& pp : cnt){
    ans = 1LL * ans * (pp.second + 1) % MOD;
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front

// #define fisier 1

using namespace std;

typedef long long ll;

const int mod = 1000000007;
const double dancila = 3.14159265359; // PI 
const double eps = 1e-9;

int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int a, b;
	cin >> a >> b;
	if(b >= a)
		cout << "unsafe";
	else
		cout << "safe";
    return 0;
}


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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define sortv(v) sort(v.begin(),v.end());
#define sorta(a,n) sort(a,a+n);
#define arrayin(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define arrayout(a,n) for(int i=0;i<n;i++) cout<<" ";cout<<"\n";
#define whatIs(x) cout<<#x<<" is "<<x<<endl;
#define fillA(a,value) memset(a,value,sizeof(a));
#define len(s) s.length()
#define reached cout<<"reached "<<endl;
#define INF INT_MAX //Infinity
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define MOD 1000000007
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vi64 vector<lli>
#define viii vector<tuple<int,int,int>>
#define prq priority_queue<int>
#define mii map<int,int>
#define msi multiset<int>
#define nl "\n"
#define sii set<int,int>
#define sz size

typedef long long int lli;
typedef unsigned long long int ulli;
typedef double ld;

using namespace std;

int main()
{
	fio;
	/*int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
	}*/
	int n,m;
	cin>>n>>m;
	vi v[n];
	REP(i,m)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		v[x].pb(y);
		v[y].pb(x);
	}
	REP(i,n) cout<<v[i].sz()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
//#define x first
//#define y second

using namespace std;
int m,n,s,c;
map<int,int>a;
int main()
{
	cin>>n>>m;
	rep(i,m)
	{
		cin>>s>>c;
		if(s>n||(a.count(s)&&a[s]!=c))
		{
			cout<<-1<<endl;
			return 0;
		}
		a[s]=c;
	}
	if(n==1&&!a.count(1)) cout<<0<<endl;
	elif(n!=1&&a.count(1)&&a[1]==0)
	{
		cout<<-1<<endl;
		return 0;
	}
	else
	{
		if(a.count(1)) cout<<a[1];else cout<<1;
		rep2(i,2,n+1) if(a.count(i)) cout<<a[i];else cout<<0;
		cout<<endl;
	}
	return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string.h>
#include<string>
#include<set>
#include<limits.h>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<functional>
#include<stack>
#include<deque>
#include<queue>
using namespace std;

int ru[100001];
signed main() {
	string a; cin >> a;
	for (int i = 0; i < a.length(); i++) {
		ru[i + 1] = ru[i];
		if (a[i] == '1')ru[i + 1]++;
	}
	int l = 1, r = a.length() + 1;
	while (r - l > 1) {
		int t = (l + r) / 2;
		if (t * 2 <= a.length()) { l = t; continue; }
		int sum = 0;
		for (int i = a.length() - t; i < t; i++) {
			if (a[i] == '1')sum++;
		}
		if (sum == 0 || sum == t * 2 - a.length())l = t;
		else r = t;
	}
	cout << l << endl;
}

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

int main() {
  string S;
  cin>>S;
  vector<int> a(4);
  vector<char> b(3);
  for(int i=0;i<4;i++) a[i]=S[i]-'0';
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
    bitset<3> s(tmp);
  int x=a[0];
  for(int i=0;i<3;i++){
    if(s.test(i)) {x+=a[i+1]; b[i]='+';}
    else {x-=a[i+1]; b[i]='-';}
  }
    if(x==7){
       for(int i=0;i<3;i++){
         cout<<a[i]<<b[i];
       }
     cout<<a[3]<<"=7"<<endl;
      return 0;
    }
  }
}





Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a != c)cout << 1;
	else cout << 0;
}


Measured memory_bytes: 3560
#include<stdio.h>
#include<string.h>

int main()
{
	long long n;
	char pass[255] = {0};
	
	scanf("%lld", &n);
	int i = 0;
	
	--n;
	while(n >= 0){
		pass[i] = (n % 26) + 'a';
		n /= 26;
		++i;
		--n;
	}
	
	int len = strlen(pass);
	
	for(int i = len - 1 ; i >= 0; i--){
		printf("%c", pass[i]);
	}
	puts("");
}

Measured memory_bytes: 1660
import sys
sys.setrecursionlimit(500000)
N = int(input())
A = [0] + list(map(int, input().split()))
E = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

def dfs(v, p=0):
    a = A[v]
    b = []
    for u in E[v]:
        if u!=p:
            b.append(dfs(u, v))
    if len(b)==0:
        return a
    sum_b, max_b = sum(b), max(b)
    if a < max_b or 2 * a < sum_b or a > sum_b:
        print("NO")
        exit()
    return 2 * a - sum_b

v = 1
ans = dfs(v)
if (ans==0 and len(E[v])>1) or (ans==A[v] and len(E[v])==1):
    print("YES")
else:
    print("NO")


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

int main(){
  int N, M, L;
  
  cin >> N;
  
  M = N % 100;
  L = M % 10;
  
  
  if(L == 2 || L == 4 || L == 5 || L == 7 || L == 9){
    cout << "hon" << endl;
  }else if(L ==0 || L == 1 || L == 6 || L == 8){
    cout << "pon" << endl;
  }else{
    cout << "bon" << endl;
  }
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x1,x2,x3,x4,x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  if(x1==0) cout << 1;
  if(x2==0) cout << 2;
  if(x3==0) cout << 3;
  if(x4==0) cout << 4;
  if(x5==0) cout << 5;
}

Measured memory_bytes: 3596
import sys
sys.setrecursionlimit(10**6)
def main():
    N = int(input())
    bl = []
    d = {i:0 for i in range(1,N+1)}
    d1 = {i:[] for i in range(1,N+1)}
    d2 = {}
    d3 = [0] * (N-1)
    for i in range(N-1):
        a, b = map(int, input().split())
        d2[tuple(sorted([a,b]))] = i
        d[a] += 1
        d[b] += 1
        d1[a].append(b)
        d1[b].append(a)
    m = 0
    for i in d:
        m = max(m, d[i])
    dfs(1, d1, d2, d3, 0)
    print(m)
    for i in d3:
        print(i)

def dfs(n, d1, d2, d3, c):
    count = 1
    for i in d1[n]:
        if d3[d2[tuple(sorted([n,i]))]] > 0:
            continue
        if count == c:
            count += 1
        d3[d2[tuple(sorted([n,i]))]] = count
        dfs(i, d1, d2, d3, count)
        count += 1
main() 


Measured memory_bytes: 85244
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;

signed main() {
	string a[3];
	cin >> a[0] >> a[1] >> a[2];
	rep(i, 3) {
		char ans = a[i][0] + ('A' - 'a');
		cout << ans;
	}
}

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


int main(){
	string s;

	while (cin >> s){
		for (auto it = s.begin(); it != s.end(); it++){
			if (*it != '@'){
				cout << *it;
				continue;
			}
			it++;
			int n = (*it) - '0';
			it++;
			for (int i = 0; i < n; i++){
				cout << *it;
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG 0
#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define VIN(VECTOR,n)
 
 
lli abs2(lli a){
	return a>=0?a:-a;
}
 
lli min2(lli a,lli b){
	return a<=b?a:b;
}
 
lli max2(lli a,lli b){
	return a>=b?a:b;
}
 
 
lli heightCalc(lli h,lli x,lli cx,lli y,lli cy){
	return max2(h-abs2(x-cx)-abs2(y-cy),0);
}
 
int main(){
 
	lli n;
	vector<lli> x,y,h;
	cin >>n;
	lli maxH=0;
	lli minH=100000000000;
	REP(i,n){
		lli tmpX,tmpY,tmpH;
		cin>>tmpX>>tmpY>>tmpH;
		x.push_back(tmpX);
		y.push_back(tmpY);
		h.push_back(tmpH);
		maxH = max2(maxH,tmpH);
		minH = min2(minH,tmpH);
	}
 
	lli flag=0;
	lli ansH,ansX,ansY;
	for(ansH = max2(minH-300,0);ansH <= maxH+500;ansH++){
	for(ansX = 0;ansX<=100;ansX++){
	for(ansY = 0;ansY<=100;ansY++){
		flag=0;
	for(lli i = 0;i<n;i++){
		if(h[i] != heightCalc(ansH,ansX,x[i],ansY,y[i])){
			flag=1;
			break;
		}
	}
	if(flag==0)goto END;
	}
	}
	}
 
END:
	if(flag==0)cout<<ansX<<" "<<ansY<<" "<<ansH<<endl;
	return 0;
	
}

Measured memory_bytes: 256
#![allow(unused)]

use std::{cell, cmp, collections, fmt, ops};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use fmt::{Debug, Display};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        _input_inner!(iter, $($r)*)
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        _input_inner!(iter, $($r)*)
    };
}

macro_rules! _input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = _read_value!($iter, $t);
        _input_inner!($iter $($r)*)
    };
}

macro_rules! _read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(_read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| _read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        _read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        _read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[cfg(feature = "debug")]
macro_rules! d {
    ($($args: tt)*) => { dbg!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! d {
    ($($args:tt)*) => {};
}

mod num {
    //
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

mod bits {
    pub fn is_high(bits: u64, pos: u64) -> bool {
        bits & (1 << pos) != 0
    }
}

fn main() {
    input!(stones_num: usize, pos_num: usize, pos: [i32; pos_num]);

    if stones_num >= pos_num {
        println!("{}", 0);
        return;
    }

    let mut pos = pos;
    pos.sort();

    let mut pos_intervals = pos.windows(2).map(|w| w[1] - w[0]).collect::<Vec<_>>();
    pos_intervals.sort_by(|d1, d2| d2.cmp(&d1));

    let ans = pos_intervals.iter().skip(stones_num - 1).sum::<i32>();

    println!("{}", ans);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}


Measured memory_bytes: 6396
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] lastpos = { 0, 0, 0 };
        for (int i = 0; i < n; i++)
        {
            int[] currentpos = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int diff = Math.Abs(currentpos[1] - lastpos[1]) + Math.Abs(currentpos[2] - lastpos[2]);
            int time = (currentpos[0] - lastpos[0]);
            if (diff > time  || (diff - time) % 2 != 0)
            {
                Console.WriteLine("No");
                return;
            }
            lastpos = currentpos;
        }
        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 17452
def val(a):
    return int(a[1:])


def bubble(lst,n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if val(lst[j])<val(lst[j-1]):
                lst[j],lst[j-1]=lst[j-1],lst[j]
    return lst

def selection(lst,n):
    for i in range(n):
        minj=i
        for j in range(i,n):
            if val(lst[j])<val(lst[minj]):
                minj=j
        if i!=minj:
            lst[minj],lst[i]=lst[i],lst[minj]
    return lst

n=int(input())
lst=input().split()
lstc=lst[:]
blst=bubble(lstc,n)
lstc=lst[:]
slst=selection(lstc,n)


print(" ".join(blst))
print("Stable") #バブルソートは安定ソート
print(" ".join(slst))
if slst==blst : print("Stable")
else : print("Not stable")


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
long long dp[55][10050];
int main(){
  long long n,p,sum=0,ans=0;
  cin >> n >> p;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
  }
  dp[0][0]++;
  for(int i=0;i<n;i++){
    for(int j=0;j<=sum;j++){
      dp[i+1][j+a[i]]+=dp[i][j];
      dp[i+1][j]+=dp[i][j];
    }
  }
  for(int i=p;i<=sum;i+=2){
    ans+=dp[n][i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2944
N=int(input())
A=[input() for i in range(N)]

t=[]
last=A[0][0]
f=True
for a in A:
	if last==a[0] and a not in t:
		last=a[-1]
		t.append(a)
	else:
		f=False
print('Yes' if f else 'No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s; cin >> s;
    ll cnt0 = 0;
    rep(i, s.size()) if(s[i] == '0') cnt0++;
    cout << s.size() - abs((ll)s.size()-2*cnt0) << endl;
}

Measured memory_bytes: 3796
#include <iostream>
using namespace std;
int main(){
    double ax1,ax2,ay1,ay2,bx1,bx2,by1,by2;
    while(cin>>ax1>>ay1>>ax2>>ay2>>bx1>>by1>>bx2>>by2)
        if(ax1<=bx2&&by1<=ay2&&bx1<=ax2&&ay1<=by2)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3148