akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

typedef struct node {
  int degree; /* 子の数 */
  int depth; /* 深さ */
  int height; /* 高さ */
  int parent; /* 親の値 */
  int sibling; /* 兄弟 */
  int left; /* 左側の子ノード */
  int right; /* 右側の子ノード */
} Node;

int cal_depth(Node *,int);
int cal_height(Node *,int);
void preParse(int);
void inParse(int);
void postParse(int);


Node T[30];
int root;

int main()
{
  int i,n,value = -1;
  scanf("%d",&n);

  /* 初期化 */
  for(i = 0;i < n;i++){
    T[i].depth = 0;
    T[i].height = 0;
    T[i].parent = -1;
    T[i].sibling = -1;
    T[i].left = -1;
    T[i].right = -1;
  }

  for(i = 0;i < n;i++){   
    scanf("%d",&value);
    scanf("%d",&T[value].left);
    scanf("%d",&T[value].right);
    if(T[value].left != -1){
      T[value].degree ++;
      T[T[value].left].sibling = T[value].right;   /* 存在したら、兄弟を入力する */
    }
    if(T[value].right != -1){
      T[value].degree ++;
      T[T[value].right].sibling = T[value].left;  /* 存在したら、兄弟を入力する */
    }
    T[T[value].left].parent = value;   /* 親を入力 */
    T[T[value].right].parent = value;
  }
  
  for(i = 0;i < n;i++){   /* ツリーを作ってから、高さと深さの計算をする */
    T[i].depth = cal_depth(T,i);
    if(T[i].depth == 0) root = i;
    T[i].height = cal_height(T,i);
  }
  

  /* 出力 */
    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

  return 0;
}

    
int cal_depth(Node *T,int now) /* 深さの計算 */
{ 
  if(T[now].parent != -1) return cal_depth(T,T[now].parent) + 1;
  return 0;
}

int cal_height(Node *T,int now) /* 高さの計算 */
{
  int sum_right = 0,sum_left = 0;

  if(T[now].left != -1) sum_left = cal_height(T,T[now].left) +1;
  if(T[now].right != -1) sum_right = cal_height(T,T[now].right) +1;

  if(sum_right >= sum_left) return sum_right;  /* 左と右の両方のパターンを計算し、大きいほうを返す */
  else return sum_left;
}

void preParse(int x)
{
  if(x != -1){
    printf(" %d",x);
    preParse(T[x].left);
    preParse(T[x].right);
  }
}

void inParse(int x)
{
  if(x != -1){
    inParse(T[x].left);
    printf(" %d",x);
    inParse(T[x].right);
  }
}

void postParse(int x)
{
  if(x != -1){
    postParse(T[x].left);
    postParse(T[x].right);
    printf(" %d",x);
  }
}

Measured memory_bytes: 616
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a % 2 == 1 && b % 2 == 1) {
      System.out.println("Odd");
    }else {
      System.out.println("Even");
    }
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
int main(){
  ll n,c; cin>>n>>c;
  ll x[n+1]={};
  ll v[n+1]={};
  repl(i,1,n+1) cin>>x[i]>>v[i];
  ll frui[n+1]={};
  ll brui[n+1]={};
  ll ca = 0;
  rep(i,n+1){
    ca += v[i];
    frui[i]=ca-x[i];}
  ll f[n+1]={};
  ca = 0;
  rep(i,n+1){
    ca = max(ca,frui[i]);
    f[i] = ca;}
  ca = 0;
  for(ll i=n; i>=0; i--){
    ca += v[i];
    brui[i]=ca-(c-x[i]);}
  ll b[n+1]={};
  ca = 0;
  for(ll i=n; i>=0; i--){
    ca = max(ca,brui[i]);
    b[i] = ca;}
  ll ans = 0;
  ca = 0;
  for(ll i=0; i<n; i++){
    ca = 0;
    ca += frui[i];
    ll k = max(b[i+1]-x[i],(ll)0);
    ca += k;
    ans = max(ans,ca);
  }
  
  for(ll i=n; i>0; i--){
    ca = 0;
    ca += brui[i];
    ll k = max(f[i-1]+x[i]-c,(ll)0);
    ca += k;
    ans = max(ans,ca);
  }
  ca = 0;
  ca += frui[n];
  ans = max(ans,ca);
  ca = 0;
  ca += brui[1];
  ans = max(ans,ca);
  cout << ans << endl;}
  


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

