akhauriyash/Code-Regression huggingface dataset:
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
const int N = 1e5+2;
signed main()
{
    fast;
    int n,k,q;
    cin>>n>>k>>q;
    int a[n+2]={};
    for(int i=1;i<=q;i++)
    {
        int x;
        cin>>x;
        a[0]++;
        a[x]--;
        a[x+1]++;
        a[n+1]--;
    }
    for(int i=1;i<=n;i++)
    {
        a[i]+=a[i-1];
    }
    for(int i=1;i<=n;i++)
    {
        a[i] = -a[i];
    }
    for(int i=1;i<=n;i++)
    {
        a[i] = a[i]+k;
        if(a[i]>0)
            cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int count(int n){
    int t = 0;
    REP(i,32){
        if(n & 1<<i) t++;
    }
    return t;
}

bool check(int n){
    if(count(n) == 1) return true;
    else return false;
}

int MSB(int n) {
    n |= (n >>  1);
    n |= (n >>  2);
    n |= (n >>  4);
    n |= (n >>  8);
    n |= (n >> 16);
    return n - (n >> 1);
}

int f(int n){
    int msb = MSB(n);
    return MSB(n)<<1;
}

int main(void){
    int N; cin >> N;
    VI A(N); REP(i,N) cin >> A[i];
    SORT(A);

    map<int,int> m;
    REP(i,N){
        if(m.find(A[i]) != m.end()) m[A[i]]++;
        else m[A[i]] = 1;
    }

    int ans = 0;
    RREP(i,N){
        int a = f(A[i]);
        int t = 0;
        if(count(A[i]) == 1) t = 1;
        if(m.find(a-A[i]) != m.end() && m[a-A[i]] > t && m[A[i]] > t){
            ans++;
            m[A[i]]--;
            m[a-A[i]]--;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
<?php
  list($n, $m) = explode(" ", trim(fgets(STDIN)));
  if($n > $m)
  {
    for($i=0;$i<$n;$i++){
      echo $m;
    }
  }else{
    for($i=0;$i<$m;$i++){
      echo $n;
    }
  }

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

int main() {
  int N;
  cin >> N;
  
  vector<double> x(N), y(N);
  vector<int> v(N);
  rep0(i, N) {
    cin >> x[i] >> y[i];
    v[i] = i;
  }

  double ans = 0;
  double bunbo = 1;
  rep1(i, N) bunbo *= i;
  
  do {
    double temp = 0;
    double x0 = x[v[0]];
    double y0 = y[v[0]];
    rep(i, 1, N) {
      double x1 = x[v[i]];
      double y1 = y[v[i]];
      temp += sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
      x0 = x1;
      y0 = y1;
    }
    ans += temp / bunbo;
  } while (next_permutation(v.begin(), v.end()));

  fcout << ans << BR;

  return 0;
}

Measured memory_bytes: 256
// D - I hate Factorization
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll X; cin>>X;
	for(ll a=-119; a<=119; ++a)
		for(ll b=-119; b<=119; ++b)
			if(pow(a,5) - pow(b,5) == X){ cout<<a<<" "<<b<<endl; return 0; }
}

Measured memory_bytes: 4104
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        sc.close();
        int i=0;
        while(n>1){
            n/=2;
            i++;
        }
        System.out.println(1<<i);
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <map>
#include <set>

#define rep(i, n) for(int i=0; i<n; i++)
#define MAX 100010
using namespace std;

//木のデータ構造
vector<vector<int> > tree(MAX, vector<int>() );

//訪問済み検査配列
vector<bool> visit(MAX, false);

//頂点Kから頂点iへの最短距離はdist[i]である
long long dist[MAX];

//頂点間の距離（コスト）
map< set<int>, int> cost;

//頂点nowからの距離がdである
void dfs(int now, long long d){
  for(auto next : tree[now-1]){
    //訪問済みなら次の頂点へ
    if(visit[next-1] == true)
      continue;

    //nextを訪問済みにし，距離を計算
    visit[next-1] = true;
    dist[next-1] = d + cost[{now, next}];

    //再帰的にDFS
    dfs(next, dist[next-1]);
  }
}


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

  //treeの作成
  int a, b, c;
  rep(i, N-1){
    cin >> a >> b >> c;
    tree[a-1].push_back(b);
    tree[b-1].push_back(a);
    cost[{a, b}] = c;
  }

  int Q, K;
  cin >> Q >> K;

  //頂点Kを探索済みにする
  visit[K-1] = true;
  
  //最短経路探索
  dfs(K, 0);

  //クエリ処理
  int x, y;
  rep(i, Q){
    cin >> x >> y;
    //頂点x -> K -> yの最短距離を考えればよい
    cout << dist[x-1] + dist[y-1] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 48548
#include <stdio.h>
#define MAX 128

char stack[MAX];

int main(void) {
    char input[MAX];
    while (1) {
        fgets(input, MAX-1, stdin);
        if (input[0] == '.') break;
        int i = 0;
        int index = 0;
        int balance = -1;
        while (1) {
            if (input[i] == '(' || input[i] == '[') {
                stack[index++] = input[i];
            } else if (input[i] == ')') {
                if(index == 0) {
                    balance = 0;
                } else if (stack[--index] != '(') {
                    balance = 0;
                }
            } else if (input[i] == ']') {
                if (index == 0) {
                    balance = 0;
                } else if (stack[--index] != '[') {
                    balance = 0;
                }
            } else if (input[i] == '.') {
                if (index == 0) {
                    balance = 1;
                } else {
                    balance = 0;
                }
            }
            if (balance != -1) break;
            i++;
        }
        if (index == 0 && balance != 0) {
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  ll c=gcd(a,b);

  if(c==1){
    cout << 1 << endl;
    return 0;
  }

  bool sosu=true;
  for(ll i=2;i*i<=c;i++){
    if(c%i==0) sosu=false;
  }
  if(sosu) {
    cout << 2 << endl;
    return 0;
  }




  ll ans=1;
  for(ll i=2;i*i<=c;i++){
    if(c%i==0){
      bool sosu=true;
      for(ll j=2;j*j<=i;j++){
        if(i%j==0) sosu=false;
      }
      if(sosu) ans++;
      
      if(i!=c/i){
        bool sosu=true;
        for(ll j=2;j*j<=(c/i);j++){
          if((c/i)%j==0) sosu=false;
        }
        if(sosu) ans++;
      }
    }
  }

  cout << ans << endl;
}

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

int main() {
    string S;
    cin >> S;
    int a = -1, b = -1;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'A') {
            a = i;
            break;
        }
    }
    for (int i = (int)S.length()-1; i >= 0; i--) {
        if (S[i] == 'Z') {
            b = i;
            break;
        }
    }
    
    cout << b-a+1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int a, b;
	cin >> a >> b;
	if(a==b)
		cout << "Draw";
	else if (a == 1)
		cout << "Alice";
	else if(b == 1)
		cout << "Bob";
	else
	{
		if (a > b)
			cout << "Alice";
		else if (b > a)
			cout << "Bob";
	}
}


Measured memory_bytes: 3652
// https://onlinejudge.u-aizu.ac.jp/beta/room.html#KUPC2020Spring/problems/B
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

struct Dice {
    // Left, Right, Front, Back, Down, Up
    int l, r, f, b, d, u;
    bool operator<(const Dice &rhs) const {
        return l * 10 + r > rhs.l * 10 + rhs.r;
    }

    // y軸方向にプラス
    void RollN() {
        // ++y;
        int buff = d;
        d = b;
        b = u;
        u = f;
        f = buff;
    }

    // y軸方向にマイナス
    void RollS() {
        //  --y;
        int buff = d;
        d = f;
        f = u;
        u = b;
        b = buff;
    }

    // x軸方向にプラス
    void RollE() {
        // ++x;
        int buff = d;
        d = r;
        r = u;
        u = l;
        l = buff;
    }

    // x軸方向にマイナス
    void RollW() {
        // --x;
        int buff = d;
        d = l;
        l = u;
        u = r;
        r = buff;
    }

    // 90度→方向に回転
    void RollL() {
        // ----->
        int buff = f;
        f = l;
        l = b;
        b = r;
        r = buff;
    }

    // 90度←方向に回転
    void RollR() {
        // <------
        int buff = f;
        f = r;
        r = b;
        b = l;
        l = buff;
    }
};

struct dir {
    int y, x;
    Dice dice;
};

int H, W;
queue<dir> q;
vector<set<Dice>> st;
void qin(int y, int x, Dice d) {
    if (st[y * W + x].count(d) == 0) {
        q.push({y, x, d});
        st[y * W + x].insert(d);
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> H >> W;
    vector<string> v(H);
    for (auto &x : v) {
        cin >> x;
    }
    auto dice = Dice();
    dice.u = 1;
    dice.f = 2;
    dice.r = 3;
    dice.l = 4;
    dice.b = 5;
    dice.d = 6;

    st.resize(H * W);
    // Y座標、X座標
    q.push({0, 0, dice});
    while (!q.empty()) {
        auto t = q.front();
        q.pop();
        if (t.y == H - 1 && t.x == W - 1) {
            cout << "YES\n";
            return 0;
        }
        if (t.y < H - 1) {
            auto u = t.dice;
            u.RollS();
            if (u.d == v[t.y + 1][t.x] - '0') {
                qin(t.y + 1, t.x, u);
            }
        }
        if (t.y > 0) {
            auto u = t.dice;
            u.RollN();
            if (u.d == v[t.y - 1][t.x] - '0') {
                qin(t.y - 1, t.x, u);
            }
        }
        if (t.x < W - 1) {
            auto u = t.dice;
            u.RollE();
            if (u.d == v[t.y][t.x + 1] - '0') {
                qin(t.y, t.x + 1, u);
            }
        }
        if (t.x > 0) {
            auto u = t.dice;
            u.RollW();
            if (u.d == v[t.y][t.x - 1] - '0') {
                qin(t.y, t.x - 1, u);
            }
        }
    }
    cout << "NO\n";

    return 0;
}



Measured memory_bytes: 3928
N = int(input())
coords, minus, plus = [], [], []
for _ in range(N):
    x, y = map(int,input().split())
    coords.append([x,y])
    minus.append(x-y)
    plus.append(x+y)

minus.sort()
plus.sort()

ans = 0
for x, y in coords:
    now_minus, now_plus = x-y, x+y
    ans = max(ans, abs(now_minus-minus[0]), abs(now_minus-minus[-1]))
    ans = max(ans, abs(now_plus-plus[0]), abs(now_plus-plus[-1]))

print(ans)

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

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			final int MOD = 1000000007;
			int s = sc.nextInt();

			long[][] dp = new long[s / 3 + 1 + 1][s + 1];

			Arrays.fill(dp[0], 1);

			for (int i = 1; i < dp.length; i++) {
				for (int j = 3; j < dp[i].length; j++) {
					dp[i][j] = dp[i - 1][j - 3];

				}

				//累積和を取る
				long sum = 0;
				for (int j = 0; j < dp[i].length; j++) {
					sum = m_add(sum, dp[i][j], MOD);
					dp[i][j] = sum;
				}

			}

			long result = 0;
			for (int i = 0; i < dp.length; i++) {
				long diff = m_sub(dp[i][s], dp[i][s - 1], MOD);
				result = m_add(result, diff, MOD);
			}

			System.out.println(result);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static long m_add(long a, long b, int MOD) {
		return ((a + b) % MOD);
	}

	public static long m_sub(long a, long b, int MOD) {
		long value = (a - b) % MOD;
		if (value < 0) {
			value += MOD;
		}
		return value;
	}

}

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

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;
using LL = long long;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

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

	if (h % a != 0)cout << h / a + 1;
	else cout << h / a;
}

Measured memory_bytes: 256
def g_solve(N, A, B, C):
  seq = []
  for _ in range(N):
    s = input()
    if s == 'AB':
      if A > B:
        A -= 1
        B += 1
        seq.append('B')
      else:
        A += 1
        B -= 1
        seq.append('A')
    elif s == 'AC':
      if A > C:
        A -= 1
        C += 1
        seq.append('C')
      else:
        A += 1
        C -= 1
        seq.append('A')
    elif s == 'BC':
      if B > C:
        B -= 1
        C += 1
        seq.append('C')
      else:
        B += 1
        C -= 1
        seq.append('B')
    if A < 0 or B < 0 or C < 0:
      print('No')
      return
  print('Yes')
  print('\n'.join(seq))    


def dp_solve(N, a,b,c):
  state = {}
  state[(a, b, c)] = []
  for _ in range(N):
    s = input()
    next_state = {}
    for a, b, c in state:
      if s == 'AB':
        if b-1 >= 0:
            next_state[(a+1, b-1, c)] = ['A', state[(a,b,c)]]
        if a-1 >= 0:
          next_state[(a-1, b+1, c)] = ['B', state[(a,b,c)]]
      if s == 'AC':
        if c-1 >= 0:
          next_state[(a+1, b, c-1)] = ['A', state[(a,b,c)]]
        if a-1 >= 0:
          next_state[(a-1, b, c+1)] = ['C', state[(a,b,c)]]
      if s == 'BC':
        if c-1 >= 0:
          next_state[(a, b+1, c-1)] = ['B', state[(a,b,c)]]
        if b-1 >= 0:
          next_state[(a, b-1, c+1)] = ['C', state[(a,b,c)]]
    state = next_state
    if not state:
      print('No')
      return
    
  print('Yes')
  ans = []
  seq = list(state.values())[0]
  while seq:
    ans.append(seq[0])
    
    seq = seq[1]
  ans.reverse()
  for a in ans:
    print(a)
    
  
  
N, A, B, C = [int(x) for x in input().split(' ')]
if A + B + C < 20:
  dp_solve(N, A, B, C)
else:
  g_solve(N, A, B, C)


Measured memory_bytes: 17644
s=input()
q=int(input())
order=1
header=''
footer=''
for _ in range(q):
  tmp=input()
  if tmp=='1':
    order*=-1
  else:
    t, f, c=tmp.split()
    if (int(f)*order)%3==1:
      header=c+header
    else:
      footer=footer+c
s=header+s+footer
print(s) if order==1 else print(s[::-1])

Measured memory_bytes: 4596
/*
 It's better to sleep happy and tired rather than disappointed and frustrated
 There's only 1 thing that's impossible and that is defeating a man who doesn't give up
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

const int inf=0x3f3f3f3f;
int n,m , ans , sum , a , b ,dp[3*mx3][3*mx3];
string s , t;

string solve(int i , int j)
{
	string res;
	if(i<=0 || j<=0)
	{
		return res;
	}
	
	if(s[i-1]==t[j-1])
	{
		res=solve(i-1,j-1);
		res+=s[i-1];
		return res;
	}
	else if(dp[i-1][j]>dp[i][j-1])
	{
		res=solve(i-1,j);
		return res;
	}
	else
	{
		res=solve(i,j-1);
		return res;
	}
	
	
}
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>s>>t;
		n=s.length();
		m=t.length();
		Fo(i,1,n+1)
		{
			Fo(j,1,m+1)
			{
				if(s[i-1]==t[j-1])
				{
					dp[i][j]=1+dp[i-1][j-1];
				}
				else
				{
					dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				}
			}
		}
		cout<<solve(n,m);
	}
	return 0;
}


Measured memory_bytes: 36224
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    vector<int>vec(3);
    cin >> vec[0];
    cin >> vec[1];
    cin >> vec[2];
    sort(vec.begin(),vec.end());
    if(vec[2]-vec[0]%2 == vec[2]-vec[1]%2) {
        cout << (vec[2]-vec[1]+vec[2]-vec[0])/2 << endl;
    }
    else {
        cout << 1+(vec[2]-vec[1]+vec[2]-vec[0]+1)/2 << endl;
    }
}



Measured memory_bytes: 256
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (a, b, c): (i64, i64, i64) = parse!(it, 3);
    println!("{} {} {}", c, a, b);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Char

main :: IO ()
main = do
  n :: Int <- readLn :: IO Int
  if n == -1
    then return ()
    else do
      putStrLn $ solve n
      main


tenToFour :: Int -> [Int]
tenToFour n = unko n []
  where unko n ls
          | n < 4 = n:ls
          | otherwise = unko (n `div` 4) ((n `mod` 4):ls)

intToStr :: [Int] -> String
intToStr = map numa
  where numa i = chr (i + (ord '0'))

solve :: Int -> String
solve = intToStr . tenToFour

Measured memory_bytes: 4076
$n = gets.to_i
$ans = 0

(1..9).each do|k|
  def sub(q, k)
    if q.size == k
      return if not q.include?(3) or not q.include?(5) or not q.include?(7)
      m = q.map{|i| i.to_s}.join('').to_i
      if m <= $n
        $ans += 1
      end
    else
      sub(q + [3], k)
      sub(q + [5], k)
      sub(q + [7], k)
    end
  end
  sub([], k)
end

p $ans


Measured memory_bytes: 3964
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  cout << min(A, B);

  cout << " ";

  if (N >= A + B) {
    cout << 0 << endl;
  } else {
    cout << A + B - N << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;

int main() {
    string s;
    cin >> s;
    if ((s.front() == s.back()) ^ (s.size() % 2)) {
        cout << "First" << endl;
    } else {
        cout << "Second" << endl;
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	string s;cin >> s;
	int n= s.size();
	int tmp = 0;
	rep(i,n){
		tmp += s[i] - '0';
	}
	cout << (tmp%9 == 0?"Yes":"No" ) <<endl;
	return 0;
}

Measured memory_bytes: 3724
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    ll n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    reverse(ALL(s));

    // mem : '1'の最大連続数
    ll mem = 0, b = 0;
    vll a(n + 1);
    REP(i, n + 1) {
        a[i] = int(s[i] - '0');
        if (a[i] == 1) b++;
        else {
            chmax(mem, b);
            b = 0;
        }
    }

    // 到達不可能
    if (mem >= m) {
        cout << -1 << endl;
        return 0;
    }

    // res : 各ターンで出すべき目
    // cur : 現在地
    vll res;
    ll cur = 0;

    while (cur != n) {
        // dice : このターン出すべき目
        ll dice = min(m, n - cur);
        while (a[cur + dice] != 0) dice--;
        cur += dice;
        res.push_back(dice);
    }
    reverse(ALL(res));
    for (auto x : res) {
        cout << x << " ";
    }
    return 0;
}

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

typedef long long ll;

const int N = 305;

int n, K, mod, C[N][N], S[N][N], F[N][N];

int main()
{
	scanf("%d%d%d", &n, &K, &mod);
	for (int i = 0; i <= max(n, K); i++)
	{
		C[i][0] = 1;
		for (int j = 1; j <= i; j++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
	}
	F[0][0] = 1;
	for (int i = K; i >= 0; i--)
	{
		F[1][i] = 1;
		S[1][i] = (S[1][i + 1] + 1) % mod;
	}
	for (int i = 2; i <= n + 1; i++)
	{
		for (int j = 0; j <= K; j++)
			for (int a = 1; a < i; a++)
				F[i][j] = (F[i][j] + (ll)F[i - a][j] * S[a][j + 1] % mod * C[i - 2][a - 1] % mod) % mod;
		for (int j = K; j >= 0; j--)
			S[i][j] = (S[i][j + 1] + F[i][j]) % mod;
	}
	printf("%d\n", F[n + 1][0]);
	return 0;
}

Measured memory_bytes: 4856
use std::io;
use std::io::prelude::*;

fn main() {
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let uline = line.unwrap();
        let vec: Vec<&str> = uline.split_whitespace().collect();
        let a: i32 = vec[0].parse().unwrap_or(0);
        let o: &str = vec[1];
        let b: i32 = vec[2].parse().unwrap_or(0);
        if o == "?" {
            break;
        } else if o == "+" {
            println!("{}", a + b);
        } else if o == "-" {
            println!("{}", a - b);
        } else if o == "*" {
            println!("{}", a * b);
        } else if o == "/" {
            println!("{}", a / b);
        }
    }
}


Measured memory_bytes: 5032
S = input()
if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();
		int[] w = new int[n];

		long r = 0;
		long l = 0;
		
		for (int i = 0; i < n; i++) {
			w[i] = scan.nextInt();	
			r += w[i];
			l = Math.max(l, w[i]);
		}

		// 二分探索
		while (l < r) {
			// 現在試している積載量p
			long m = (l + r) / 2;
			// 各トラックの搭載量
			long sum = 0;
			// 現在荷物を載せているトラックのid
			int kId = 0;
			
			// 全荷物を載せていく
			for (int i = 0; i < n; i++) {
				// 荷物を載せるとpを超えるようなら次のトラックへ
				if (sum + w[i] > m) {
					sum = w[i];
					kId++;
				}
				else {
					sum += w[i];
				}

				// トラックの数がkを超えるようなら終了
				if (kId == k) {
					break;
				}
			}
			
			// pで積載可能ならばpを小さくする
			if (kId != k) {
				r = m;
			}
			else {
				l = m + 1;
			}
		}

		System.out.println(l);

		scan.close();
	}
}

Measured memory_bytes: 64756
#include<bits/stdc++.h>
#define M   1000000007
#define lli long long int
using namespace std;

class Query
{
public:
    int l,r,id;
    inline Query(int a,int b,int i)
    {
        l=a,r=b,id=i;
    }
};
int block=0;
int unik;
bool cmp(const Query a,const Query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block < b.l/block;
    return (a.l/block)&1?a.r < b.r:a.r>b.r ;
}

int arr[500007];
int freq[500007];
vector<Query>all;
int ans[500007];

void add(int d){ freq[arr[d]]++; if(freq[arr[d]]==1) unik++; }
void del(int d){ freq[arr[d]]--; if(freq[arr[d]]==0) unik--; }

int main()
{
    int n,i,j,k,p,q,l,r;

    scanf("%d %d",&n,&q);

    for(i=1;i<=n;i++) scanf("%d",&arr[i]);

    for(i=1;i<=q;i++)
    {
        scanf("%d %d",&l,&r);
        all.push_back(Query(l,r,i));
    }

    block=sqrt(n)+1;
    sort(all.begin(),all.end(),cmp);

    int cur_l=1,cur_r=0;
    for(i=0;i<q;i++)
    {
        l=all[i].l,r=all[i].r;
        while(cur_l>l) { cur_l--; add(cur_l); }
        while(cur_l<l) { cur_l++; del(cur_l-1); }
        while(cur_r>r) { cur_r--; del(cur_r+1); }
        while(cur_r<r) { cur_r++; add(cur_r); }

        ans[all[i].id]=unik;
    }

    for(i=1;i<=q;i++)
        printf("%d\n",ans[i]);

    return 0;
}



Measured memory_bytes: 15620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int L;
  cin>>L;
  L--;
  int LL=L;
  VI X(21);
  rep(i,21){
    X[i]=L&1;
    L>>=1;
  }
  int cnt=0;
  rep(i,21) if(X[i]) cnt++;
  int N=0;
  rep(i,21) if(X[i]) N=i+1;
  vector<tuple<int,int,int>> P(0);
  if(N==cnt) N++;
  rep(i,N-1){
    P.pb(mt(i+1,i+2,(1<<i)));
    P.pb(mt(i+1,i+2,0));
  }
  int tmp=(1<<(N-1));
  rep(i,N-1){
    if((1<<(N-2-i))+tmp-1<=LL){
      P.pb(mt(N-1-i,N,tmp));
      tmp+=(1<<(N-2-i));
    }
  }
  cout<<N<<" "<<P.size()<<endl;
  rep(i,P.size()) cout<<get<0>(P[i])<<" "<<get<1>(P[i])<<" "<<get<2>(P[i])<<endl;
}

Measured memory_bytes: 256
w=[]
N=int(input())
for i in range(N):
    A,B=map(int,input().split())
    w.append([A,B])
w.sort(key=lambda x:x[1])

flag=True
time=0
for work in w:
    time+=work[0]
    if time>work[1]:
        flag=False
        break
print('Yes' if flag else 'No')

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

using ll = long long;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        A[i]--;  // 0-indexed に変更
    }

    int logK = 1;
    while ((1LL << logK) < K) logK++;
    // doubling[k][i] : i番目から 2^k 進んだ町
    vector<vector<int> > doubling(logK, vector<int>(N));
    for (int i = 0; i < N; i++) {
        doubling[0][i] = A[i];
    }

    // 前処理 doubling の計算
    for (int k = 0; k < logK - 1; k++) {
        for (int i = 0; i < N; i++) {
            doubling[k + 1][i] = doubling[k][doubling[k][i]];
        }
    }

    int now = 0;
    for (int k = 0; K > 0; k++) {
        if (K & 1) now = doubling[k][now];
        K = K >> 1;
    }
    cout << now + 1 << endl;
}


Measured memory_bytes: 51832
using System;
using System.Collections.Generic;

namespace cswork
{

    class Program
    {
        public Program() { }

        Scanner cin;

        void Omame()
        {
            cin = new Scanner();

            long n = cin.nextLong();
            int ans = int.MaxValue;
            for (long i = 1; i <= Math.Pow(n, 0.5); i++)
            {
                if (n % i == 0)
                {
                    int fab = Math.Max(i.ToString().Length, (n / i).ToString().Length);

                    if (fab < ans)
                    {
                        ans = fab;
                    }
                }
            }

            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int n, r; scanf("%d%d", &n, &r);
	int ans;
	if(n >= 10) ans = r;
	else ans = r + 100 * (10 - n);
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    for(auto& x: A) cin >> x;
    sort(A.begin(), A.end());

    bool ok = true;
    for(int i=0; i<N-1; i++){
        if(A[i] == A[i+1]) ok = false;
    }

    if(ok){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
}

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

int main() { 
    long A,B,C;
	cin >> A >> B >> C;

    long ansA = A;
    long ansB = B;
    if (A >= C) {
        ansA = A - C;
    } else if ((A + B) >= C ) {
        ansA = 0;
        ansB = B - (C - A);
    } else {
        ansA = 0;
        ansB = 0;
    }
    cout << ansA << " " << ansB << endl;
	return 0;
}

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

int main(void){
   
    int n;
    string str;
    
    int x=0;
    int mv=0;
    
    cin>>n;
    cin>>str;
    for(int i=0; i<str.size(); i++){
        if(str[i]=='I'){
            x++;
            mv=max(mv,x);
        }else if(str[i]=='D'){
            x--;
        }
    }
    
    cout<<mv<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

constexpr double EPS = 1e-7;
constexpr int INF = 1e9;
#define PI (acos(-1))

constexpr int MOD = 1e9 + 7;

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int H, A;
	cin >> H >> A;
	if (H % A == 0) {
		cout << H / A << endl;
	} else {
		cout << H / A + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  int n,k;
  cin >> n >> k;
  int d;
  vector<int>a(d),cnt(n+1);//すぬけくんnの持ってる個数
  rep(i,k){
    cin >> d;
    rep(i,d){
      cin >> a[i];
      cnt[ a[i] ]++;
    }
  }
  int ans = 0;
  rep1(i,n){
    if(cnt[i] == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3760
#include<cstdio>
#include<iostream>
using namespace std;
int n;
int k,a,b;
char s[2];
int ans=0;
int sum[2010][2010][2];
int t1,t2;
int qzh(int x1,int ckw,int x2,int y2,bool p)
{
	if (x1<0||ckw<0||x2<0||y2<0) return 0;
	if (x1==0&&ckw==0) return sum[x2][y2][p];
	if (x1==0) return sum[x2][y2][p]-sum[x2][ckw-1][p];
	if (ckw==0) return sum[x2][y2][p]-sum[x1-1][y2][p];
	return sum[x2][y2][p]-sum[x2][ckw-1][p]-sum[x1-1][y2][p]+sum[x1-1][ckw-1][p];
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d%s",&a,&b,s);
		if (s[0]=='B') sum[a%(2*k)][b%(2*k)][1]++;
		else sum[a%(2*k)][b%(2*k)][0]++;
	}
	for (int i=1;i<2*k;i++)
	{
		sum[i][0][0]+=sum[i-1][0][0];sum[0][i][0]+=sum[0][i-1][0];
		sum[i][0][1]+=sum[i-1][0][1];sum[0][i][1]+=sum[0][i-1][1];
	}
	for (int i=1;i<2*k;i++)
		for (int j=1;j<2*k;j++)
		{
			sum[i][j][0]+=sum[i-1][j][0]+sum[i][j-1][0]-sum[i-1][j-1][0];
			sum[i][j][1]+=sum[i-1][j][1]+sum[i][j-1][1]-sum[i-1][j-1][1];
		}
	for (int i=0;i<k;i++)
		for (int j=0;j<k;j++)
		{
			t1=qzh(0,0,i-1,j-1,0)+qzh(i,j,i+k-1,j+k-1,0)+qzh(i+k,j+k,2*k-1,2*k-1,0)+qzh(0,j+k,i-1,2*k-1,0)+qzh(i+k,0,2*k-1,j-1,0)+qzh(i,0,i+k-1,j-1,1)+qzh(0,j,i-1,j+k-1,1)+qzh(i+k,j,2*k-1,j+k-1,1)+qzh(i,j+k,i+k-1,2*k-1,1);
			t2=qzh(0,0,i-1,j-1,1)+qzh(i,j,i+k-1,j+k-1,1)+qzh(i+k,j+k,2*k-1,2*k-1,1)+qzh(0,j+k,i-1,2*k-1,1)+qzh(i+k,0,2*k-1,j-1,1)+qzh(i,0,i+k-1,j-1,0)+qzh(0,j,i-1,j+k-1,0)+qzh(i+k,j,2*k-1,j+k-1,0)+qzh(i,j+k,i+k-1,2*k-1,0);
			ans=max(ans,max(t1,t2));
		}
	printf("%d",ans);
}

Measured memory_bytes: 31616
#include"iostream"

using namespace std;

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

    if (a > 12) {
        cout << b << endl;
    }
    else if (a < 6) {
        cout << 0 << endl;
    }
    else {
        cout << b / 2 << endl;
    }

  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int mod=1e9+7;
const int N=2e5+5;
ll po(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod,b>>=1;
	}
	return ans;
}
ll inv(ll x){return po(x,mod-2);}
ll jc[N<<1],jcinv[N<<1];
inline ll c(ll a,ll b)
{return jc[a]*jcinv[b]%mod*jcinv[a-b]%mod;}



int n;
struct Edge{
	int nxt,to;
}e[N<<1];
int cnt=1,head[N];
void inline add(int u,int v)
{
	e[cnt]={head[u],v};
	head[u]=cnt++;
}

ll sz[N];//子树大小
ll f[N];//走完子树的方法数
ll ans[N];
void dfs1(int u,int fa)
{
	f[u]=1;
	for(int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].to;
		if(v==fa) continue;
		dfs1(v,u);
		sz[u]+=sz[v];
		f[u]=f[u]*c(sz[u],sz[v])%mod*f[v]%mod;
	}
	sz[u]++;
}
void dfs2(int u,int fa,ll ffa)
{
	ans[u]=f[u]*c(n-1,n-sz[u])%mod*ffa%mod;
	for(int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].to;
		if(v==fa) continue;
		dfs2(v,u,ans[u]*inv(f[v])%mod*inv(c(n-1,sz[v]))%mod);
	}
}

int main()
{
	jc[0]=jcinv[0]=jc[1]=jcinv[1]=1;
	for(int i=2;i<(N<<1);i++)
	{
		jc[i]=jc[i-1]*i%mod;
		jcinv[i]=po(jc[i],mod-2);
	}
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs1(1,0);
	dfs2(1,0,1);
	for(int i=1;i<=n;i++)
	{
		printf("%lld\n",ans[i]);
	}
	return 0;
}


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


int main(){

    int A[3];
    for( int i = 0; i < 3; i++ ) cin >> A[i];


    int diff[3];
    for( int i = 0; i < 3; i++ ){
        int next = ( i==2 ) ? 0 : i+1;
        diff[i] = abs( A[next] - A[i] );
    }
    
    sort( diff, diff+3 );
    
    cout << diff[0] + diff[1] << endl;

    return 0;

}

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

struct UnionFind{
    
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int N): par(N+1), rank(N+1)  {
        for(int i = 0; i < N;i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int find(int x){
        if(par[x]==x)return x;
        else return par[x] = find(par[x]);
    }
    
    void unite(int x,int y){
        x = find(x);
        y = find(y);
        if(x == y)return;
        
        if(rank[x]<rank[y]){
            par[x] = y;

        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }

    }
    
    bool same(int x,int y){
        return find(x) == find(y);
    }
    
};

int main(void){
    
    int N,K,L;
    cin >> N >> K >> L;
    
    UnionFind route(N);
    UnionFind train(N);
    
    int p,q;
    for(int i = 0; i < K;i++){
        cin >> p >> q;
        p--;
        q--;
        route.unite(p,q);
    }
    
    int r,s;
    for(int i = 0; i < L;i++){
        cin >> r >> s;
        r--;
        s--;
        train.unite(r,s);
    }
    
    using pint = pair<int,int>;
    map<pint,int> mp;
    
    for(int i = 0; i < N;i++){
        pint p(route.find(i),train.find(i));
        mp[p]++;
    }
    
    for(int i = 0; i < N;i++){
        pint p(route.find(i),train.find(i));
        cout << mp[p] <<" ";
    }
    
    
    
}


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

int main(){
  int A[3];
  int K;
  for (int i=0;i<3;i++) cin>>A[i];
  cin>>K;
  sort(A,A+3);
  for(int i=0;i<K;i++) A[2]*=2;
  cout<<A[0]+A[1]+A[2];

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

   int i,j,tmp;
   
   int number[100];
   
   for(i=0;i<3;++i){
      scanf("%d", &number[i]);
      }
   
   for(i=0;i<3;++i){
      for(j=i+1;j<3;++j){
         if(number[i]>number[j]){
            tmp = number[i];
            number[i] = number[j];
            number[j] = tmp;
      }}}
         
   i = 0;
	
      printf("%d %d %d\n", number[i],number[i+1],number[i+2]);
   
   return 0;
}


Measured memory_bytes: 2092
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        long x = sc.NextInt();

        var ans = (x / 500) * 1000;
        x %= 500;
        ans += (x / 5)*5;
        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;



int main(){
	cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    if (n%2 != 0){
        cout << 0;
        return 0;
    }
    n /= 2;
    ll base = 5;
    ll ans = 0;
    while(base <= n){
        ans += n / base;
        base *= 5;
    }
    cout << ans;

    return 0;
    
}



Measured memory_bytes: 256
n, m = map(int, input().split())
lst = [x for x in range(n)]
dic = {}
not_found = False
special_case = False
for i in range(m):
    a, b = map(int, input().split())
    if str(a) not in list(dic.keys()):
        dic[str(a)] = b
    else:
        if dic[str(a)] != b:
            not_found = True
    lst[a - 1] = b
if m == 0:
    special_case = True
if not_found:
    print(-1)
elif special_case:
    if n == 1:
        print(0)
    elif n == 2:
        print(10)
    else:
        print(100)
else:
    for i in range(n):
        if str(i + 1) not in list(dic.keys()):
            if i + 1 == 1:
                lst[i] = 1
            else:
                lst[i] = 0
    lst = list(map(str, lst))
    res = ''.join(lst)
    if res[0] == '0' and len(res) > 1:
        print(-1)
    else:
        print(int(res))

Measured memory_bytes: 3188
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  when (n /= 0) $ do
    xs <- getl $ split toInt
    solve 0 xs
    main

solve :: Int -> [Int] -> IO ()
solve n xs
  | oxs == xs = print n >> putStrLn (toStr xs)
  | otherwise = solve (n+1) oxs
  where
    oxs = opefreapp xs
    toStr = unwords . map show
    
opefreapp :: [Int] -> [Int]
opefreapp xs = foldr f [] xs
  where
    f n ls = let m = (length . filter (== n)) xs in m : ls

toInt :: String -> Int
toInt s = read s

split :: (String -> a) -> String -> [a]
split f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4092
from collections import deque

INF = 100000000

# 入力
N, M = map(int, input().split())

maze = [[] for i in range(N)]
for i in range(M):
    ai,bi = map(int,input().split())
    maze[ai-1].append(bi-1)
    maze[bi-1].append(ai-1)


# たどりつけないとINF

def bfs(N,M,maze):
    que = deque([])
    # 全ての点をINFで初期化
    d = [INF for i in range(N)]

    # スタート地点をキューに入れ、その点の距離を0にする
    que.append(0)
    d[0] = 0

    # キューが空になるまでループ
    while len(que) > 0:
        # キューの先頭を取り出す
        p = que.popleft()
        # 移動4方向をループ
        for i in maze[p]:
            # 移動が可能化の判定とすでに訪れたことがあるかの判定
            if d[i] == INF:
                que.append(i)
                d[i] = p
    
    return d
res = bfs(N,M,maze)

for i in range(N):
    if i == INF:
        print('No')
        exit()
print('Yes')
for i in range(N-1):
    print(res[i+1]+1)


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

const int MAX_PRIME = 2000000;
vector<int> primes;
vector<bool> is_prime;
void init_primes() {
  is_prime = vector<bool>(MAX_PRIME + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= MAX_PRIME; i++) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = i*2; j <= MAX_PRIME; j+=i) {
        is_prime[j] = false;
      }
    }
  }
}
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  init_primes();

  int x;cin>>x;

  for(auto p : primes) {
    if(p>=x){
      cout<<p<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1656