class MainClass
{
    static void Main()
    {
        var NM = Console.ReadLine().Split().Select(int.Parse ).ToArray();
        int N = NM[0], M = NM[1];
        var G = new List<int>[N];
        for (int i = 0; i < N; i++) G[i] = new List<int>();
        var parents = new List<int>[N];
        for (int i = 0; i < N; i++) parents[i] = new List<int>();
        var Degrees = new int[N];

        for(int i = 0; i < N+M-1; i++)
        {
            var ab = Console.ReadLine().Split().Select(_=>int.Parse(_)-1).ToArray();
            G[ab[0]].Add(ab[1]);
            Degrees[ab[1]]++;
            parents[ab[1]].Add(ab[0]);
        }

        var sorted = TopologicalSort(G, Degrees);
        var sortedpos = new int[N];
        for (int i = 0; i < N; i++)
        {
            sortedpos[sorted[i]] = i;
        }

        for (int i = 0; i < N; i++)
        {
            int parent = -1;
            int parentpos = -1;
            foreach (var vs in parents[i])
            {
                if (parentpos < sortedpos[vs])
                {
                    parent = vs;
                    parentpos = sortedpos[vs];
                }

            }

            Console.WriteLine(parent+1);
        }
    }
    static List<int> TopologicalSort(List<int>[] G,int[] Degrees)
    {
        var que = new Queue<int>();
        for (int i = 0; i < Degrees.Length; i++)
        {
            if (Degrees[i] == 0)
                que.Enqueue(i);
        }

        List<int> sorted = new List<int>();
        while (que.Count > 0)
        {
            var t = que.Dequeue();
            sorted.Add(t);

            foreach (var i in G[t])
            {
                Degrees[i]--;
                if (Degrees[i] == 0)
                {
                    que.Enqueue(i);
                }
            }
        }

        return sorted;
    }
}

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

int main() {
	string a;
	while (1) {
		getline(cin, a);
	    if (a == "END OF INPUT")break;
		string b = "";
		for (int c = 0; c < a.length(); c++) {
			if (a[c] == ' ') { cout << b.length(); b = ""; }
			else b += a[c];
		}
		cout << b.length() << endl;
	}
}

Measured memory_bytes: 3132
#include <stdio.h>

int main(void)
{
	int a;
	int m[10];
	int i;
	int j;
	int tmp;
	
	for (a = 0; a < 10; a++) {
		scanf("%d", &m[a]);
	}
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			if (m[i] > m[j]) {
				tmp = m[i];
				m[i] = m[j];
				m[j] = tmp;
			}
		}
	}
	for (a = 0; a < 3; a++) {
		printf("%d\n", m[a]);
	}
	
	return (0);
}

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

int		main(void)
{
	int N, T;

	cin >> N >> T;
	set<int> cost;
	
	for (int i = 0; i < N; i++)
	{
		int c, t;

		cin >> c >> t;
		if (t <= T)
			cost.insert(c);
	}
	if (cost.empty())
		cout << "TLE" << endl;
	else
		cout << *begin(cost) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int Mod=1e9+7;
const int INF=0x3f3f3f3f;

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	LL N,a=10,b=9,c=8;
	cin>>N;
	while(--N){
		a=a*10%Mod;
		b=b*9%Mod;
		c=c*8%Mod;
	}
	b=b*2%Mod;
	LL ans=(a-b+c)%Mod;
	if(ans<0) ans+=Mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int> pll;

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


Measured memory_bytes: 3580
import java.util.*;

public class Main{
  static int[] ans;
  static Map<Integer, Integer> map;
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int R = sc.nextInt();
    int G = sc.nextInt();
    int B = sc.nextInt();
    int N = sc.nextInt();
    
    int ans = 0;
    for(int i = 0; i*R <= N; i++){
      for(int j = 0; j*G <= N-(i*R); j++){
        if((N-(i*R)-(j*G))%B == 0){
          ans++;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> vec = {A, B, C};
  sort(vec.begin(),vec.end());
  if (vec.at(0)==vec.at(2)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

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

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

	const int INF = 0xfffffff;
	for(int n; cin >> n, n;) {
		vector<int> p(n + 1, 0), t(n + 1, 0);
		for(int i = 1; i <= n; ++i)
			cin >> p[i] >> t[i];

		vector<int> dp(4, INF);
		dp[0] = 0;
		for(int i = 0; i < n; ++i) {
			vector<int> tmp(4, INF);
			const int dist = abs(p[i] - p[i + 1]);
			for(int j = 0; j < 4; ++j) {
				if(dp[j] < INF) {
					if(j < 3 && t[i] + dist * (j + 1) <= t[i + 1])
						chmin(tmp[j + 1], dp[j] + dist);

					if(t[i] + p[i] * (j + 1) + p[i + 1] <= t[i + 1])
						chmin(tmp[1], dp[j] + p[i] + p[i + 1]);
				}
			}

			bool ng = true;
			for(int j = 1; j < 4; ++j)
				if(tmp[j] < INF)
					ng = false;

			if(ng) {
				cout << "NG " << i + 1 << endl;
				goto next;
			}

			dp.swap(tmp);
		}

		cout << "OK " << *min_element(dp.begin(), dp.end()) + p[n] << endl;
	next:;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cassert>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <complex>
#include <cmath>

using namespace std;
typedef long long ll;

typedef long double R;
typedef complex<R> P;

namespace std {
    bool operator < (P a, P b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
    bool operator > (P a, P b) {
        return (b < a);
    }
}

const R EPS = 1e-10;
const R PI = acos((R)(-1));

/*
 -1 -> neg
  0 -> near 0
  1 -> pos
  */
int sgn(R a) {
    if (a < -EPS) return -1;
    if (a > EPS) return 1;
    return 0;
}

int sgn(R a, R b) {
    return sgn(b-a);
}

bool near(P a, P b) {
    return !sgn(abs(a-b));
}

R cross(P a, P b) { return imag(conj(a)*b); }
R dot(P a, P b) { return real(conj(a)*b); }


R ssqrt(R d) {
    d = max<R>(0, d);
    return sqrt(d);
}

R sacos(R d) {
    d = max<R>(-1, d);
    d = min<R>(1, d);
    return acos(d);
}

struct L {
    P x, y;
    L() {};
    L(P x, P y) :x(x), y(y) {};
};

struct C {
    P p;
    R r;
    C() {}
    C(P p, R r) : p(p), r(r) {}
};

//return number of cross point
int crossP(const C &c, const C &d, L &l) {
    if (near(c.p, d.p) && !sgn(c.r, d.r)) return -1;
    R di = abs(c.p - d.p);
    if (sgn(c.r+d.r, di) == 1) return 0;
    if (sgn(di, abs(c.r-d.r)) == 1) return 0;
    R bth = arg(d.p - c.p);
    R th = sacos((c.r*c.r + di*di - d.r*d.r) / (2*c.r*di));
    l.x = c.p+polar<R>(c.r, bth+th);
    l.y = c.p+polar<R>(c.r, bth-th);
    if (sgn(th) == 0) return 1;
    return 2;
}

const int MN = 110;
int n;
C c[MN];
vector<P> v;

int main() {
    while (true) {
        v.clear();
        cin >> n;
        if (!n) break;
        for (int i = 0; i < n; i++) {
            R x, y; char ign;
            cin >> x >> ign >> y;
            c[i] = C(P(x, y), 1.0);
            v.push_back(P(x, y));
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                L l;
                int u = crossP(c[i], c[j], l);
                if (u > 0) {
                    v.push_back(l.x);
                    v.push_back(l.y);
                }
            }
        }
        int res = -1;
        for (P p: v) {
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (sgn(abs(p-c[i].p), 1.0) >= 0) r++;
            }
            res = max(res, r);
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1364
// C - Prison
#include <bits/stdc++.h>
using namespace std;

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

int main(){
	int N=in(), M=in();
	int L = 1, R = N;
	while(M--){
		L = max(L, in());
		R = min(R, in());
	}
	cout<< (R<L? 0: R-L+1) <<endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)


typedef map<string, int> map_type;
typedef pair<string, int> value_type;

struct second_order {
  bool operator()(const value_type& x, const value_type& y) const {
    if( x.second != y.second) return x.second < y.second;
    return x.first > y.first;
  }
};

typedef priority_queue<value_type, vector<value_type>, second_order> pqueue_type;


pqueue_type map_to_pqueue(map_type m) {
    pqueue_type que;
    for(auto it=m.begin(); it!=m.end(); ++it) {
        que.push(*it);
    }
    return que;
}


int main(void){
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    int vx1, vy1, vx2, vy2;
    vx1 = x2-x1;
    vy1 = y2-y1;
    vx2 = -1*vy1;
    vy2 = vx1;
    x3 = x2+vx2;
    y3 = y2+vy2;
    x4 = x3-vx1;
    y4 = y3-vy1;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
using namespace std;
int main()
{
    int n,w;
    cin>>n>>w;
    vp v;
    v.pb(mp(0,0));
    for (int i=1; i<=n; i++)
    {
        int x,y;
        cin>>x>>y;
        v.pb(mp(x,y));
    }
    ll dp[n+1][w+1];
    for (int i=0; i<=n; i++)
        dp[i][0]=0;
    for (int i=1; i<=w; i++)
        dp[0][i]=0;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=w; j++)
        {
            if(j<v[i].F)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],
                dp[i-1][j-v[i].F]+v[i].S);
        }
    }
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79104
N = int(input())
#print(N)

work = []
for i in range(N):
     work.append(list(map(int, input().split(' '))))

#print(work)
work.sort(key=lambda x:x[1])
#print(work)

time = 0
time_over = 0
for i in range(N):
    time += work[i][0]
    if(time > work[i][1]):
        time_over = 1
        break

if(time_over == 0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 53720
#include <atcoder/math>
#include <atcoder/convolution>
#include <atcoder/dsu>
#include <atcoder/fenwicktree>
#include <atcoder/lazysegtree>
#include <atcoder/maxflow>
#include <atcoder/mincostflow>
#include <atcoder/scc>
#include <atcoder/segtree>
#include <atcoder/string>
#include <atcoder/twosat>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;

int main() {
   int k;
   cin >> k;
  string a = "ACL";
  while(k > 1){
    a += "ACL";
    k--;
  }
   cout << a << endl;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cmath>
#define Int int
using namespace std;
 
const int MAX_NUM = 500000;
bool prime_number[MAX_NUM];
  
void isPrime() {
    fill(prime_number, prime_number + MAX_NUM, true);
    prime_number[0] = prime_number[1] = false;
  
    for(int i = 2; i < MAX_NUM; i++) {
        if(prime_number[i])
        for(int j = 2; i*j < MAX_NUM; j++) {
            prime_number[i*j] = false;
        }
    }
}
int main(void){
  int n;
  isPrime();
  while(cin>>n){
    int i;
 
    for(i = (!prime_number[n]?n:n-1) ; !prime_number[i] ; i --);
    cout<<i<<" ";
    for(i = (!prime_number[n]?n:n+1) ; !prime_number[i] ; i ++);
    cout<<i<<endl;
  }
}

Measured memory_bytes: 1648
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
A = [i for i in range(1, M + 1)]
tL = list(zip(*L))
P = tL[0]
Y = tL[1]
Z = list(zip(A, P, Y))
sortedZ = sorted(Z, key=lambda x:x[2])
count= {}
X = []
for i in range(M):
    count.setdefault(sortedZ[i][1], 0)
    count[sortedZ[i][1]] = count[sortedZ[i][1]] + 1
    X.append(count[sortedZ[i][1]])
T = list(zip(*sortedZ))
GOD = list(zip(T[0], T[1], T[2], X))
ans = sorted(GOD)
for i in range(M):
    print(str(ans[i][1]).rjust(6, '0') + str(ans[i][3]).rjust(6, '0'))


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

int coin[6] = {1,5,10,50,100,500};

int main(){
	int i,c;
	int s = 0;
	for( i = 0; i < 6; i++ ){
		cin >> c;
		s += c * coin[i];
	}
	if( s >= 1000 ){
		cout << "1" << endl;
	}
	else{
		cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
using namespace std;
using graph = vector<vector<int>>;
using ll = long long;
using p = pair<int, int>;

bool isContain(int a, vector<int> p)
{
    int n = p.size();
    for (int i = 0; i < (n); ++i)
    {
        if (a == p[i])
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    for (int i = 0; i < (n); ++i)
    {
        cin >> p[i];
    }

    int score = 100;
    int ans = 100;
    for (int i = 0; i <= (101); ++i)
    {
        if (isContain(i, p))
        {
            continue;
        }

        int temp = abs(x - i);
        if (temp < score)
        {
            score = temp;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
from collections import deque

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append((b - 1, i))
    edge[b - 1].append((a - 1, i))
ec = [0] * (N - 1)


def bfs():
    q = deque()
    q.append((0, 0))

    while len(q):
        v, pc = q.popleft()
        color = 1

        for e in edge[v]:
            if color == pc:
                color += 1

            if ec[e[1]] == 0:
                ec[e[1]] = color
                q.append((e[0], color))
                color += 1


bfs()
print(max(ec))
for c in ec:
    print(c)


Measured memory_bytes: 40128
//
//  main.cpp
//  kyougi
//
//  Created by 寺林 一旭 on 2018/08/27.
//  Copyright © 2018年 寺林 一旭. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <map>
using namespace std;
int main() {
    
    string num;
    int inputValue;
    vector<int> list;
  
    while(getline(cin, num))
    {
        int a,b;
        sscanf(num.c_str(), "%d %d",&a,&b);
        int sum = a+b;
        int digit = 0;
        while( sum != 0)
        {
            sum = sum/10;
            digit++;
        }
        cout << digit << endl;
   //     cout << a-b <<endl;
    }
  
    
    return 0;
}



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

// 0以上n以下のうちxで割り切れるものの個数
long long method(long n, long x) {
    long long result = 0;
    if (n == -1) {
        result = 0;
    } else {
        result = n / x + 1;
    }
    return result;
}

int main(){   
    long long a, b, x;
    cin >> a >> b >> x;
    // cout << a-1 << endl;
    long long result_a = method(a-1, x);
    long long result_b = method(b, x);

    cout << result_b - result_a << endl;

    return 0;
}

Measured memory_bytes: 256
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    n = int(input())
    ll = list(map(int, input().split()))
    l = [0] * 9
    for i in ll:
        if i < 400:
            l[0] += 1
        elif i < 800:
            l[1] += 1
        elif i < 1200:
            l[2] += 1
        elif i < 1600:
            l[3] += 1
        elif i < 2000:
            l[4] += 1
        elif i < 2400:
            l[5] += 1
        elif i < 2800:
            l[6] += 1
        elif i < 3200:
            l[7] += 1
        else:
            l[8] += 1
    cnt = 0
    for j in l[:8]:
        if j >= 1:
            cnt += 1
    if cnt==0:
        print(1,l[8])
    else:
        print(cnt, cnt + l[8])

resolve()

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec A(M), B(M);
    REP(i,0,M) {
        cin >> A[i] >> B[i];
        --A[i]; --B[i];
    }

    ll cnt = 0;

    REP(i,0,M) {
        
        mat G(N);
        REP(j,0,M) {
            if(i == j) continue;
            G[A[j]].pb(B[j]);
            G[B[j]].pb(A[j]);
        }

        queue<ll> Q;
        vector<bool> F(N, false);
        Q.push(0);
        F[0] = true;
        while(!Q.empty()) {
            ll v = Q.front(); Q.pop();
            FORR(nv,G[v]) {
                if(!F[nv]) {
                    F[nv] = true;
                    Q.push(nv);
                }
            }
        }

        bool f = true;
        REP(j,0,N) {
            if(!F[j]) {
                f = false;
                break;
            }
        }
        if(!f) ++cnt;

    }

    PR(cnt);

    return 0;
}

/*



*/

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    string S; cin >> S;
    S[3] = '8';
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vector<ll> zalgo(string s){
	ll n = s.size();
	vector<ll> z(n,0);
	z[0] = n;
	ll i = 1, j = 0;
	while(i < n){
		while(i+j < n && s[j] == s[i+j]) j++;
		if(j == 0){
			i++;
			continue;
		}
		z[i] = j;
		ll k = 1;
		while(k < j && k + z[k] < j){
			z[i+k] = z[k];
			k++;
		}
		i += k;
		j -= k;
	}
	return z;
}

int main(){
	ll n; cin >> n;
	string s; cin >> s;
	ll ans = 0;
	rep(i,n-1){
		vl z = zalgo(s.substr(i));
		rep(j,n-i){
			chmax(ans, min(z[j], j));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int n,m,i,j,s;
	int d1[100][100];
	int d2[100];
scanf("%d %d",&n,&m);

for(i=0;i<n;i++){
	for(j=0;j<m;j++){
		scanf("%d ",&d1[i][j]);
	}
}
for(i=0;i<m;i++){
	scanf("%d",&d2[i]);
}
for(i=0;i<n;i++){
	s=0;
	for(j=0;j<m;j++){
		s=s+d1[i][j]*d2[j];
	}
	printf("%d\n",s);
}

	return 0;
}

Measured memory_bytes: 644
import java.util.Scanner;
import java.util.stream.*;

public class Main{
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] time = new int[n];
		for(int i = 0; i < n; i++){
			time[i] = sc.nextInt();
		}
		
		int m = sc.nextInt();
		for(int i = 0; i < m; i++){
			int problem_no = sc.nextInt();
			int time_drank = sc.nextInt();
			int result = IntStream.of(time).sum();
			result = result - time[problem_no-1] + time_drank;
			System.out.println(result);
		}
		sc.close();
	}
	
	
}


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

int main() {
    string s;
    cin>>s;
    int flag=0;
    rep(i,s.size()){
        if(s.at(i)=='C'){
            flag=1;
        }
        if(flag==1){
            if(s.at(i)=='F'){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
return 0;}
/*
g++ code.cpp
./a.out
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long

static const int MAX = 100000;

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int n, m, k;
int A[MAX];

int main(){
    cin >> n >> m >> k;
    UnionFind uf(n);
    uf.init(n);

    for(int i = 0; i < n; i++){
        A[i] = 1;
    }

    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.merge(a,b);
        A[a]++;
        A[b]++;
    }
    for(int i = 0; i < k; i++){
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        if( uf.issame(c,d) ){
            A[c]++;
            A[d]++;
        }
    }
    for(int i = 0; i < n; i++){
        if(i) cout << " ";
        cout << uf.size(i) - A[i];
    }
    cout << endl;
    return 0;
}

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

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

template<typename T>
T lcm(T a, T b)
{
	return a / gcd(a, b) * b;
}

//(a^e)%mod
template<typename T>
T power(T a, T e, T mod)
{
	if(e == 0)
	{
		return 1;
	}
	if(e % 2 != 0)
	{
		//a^e=a^(e-1)*a
		return (power(a, e - 1, mod) * a) % mod;
	}
	T res = power(a, e / 2, mod);
	//a^e=a^(e/2)*a^(e/2)
	return (res * res) % mod;
}

template<typename T>
class Tree
{
private:
public:
	T data;
	Tree* parent = NULL;
	std::vector<Tree*> children;
	void setData(T x)
	{
		data = x;
	}
	void setParent(Tree* t)
	{
		parent = t;
	}
	void addChild(Tree* t)
	{
		children.push_back(t);
	}
	Tree(){}
	~Tree(){}
	
};

template<typename T>
class Graph
{
public:
	T index;
	vector<T> edge;
	void setEdge(T t)
	{
		edge.push_back(t);
	}
	Graph(){}
	~Graph(){}
};

Graph<int> G[101];
pair<int, int> timeStamp[101] = {};
int cn = 1;

void rec(int now)
{
	if(timeStamp[now].first != 0)
	{
		return;
	}
	timeStamp[now].first = cn++;
	for (auto t : G[now].edge)
	{
		rec(t);
	}
	timeStamp[now].second = cn++;
}

int main()
{
	using namespace std;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int index, k;
		cin >> index >> k;
		G[index].index = index;
		for (int j = 0; j < k; ++j)
		{
			int in;
			cin >> in;
			G[index].setEdge(in);
		}
		sort(G[index].edge.begin(), G[index].edge.end());
	}
	for (int i = 1; i <= n; ++i)
	{
		rec(i);
	}
	for (int i = 1; i <= n; ++i)
	{
		cout << i <<" " << timeStamp[i].first << " " << timeStamp[i].second << endl;
	}
	return 0;
}



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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<k;i++){
    ans += p.at(i);
  }
  cout << ans << endl;
  
  return 0;
}

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

int main() {
	string s;
	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 1) {
			if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
			     continue;	
			}
			else {
				cout << "No" << "\n";
				return 0;
			}
		}
		else {
			if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
				continue;
			} 
			else {
				cout << "No" << "\n";
				return 0; 
			}
		}
	}
	cout << "Yes" << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double d = scan.nextDouble();
        double v = (d/3)*(d/3)*(d/3);
        System.out.println(v);
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
  long long a,b,c;
  cin>>a>>b>>c;
  long long x=c-a-b;
  if(x>0&&4*a*b<x*x) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3136
n = int(input())
t1, x1, y1 = 0, 0, 0

for i in range(n):
    t2, x2, y2 = [int(j) for j in input().split()]
    if not ((t2 - t1) % 2 == (abs(x2 - x1) + abs(y2 - y1)) % 2
            and (t2 - t1) >= abs(x2 - x1) + abs(y2 - y1)):
        print('No')
        break
    else:
        t1, x1, y1 = t2, x2, y2
else:
    print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
int32_t main()
{
	fast;
	int h, w;
	cin>>h>>w;
	int arr[h][w];
	int arr2[h][w];
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			char c;
			cin>>c;
			if(c=='#')
				arr[i][j]=0;
			else
				arr[i][j]=1;
			arr2[i][j]=0;
			// if(i==0 || j==0)
			// 	arr2[i][j]=arr[i][j];
		}
	}
	arr2[0][0]=1;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(i==0 && j==0)
				continue;
			if(!arr[i][j])
				continue;
			int a=0, b=0;
			if(i!=0)
				a=arr2[i-1][j];
			if(j!=0)
				b=arr2[i][j-1];
			arr2[i][j]=(a+b)%mod;
		}
	}
	cout<<arr2[h-1][w-1]<<endl;
	return 0;
}

Measured memory_bytes: 15872
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N;
    scan(N);
    auto primes = eratos(2 * 10^^5);
    foreach (pi ; primes) {
        if (pi >= N) {
            writeln(pi);
            return;
        }
    }
}

int[] eratos(int N) {
    auto s = new bool[](N);
    s[] = true;
    s[0] = s[1] = false;

    for (int p = 2; p*p < N; p++) {
        if (s[p]) for (int d = p*p; d < N; d += p) {
            s[d] = false;
        }
    }

    return iota(N).filter!(i => s[i]).array;
}


struct ModComb {
    int _N;
    long[] _fact, _factinv;
    long _mod;

    this(int n, long mod = 1_000_000_007L) {
        _N = n;
        _fact = new long[](_N + 1);
        _factinv = new long[](_N + 1);
        _mod = mod;

        _fact[0] = 1;
        foreach (i ; 1 .. _N + 1) {
            _fact[i] = (_fact[i-1] * i) % mod;
        }

        _factinv[_N] = _powmod(_fact[_N], mod - 2);
        foreach_reverse (i ; 0 .. _N) {
            _factinv[i] = (_factinv[i+1] * (i+1)) % mod;
        }
    }

    long c(int n, int k) {
        if (k < 0 || k > n) return 0;
        return f(n) * finv(n - k) % _mod * finv(k) % _mod;
    }

    long p(int n, int r) {
        if (r < 0 || r > n) return 0;
        return f(n) * finv(n - r) % _mod;
    }

    long f(int n) {
        return _fact[n];
    }

    long finv(int n) {
        return _factinv[n];
    }

    long _powmod(long x, long y) {
        return y > 0 ? _powmod(x, y>>1)^^2 % _mod * x^^(y & 1) % _mod : 1;
    }
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

int main(){
  string S;
  cin>>S;
  
  if(S=="ABC"){
    cout<<"ARC"<<endl;
  }else{
    cout<<"ABC"<<endl;
  }

}

Measured memory_bytes: 3548
#include <iostream>
using namespace std;
int main(){
  int r,c,m,n,data[101][101];

  cin>>r>>c;

  for(m=0; m<101; m++)for(n=0; n<101; n++)data[m][n]=0;

  for(m=0; m<r; m++)for(n=0; n<c; n++)cin>>data[m][n];

  for(m=0; m<r; m++){

    for(n=0; n<c; n++)cout<<data[m][n]<<" ";

    for(n=0; n<c; n++)data[m][c]+=data[m][n];
    cout<<data[m][c];

    cout<<"\n";

  }

  for(n=0; n<c+1; n++){

    for(m=0; m<r; m++)data[r][n]+=data[m][n];

    cout<<data[r][n];
    if(n==c)break;
    else cout<<" ";

      }

  cout<<"\n";

}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int n,a[3000],ans;
int main(){
	cin>> n;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			auto k=lower_bound(a+j,a+n,a[i]+a[j])-a;
			k--;ans+=k-j;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
(* O(n) *)
Scanf.scanf " %d" @@ fun n ->
  let g = Array.make n [] in
  for _ = 1 to n - 1 do
    Scanf.scanf " %d %d %d" @@ fun u v w ->
      let u, v = u - 1, v - 1 in
      g.(u) <- (v, w mod 2) :: g.(u);
      g.(v) <- (u, w mod 2) :: g.(v);
  done;
  let cs = Array.make n 0 in
  let rec dfs v p c =
      cs.(v) <- c;
      let f (v2, w) = if v2 <> p then dfs v2 v @@ c lxor w in
      List.iter f g.(v) in
  dfs 0 (-1) 0;
  cs |> Array.iter @@ fun c -> max 0 c |> Printf.printf "%d\n"

Measured memory_bytes: 20224
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::VecDeque;

fn main() {
    input!{
        n: usize
    }
    let mut q: VecDeque<Vec<usize>> = VecDeque::new();
    q.push_back(vec![]);
    while let Some(w) = q.pop_front() {
        let mut wt = w.clone();
        if w.len() == n {
            println!("{}", wt.iter().map(|&c| (c as u8 + 'a' as u8) as char).collect::<String>());
        } else {
            let mut ds = vec![false; n];
            for &c in &w {
                ds[c] = true;
            }
            for i in 0..n {
                if !ds[i] {
                    ds[i] = true;
                    break;
                }
            }
            for i in 0..n {
                if ds[i] {
                    wt.push(i);
                    q.push_back(wt.clone());
                    wt.pop();
                }
            }
        }
    }
}


Measured memory_bytes: 16892
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

int main(int argc,char*argv[]){
int n;
std::cin >> n;

for(int i = 1;i < 10;i++)
if(n <= 111*i){
std::cout << 111*i << std::endl;
break;
}
return 0;
}


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

int main(){
    ll N;
    cin >> N;
    vector<ll> x(N),y(N);
    rep(i,N){
        cin >> x[i] >> y[i];
    }
    ll M = 0;
    rep(i,N){
        rep(j,N){
            if(i == j)continue;
            ll vecx = x[j] - x[i];
            ll vecy = y[j] - y[i];
            ll cnt = 0;
            rep(k,N){
                rep(m,N){
                    if(k==m)continue;
                    if(vecx == x[m]-x[k] && vecy == y[m] - y[k]){
                        cnt++;
                    }
                }
            }
            M = max(M,cnt);
        }
    }
    cout << N - M << endl;
    /*vector<pair<ll,ll>> p(N);
    rep(i,N){
        cin >> p[i].first >> p[i].second;
    }
    
    sort(p.begin())
    ll ans = 50;
    rep(i,N){
        rep(j,N){
            ll dx = p[i].first - p[j].first;
            ll dy = p[i].second - p[j].second;
            vector<bool> used(N,false);
            used[i] = true;
            used[j] = true;
            ll curx = p[j].first;
            ll cury = p[j].second;
            ll cnt = 0;
            rep(k,N-2){
                rep(m,N-2){
                    if(used[m])continue;
                    if(curx+dx == p[m].first && cury+dy == p[m].second){
                        used[m] = true;
                        cnt++;
                        break;
                    }
                }
            }
        }
    }*/

}


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

// int main() {
//     cout << 200000 << " " << 1000000000000000000 << endl;
//     rep(i, 200000) {
//         cout << 1000000 << " ";
//     }
//     cout << endl;
//     rep(i, 200000) {
//         cout << 1000000 << " ";
//     }
//     cout << endl;
// }


ll N, K;
ll A[301010], F[301010];

bool ok(ll m) {
    ll sum = 0;
    bool ok = true;
    rep(i, N) {
        if (A[i] * F[i] <= m) continue;
        ll tmp = ((A[i]*F[i] - m) / F[i]) + bool((A[i]*F[i]-m)%F[i]);
        sum += tmp;
        if (sum > K) {
            ok = false;
            break;
        }
    }
    return ok;
}

int main() {
    cin >> N >> K;
    ll sum = 0;

    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    rep(i, N) cin >> F[i];

    if (sum <= K) {
        cout << 0 << endl;
        return 0;
    }

    sort(A, A+N);

    sort(F, F+N);
    reverse(F, F+N);

    ll l = 0, r = 1e13;
    while (r-l>1) {
        ll m = (l+r)/2;
        if (ok(m)) r = m;
        else l = m;
    }

    cout << r << endl;
}


Measured memory_bytes: 3840
#include <stdio.h>

int main(void) {
	
	int b1, b2, b3;
	
	scanf("%d%d%d", &b1, &b2, &b3);
	
	if(b3 == 1) {
		printf("Open\n");
	} else if (b1 == 1 && b2 == 1) {
		printf("Open\n");
	} else {
		printf("Close\n");
	}
	
	return 0;
}

Measured memory_bytes: 2684
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
const int maxn = 1e3 + 5;
struct Node {
    int c, item;
}a[maxn];
int dp[(1 << 12) + 5];

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    int n, m;
    sf(n, m);
    memset(dp, INF, sizeof(dp));
    for (int i = 1; i <= m; ++i) {
        int x, y;
        sf(x, y);
        a[i].c = x;
        a[i].item = 0;
        for (int j = 1; j <= y; ++j) {
            int t = read();
            a[i].item |= 1 << (t - 1);
        }
    }
    dp[0] = 0;
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 1; j <= m; ++j) {
            if ((i | a[j].item) != 0) {
                dp[(i | a[j].item)] = min(dp[(i | a[j].item)], dp[i] + a[j].c);
            } 
        }
    }
    if (dp[(1 << n) - 1] == INF) puts("-1");
    else cout << dp[(1 << n) - 1] << endl;
    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

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

#define mp(x,y) make_pair(x,y) 
#define M 1000000007
#define endl "\n"
#define pb(x) push_back(x)
#define llip(t) long long t ; cin >> t ;
#define llip2(a,b) long long a,b ; cin >> a >> b ;
#define dip(a) double a ; cin >> a ;
#define dip2(a,b) double a,b ; cin >> a >> b ; 
#define pll pair<long long,long long>  
typedef long long ll;
 
int main(){ 
    ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    llip(n) ;
    vector<ll> ip(n) ;
    for(int i = 0 ; i < n ; i++){
    	cin >> ip[i] ;
    }
    vector<ll> dp(n) ;
    dp[0] = 0 ;
    dp[1] = abs(ip[1]-ip[0]) ;
    for(int i = 2 ; i < n ; i++){
    	dp[i] = min(dp[i-1] + abs(ip[i]-ip[i-1]), dp[i-2] + abs(ip[i-2]-ip[i])) ;
    }
    cout << dp[n-1] << endl ;
}
 

Measured memory_bytes: 1792