akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

type Q struct {
	pq *PriorityQueue
	ds map[int]int // It has always same value as pq. For random access.
}

func newQ() *Q {
	pq := new(PriorityQueue)
	heap.Init(pq)
	return &Q{
		pq: pq,
		ds: make(map[int]int),
	}
}
func (q *Q) pop() (u, d int) {
	item := heap.Pop(q.pq).(*Item)
	delete(q.ds, item.value)
	return item.value, item.priority
}
func (q *Q) get(u int) (int, bool) { // returns d
	d, ok := q.ds[u]
	return d, ok
}
func (q *Q) set(u, d int) {
	q.ds[u] = d
	for _, item := range *q.pq {
		if item.value != u {
			continue
		}

		item.priority = d
		heap.Fix(q.pq, item.index)
		return
	}
	heap.Push(q.pq, &Item{
		priority: d,
		value:    u,
	})
}
func (q *Q) len() int {
	return len(q.ds)
}

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := newQ()
	q.set(0, 0)
	visited := make(map[int]struct{})
	out := make([]int, n)

	for q.len() > 0 {
		u, d := q.pop()
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			dd := d + c
			if d, ok := q.get(uu); !ok || d > dd {
				q.set(uu, dd)
			}
		}

		out[u] = d
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}



Measured memory_bytes: 30968
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

int main()
{
    int n;cin>>n;
    vector<int> v(n);

    for(int i=0;i<n;++i) cin>>v[i];

    sort(v.begin(),v.end(),greater<int>());

    ll sum=v[0];

    int x=1;
    int y=2;
    while(y<n){
        if(n-1-y >=2) sum+=(2*v[x]),y+=2,x++;
        else sum+=v[x],y++;
    }
    cout<<sum;

}

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

int main() {
  int N;
  string S;
  cin>>S;
  N=S.size();
  int a;
  a=0;
  for(int i=0;i<=N-1;i++){
    if(S[i]=='0'){
      a+=1;}
  }
  cout<<2*min(a,N-a)<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


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

int main() {
    int x,n;
    cin >> x >> n;
    vector<int> p(n);
    REP(i,n){
        cin >> p[i];
    }
    int mi = 100;
    int ans = 1000;
    sort(p.begin(),p.end());
    FOR(i,-100,102){
        if(abs(i - x) < mi){
            if(upper_bound(p.begin(),p.end(),i) == lower_bound(p.begin(),p.end(),i)){
                ans = i;
                mi = abs(i - x);
            }
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 3628
#include <iostream>
#include <string>

int main()
{
    int inning_num;
    std::cin >> inning_num;
    
    std::string ev[] = {"HIT", "OUT", "HOMERUN"};
    
    while (inning_num--) {
        std::string s;
        int out = 0;
        int state = 0;
        int runner = 0;
        int point = 0;
        
        while (out < 3) {
            std::cin >> s;
            
            if (ev[0] == s) {
                state = state << 1;
                state++;
                
                if (state & (1 << 3)) {
                    point++;
                }else {
                    runner++;
                }
            } else if (ev[1] == s) {
                out++;
            } else {
                point += ++runner;
                runner = 0;
                state = 0;
            }
        }
        
        std::cout << point << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<vector>

using namespace std;

int main()
{
  int N;
  cin >> N;
  cin.get();  // advance line

//int A[N];
  vector<int> A(N);

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

  for (int k = 0; k < N; ++k) {
    if (k > 0) cout << " ";
    cout << A[k];
  }
  cout << endl;

  for (int i = 1; i < N; ++i) {
    int key = A[i];
    int j=i-1;
    for (; j>=0 and A[j]>key; --j)
      A[j+1]=A[j];
    A[j+1]=key;

    for (int k = 0; k < N; ++k) {
      if (k > 0) cout << " ";
      cout << A[k];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3088
#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>;
const double PI=acos(-1);

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    char turn = 'a';
    int Acards = 0, Bcards = 0, Ccards = 0;

    while(1){
        if(turn == 'a'){
            if(Acards==a.size()) {
                cout << "A" << endl;
                break;
            }
            turn = a[Acards];
            Acards++;
        }
        if(turn == 'b'){
            if(Bcards==b.size()) {
                cout << "B" << endl;
                break;
            }
            turn = b[Bcards];
            Bcards++;
        }
          if(turn == 'c'){
            if(Ccards==c.size()) {
                cout << "C" << endl;
                break;
            }
            turn = c[Ccards];
            Ccards++;
        }
    }


    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N=50005;
int main()
{
    double l;
    scanf("%lf",&l);
    double x=l/3;
    if(x+x+x==l)
    printf("%.6lf\n",x*x*x);
    else
    printf("%.6lf\n",x*x*(x+0.1));
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

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

  vector<int> v;
  SV(2 * n,v);

  sort(ALL(v), greater<int>());
  
  int ans = 0;
  REP(i,n){
    ans += v[i * 2 + 1];
  }

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



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

int L[20];
int main()
{
    int n; cin>>n;
    for(int i=0; i<n; ++i) cin>>L[i];
    sort(L, L+n);
    for(int i=0; i<n-1; ++i) L[n-1]-=L[i];
    cout<<(L[n-1]<0 ? "Yes" : "No")<<endl;
}


Measured memory_bytes: 256
a,b,i,j,N,p,P,t[36],c[36],T[36],C[36];
Q(int*a,int*b){
    for(i=0;i<N;printf("%c%d%s",a[i],b[i],i==N-1?"\n":" "),i++);
}
B(){
    for(i=0;i<N;i++)
    for(j=N-1;j>0;j--)
        if(t[j-1]>t[j]){
            t[j]^=t[j-1]^=t[j]^=t[j-1];
            c[j]^=c[j-1]^=c[j]^=c[j-1];
        }
    Q(c,t);
    puts("Stable");
}
S(){
    for(i=0;i<N;i++){
        for(j=p=i;j<N;j++)if(T[j]<T[p])p=j;
        P=T[p];T[p]=T[i];T[i]=P;
        P=C[p];C[p]=C[i];C[i]=P;
    }
    Q(C,T);
    for(i=p=0;i<N;i++)if(c[i]==C[i]&&t[i]==T[i])p++;
    puts(p==N?"Stable":"Not stable");
}

int main(){
    for(scanf("%d",&N);i<N;scanf(" %c%d",&c[i],&t[i]),T[i]=t[i],C[i]=c[i],i++);
    B();S();

}

Measured memory_bytes: 1796
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N){
  string ans = "";
  while(N>0) {
    ll r = N%26;
    N = N/26;
    if(r==0) {
      ans.insert(ans.begin(), 'z');
      N--;
    }
    else 
      ans.insert(ans.begin(), (char)('a'+r-1));      
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}



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

#define rep(i,n) for(int i = 0;i < (int)(n);i++)
#define Rep(i,n,m) for(int i = (int)(n); i < (int)(m);i++)
#define rrep(i,n) for(int i = (int)(n); i > -1;i--)

#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

template<typename T>
void swap(T*,T*);

int main()
{
    int N;cin >> N;
    int count = 0;
    int max = log10(N) + 1;
    if(max == 6)
    {
        rep(i,90000)
        {
            count++;
        }
    }
    if(max == 5)
    {
        rep(i,N - 10000 + 1)
        {
            count++;
        }
    }

    if(max >= 4)
    {
        rep(i,900)
        {
            count++;
        }
    }

    if(max == 3)
    {
        rep(i,N - 100 + 1)
        {
            count++;
        }
    }

    if(max >= 2)
    {
        rep(i,9)
        {
            count++;
        }
    }

    if(max == 1)
    {
        rep(i,N)
        {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;



int main(){
    int n; cin >> n;
    float v[n]; for(int i=0; i<n; i++) cin >> v[i];
    sort(v, v+n);

/*
    for(int i=0; i<n; i++) printf("%d ", v[i]);
    putchar('\n');
*/
    float ans = v[0];
    for(int i=1; i<n; i++){
        ans = (ans + v[i])/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000



int main(){
  while(true){
    int n;
    scanf("%d", &n);
    if(n==0) break;
    if(n==1){
      cout << "1 1" << endl;
      continue;
    }

    vector<pii> p(n);
    p[0]=mp(0,0);
    int minW=0, maxW=0, minH=0, maxH=0;

    int dx[]={-1,0,1,0}, dy[]={0,-1,0,1};
    rep(i,n-1){
      int ni, di;
      scanf("%d %d", &ni, &di);
      int nx=p[ni].first+dx[di];
      int ny=p[ni].second+dy[di];
      p[i+1]=mp(nx,ny);
      minW=min(minW,nx);
      maxW=max(maxW,nx);
      minH=min(minH,ny);
      maxH=max(maxH,ny);
    }
    cout << maxW-minW+1 << " " << maxH-minH+1 << endl;

  }
}

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

int main(){

    int N;
    cin >> N;
    vector<int> h(N);
    for(int i = 0; i < N; i++) cin >> h[i];

    vector<long long> dp(1e5+1, 1e10);
    dp[0] = 0; dp[1] = abs(h[1] - h[0]);

    for(int i = 2; i < N; i++){
        int jump1 = (dp[i - 1] + abs(h[i] - h[i - 1]));
        int jump2 = (dp[i - 2] + abs(h[i] - h[i - 2]));
        dp[i] = jump1 < jump2 ? jump1 : jump2;
    }

    cout << dp[N - 1] << endl;

    return 0;
}

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

int main() 
{
    // return cout << "No", 0;
    string s, t;
    cin >> s >> t;
    map<char, int> sm;
    map<char, int> tm;
    for (int i=0; i<s.size(); i++)
        sm[s[i]]++;
    for (int i=0; i<t.size(); i++)
        tm[t[i]]++;
    vector<int> sv;
    vector<int> tv;
    for (auto x:sm)
        sv.push_back(x.second);
    for (auto x:tm)
        tv.push_back(x.second);
    sort(sv.begin(), sv.end());
    sort(tv.begin(), tv.end());
    cout << (sv==tv?"Yes":"No");
    return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    string S;
    cin >> S;
    bool p = S[0] == 'R';
    bool q = S[1] == 'R';
    bool r = S[2] == 'R';
    if (p and q and r) {
        cout << 3 << endl;
    } else if ((p and q) or (q and r)) {
        cout << 2 << endl;
    } else if (p or q or r) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)
using namespace std;

int S[10000];
int root(int i){
    if(S[i] == i) return i;
    else return S[i] = root(S[i]);
}

int main(){
    int n,q,com,x,y;
    cin >> n >> q;
    REP(i,n){
        S[i] = i;
    }
    REP(i,q){
        cin >> com >> x >> y;
        if(com){ // same
            bool same = (root(S[x]) == root(S[y]));
            cout << same << endl;
        }
        else{ // unite
            S[root(x)] = root(y);
        }
    }
    return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define F first
#define S second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
const int N = 2e5 + 10;
const ll INF = 1LL << 60;
ll iv[N];
ll powM(ll a, ll b){ll res = 1;for(;b;a=a*a%M,b/=2) if(b&1) res=res*a%M;return res;}
ll nckbig(int n, int k){ll ans = 1;for(int i=1; i<=k; ++i){ans = ans*(n-i+1)%M*iv[i]%M;}return ans;}
void caliv(){iv[1] = 1;for(int i=2; i<N; i++){iv[i] = M-M/i*iv[M%i]%M;}}
ll f1[N], f2[N];
void calf(){f1[0] = f2[0] = 1;for(int i=2; i <N; ++i){f1[i] = f1[i-1]*i%M;f2[i] = f2[i-i]*iv[i]%M;}}
ll nck(int n, int k){return f1[n]*f2[n-k]%M*f2[k]%M;}
ll npk(int n, int k){return f1[n]*f2[n-k]%M;}
void Rnck(int big){if(big){caliv();}else{calf();}}

ll f[N*4];
vector<ll> v;
void upd(ll pos, ll val)
{
	for(int i=pos; i<N*4; i += i&-i) f[i] += val;
}

ll query(ll pos)
{
	ll res = 0;
	for(int i=pos; i>0; i -= i&-i) res += f[i];
	return res;
} 

bool check(ll m, ll sz)
{
	memset(f, 0, sizeof(f));
	ll inv = 0;
	ll n = sz;
	vector<ll> tmp(n+1);
	tmp[0] = 0;
	for(int i=0; i<n; i++)
		tmp[i+1] = tmp[i]  + (v[i] >= m?1:-1);
	for(int i=0; i<=n; i++)
	{
		ll ind = tmp[i] + N + 1;
		inv += query(ind);
		upd(ind, 1);
	} 
	ll total = (n*(n+1)) /2;
	ll obj = (total+1) /2;
	if(inv>= obj) return true;
	else return false;
}


void solve()
{
	int n;
	cin>>n;
	v.resize(n);
	for(int i=0; i<n; i++) cin>>v[i];
	ll l = 0, r = 1 << 30;
	ll ans = 0;
	while(l <= r)
	{
		ll mid = (l+r) / 2;
		if(check(mid, n)) {ans = mid, l = mid + 1;}
		else r = mid - 1;
	}
	cout<<ans<<endl;
}


int main()
{
    FAST
    ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
        solve();
    }
    return 0;
}


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

const long long mod=1000000007;

int main(int argc, char const *argv[])
{
	int n;
	long long k;
	cin>>n>>k;
	long long a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	long long ans=0LL;
	for (int i = 0; i < n; ++i)
	{
		long long d=0LL,r=0LL;
		for (int j = 0; j < n; ++j)
		{
			if (a[i]>a[j])
			{
				++d;
				if (i<j)
				{
					++r;
				}
			}
		}
		ans+=r*k;
		ans%=mod;
		long long tmp=k*(k-1LL)/2LL%mod;
		ans+=d*tmp;
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
import bisect

class Tree:
    """
    node id starts from 1
    """

    DUMMY = 0 # used as dummy_node_id and dummy_node_value

    def __init__(self, num_node, node_values):
        self.node_values = [-1] + node_values # [0] is dummy
        self.edges = [None] * (num_node + 1) # [0] is dummy, var[a] = set of links
        for i, _ in enumerate(self.edges):
            self.edges[i] = set()
        self.seq = [self.DUMMY] * num_node

        self.dp = [math.inf] * (num_node + 1)
        self.dp[0] = -1 * math.inf
        self.ans = [0] * (num_node + 1) # [0] is dummy


    def node_values(self, node_values):
        self.node_values = [-1] + node_values # [0] is dummy

    def make_edge(self, a, b):
        self.edges[a].add(b)
        self.edges[b].add(a)

    def dps(self, node_id, prev=0, depth=0):
        # process
        value = self.node_values[node_id]
        key = bisect.bisect_left(self.dp, value)
        old_value = self.dp[key]
        self.dp[key] = value
        self.ans[node_id] = max(key, self.ans[prev])
        # recursive
        for to in self.edges[node_id]:
            if to == prev:
                continue
            self.dps(to, node_id, depth + 1)
        # recursive back
        self.dp[key] = old_value

if __name__ == '__main__':
    num_node = int(input())
    node_values = list(map(int, input().split()))
    tree = Tree(num_node, node_values)
    for i in range(num_node - 1):
        frm, to = map(int, input().split())
        tree.make_edge(frm, to)
    tree.dps(1)
    for a in tree.ans[1:]:
        print(a)




Measured memory_bytes: 317032
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int dp[41][4];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	while(cin >> n,n){
		vector<int> p(n),t(n);
		for(int i=0;i<n;i++){
			cin >> p[i] >> t[i];
		}
		for(int i=0;i<41;i++){
			for(int j=0;j<4;j++){
				dp[i][j]=1e9;
			}
		}
		if(p[0]>t[0]){
			printf("NG 1\n");
			continue;
		}
		dp[0][1]=p[0];
		for(int i=1;i<n;i++){
			for(int j=0;j<4;j++){
				if(dp[i-1][j]==1e9)continue;
				if(j<3){
					int dis=abs(p[i]-p[i-1]);
					if(t[i]-t[i-1]>=dis*(j+1)){
						dp[i][j+1]=min(dp[i][j+1],dp[i-1][j]+dis);
					}
				}
				if(t[i]-t[i-1]>=(j+1)*p[i-1]+p[i]){
					dp[i][1]=min(dp[i][1],dp[i-1][j]+p[i]+p[i-1]);
				}
			}
		}
		int r=1;
		while(r<n){
			bool ok=0;
			for(int i=0;i<4;i++){
				if(dp[r][i]!=1e9)ok=1;
			}
			if(!ok){
				printf("NG %d\n",r+1);
				break;
			}
			r++;
		}
		if(r==n){
			int res=1e9;
			for(int i=0;i<4;i++){
				res=min(res,dp[n-1][i]);
			}
			printf("OK %d\n",res+p[n-1]);
		}
	}
}


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

  int N , M ;
  cin >> N >> M ;
  if ( N>=M ){
    cout << 0 << endl;
    return 0 ;
  }
  vector<int> A(M) ;
  rep(i,M) cin >> A.at(i) ;
  sort(A.begin(),A.end()) ;
  int ans = 0 ;
  rep(i,M-1) ans += abs( A.at(i+1) - A.at(i) ) ;
  //cout << ans << endl;  
  priority_queue<int> pq ;
  rep(i,M-1) pq.push( abs( A.at(i+1) - A.at(i) ) ) ;
  rep(i,N-1){
   ans -= pq.top();
   pq.pop();
  }
  cout << ans << endl;  
}

Measured memory_bytes: 1276
n,k = map(int,input().split())
d = input().split()

def judge(strn):
    for i in strn:
        if i in d: return 0
        else: continue
    return 1

while True:
    strn = str(n)
    if judge(strn): 
        print(strn)
        exit()
    else: n+=1

Measured memory_bytes: 40812
num = int(input())
A=list(map(int,input().split(" ")))

chg = 0
for i in range(num-1):

	minv = i+1
	for j in range(i+2,num):
		if A[minv] > A[j]:
			minv = j

	if A[i] > A[minv]:
		A[i],A[minv] = A[minv],A[i]
		chg += 1
print(*A)
print(chg)



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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a + b + 1)/2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>

static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> visited(n, 0), link(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> link[i];
    }
    int k = 0, ans = 0;
    while(!visited[k]){
        visited[k] = 1;
        k = link[k] - 1;
        if(visited[1]) break;
        ans++;
    }
    cout << (visited[1] ? ans : -1) << "\n";
    return 0;
}


Measured memory_bytes: 1024
import sys

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

if __name__ == "__main__":
    sl = sorted([ord(i) - 97 for i in input()])
    tl = sorted([ord(i) - 97 for i in input()], reverse=True)

    for s, t in zip(sl, tl):
        if s == t:
            continue
        elif s < t:
            print("Yes")
            exit()
        else:
            print("No")
            exit()

    print("Yes" if len(sl) < len(tl) else "No")


Measured memory_bytes: 3060
#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.at(2) == s.at(3) && s.at(4) == s.at(5)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int count=n;
  for(int i=0;i<n-1;i++){
    if(s.at(i)==s.at(i+1)){
      count--;
    }
  }
  cout << count;
}
  


Measured memory_bytes: 512
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;
int power(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return ret;
}

int n,m,k;
int fac[1000111],invf[1000111];
int c(int x,int y){if(x<y||y<0)return 0;return 1ll*fac[x]*invf[y]%mod*invf[x-y]%mod;}
int main()
{
	fac[0]=1;
	for(int i=1;i<1000111;i++)fac[i]=1ll*fac[i-1]*i%mod;
	invf[1000110]=power(fac[1000110],mod-2);
	for(int i=1000109;i>=0;i--)invf[i]=1ll*invf[i+1]*(i+1)%mod;
	
	get3(n,m,k);
	int ans=0,cur=1;
	for(int i=n;i<=n+m+k;i++)
	{
		ans=(ans+1ll*c(i-1,n-1)*cur%mod*power(3,n+m+k-i))%mod;
		cur=(2ll*cur-c(i-n,m)+mod-c(i-n,i-n-k)+mod)%mod;
	}
	printendl(ans);
	return 0;
}

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

typedef pair<int64_t, int64_t> P;
const int64_t INF = 1e18;

void dijkstra(int N, vector<P> edges[], vector<int64_t>& dist){
    priority_queue<P, vector<P>, greater<P>> que;
    for(int i=0; i<N; i++) que.push({dist[i], i});
    while(que.size()){
        auto p = que.top(); que.pop();
        int i = p.second;
        int64_t d = p.first;
        if(d > dist[i]) continue;
        for(auto& e : edges[i]){
            int j = e.first;
            int64_t d2 = d + e.second;
            if(d2 < dist[j]){
                dist[j] = d2;
                que.push({d2, j});
            }
        }
    }
}

vector<P> edges[100000];

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    int P[100000], C[100000], J[100000];
    for(int i=0; i<N; i++) cin >> P[i];
    for(int i=0; i<N; i++) cin >> C[i];
    for(int i=0; i<N; i++) cin >> J[i];
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        edges[a-1].emplace_back(b-1, c);
        edges[b-1].emplace_back(a-1, c);
    }

    vector<int64_t> D0(N, INF);
    D0[0] = 0;
    dijkstra(N, edges, D0);

    vector<int64_t> cost(N);
    for(int i=0; i<N; i++) cost[i] = D0[i] - P[i];
    dijkstra(N, edges, cost);

    vector<int64_t> ans(K+1, -INF);
    for(int i=0; i<N; i++){
        int64_t res = J[i] - cost[i] - D0[i];
        ans[C[i]] = max(ans[C[i]], res);
    }
    for(int i=1; i<=K; i++) cout << ans[i] << endl;
    return 0;
}



Measured memory_bytes: 21960
A,B,K=map(int,input().split())

if K%2==0:
    for _ in range(int(K/2)):
        if A%2==0:
            A=A/2
            B=B+A
        else:
            A=A-1
            A=A/2
            B=B+A
        if B%2==0:
            B=B/2
            A=A+B
        else:
            B=B-1
            B=B/2
            A=A+B

else:
    for _ in range(int((K-1)/2)):
        if A%2==0:
            A=A/2
            B=B+A
        else:
            A=A-1
            A=A/2
            B=B+A
        if B%2==0:
            B=B/2
            A=A+B
        else:
            B=B-1
            B=B/2
            A=A+B
    if A%2==0:
            A=A/2
            B=B+A
    else:
        A=A-1
        A=A/2
        B=B+A

print(str(int(A))+" "+str(int(B)))

Measured memory_bytes: 3188
#include<stdio.h>
 
#define N 10000
 
int search(int *,int,int);
 
 
int main(){
   
  int i;
  int n, n2;
  int A[N], key;
  int count = 0;
   
  scanf("%d", &n);
   
  for ( i = 0 ; i < n ; i++ ) {
    scanf("%d", &A[i]);
  }
 
   
  scanf("%d", &n2);
   
  for ( i = 0 ; i < n2 ; i++ ){
    scanf("%d", &key);
    if ( search(A, n, key) ){
      count++;
    }
  }
   
  printf("%d\n", count);
 
 
  return 0;
}
 
 
 
int search(int A[], int n, int key){
   
  int i;
   
  for ( i = 0; i < n; i++ ){
     
    if ( A[i] == key ) {
      return 1;
    }
     
  }
  return 0;
}

Measured memory_bytes: 640
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    s=readline().strip()
    ans=0
    atgc=("A","T","G","C")
    for i in range(len(s)):
        for j in range(i+1,len(s)+1):
            cnt=0
            t=s[i:j]
            for c in t:
                if c in atgc:
                    cnt+=1
                else:
                    break
            else:
                ans=max(ans,cnt)

    print(ans)            

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

#define ll long long
#define int ll
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

#define dump(x)  cerr << #x << " = " << (x) << endl; 

typedef pair<int, int> P;
struct Point{
	int x, y;
};
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = {1,0,-1,0};


signed main(){
	int N;
	string s, t;
	cin >> N >> s >> t;

	// N文字一致するか？
	int r = 0;
	for (int i = N; i >= 0; i--){
		if (s.substr(N - i, i) == t.substr(0, i)){
			r = i; break;
		}
	}

	cout << 2 * N - r << endl;



	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

int main(void)
{
	vector<int> prime;
	int n;
	
	prime.push_back(2);
	scanf("%d", &n);
	while (n != 0){
		int i;
		int sum = 0;
		int num;
		for (num = prime[prime.size() - 1] + 1; n > prime.size(); num++){
			for (i = 0; i < prime.size(); i++){
				if (num % prime[i] == 0){
					break;
				}
			}
			if (i == prime.size()){
				prime.push_back(num);
			}
		}
		for (i = 0; i < n; i++){
			sum += prime[i];
		}
		printf("%d\n", sum);
		
		scanf("%d", &n);
	}
	
	return 0;
}

Measured memory_bytes: 1156
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    map<P,ll> mp;
    rep(i,N){
        ld s;
        cin >> s;
        ll div_2=-9,div_5=-9;
      	ll k=1000000000*s+0.5;
        while(k%2==0){
            k/=2;
            div_2++;
        }
        while(k%5==0){
            k/=5;
            div_5++;
        }
        mp[{div_2,div_5}]++;
    }
    ll ans=0;
    FOR(i,-9,51){
        FOR(j,-9,21){
            ll res=0;
            FOR(ii,-9,51){
                FOR(jj,-9,21){
                    if(i+ii>=0&&j+jj>=0){
                        if(i==ii&&j==jj)res--;
                        res+=(mp[{ii,jj}]);
                    }
                }
            }
            ans+=res*mp[{i,j}];
        }
    }
    ans/=2;
    cout << ans << endl;
}


Measured memory_bytes: 3908
#include <iostream>

int main( void ) {
    int a, b;

    std::cin >> a >> b;
    
    int sum = a + b;
    if( 10 <= sum ) {
        std::cout << "error" << std::endl;
    } else {
        std::cout << sum << std::endl;
    }

    return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nhw = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nhw[0];
        var h = nhw[1];
        var w = nhw[2];
        var abs = new Tuple<int, int>[n];
        for (int i = 0; i < abs.Length; i++)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            abs[i] = Tuple.Create(ab[0], ab[1]);
        }
        var k = 0;
        for (int i = 0; i < abs.Length; i++)
        {
            if (abs[i].Item1 >= h && abs[i].Item2 >= w)
            {
                k++;
            }
        }
        Console.WriteLine(k);
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main(){
    int n; cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    
    int ans = INF;
    
    for (int i=1; i<=100; i++) {
        int sum = 0;
        int P = i; //集会地点の座標
        rep(i, n){
            sum += (x[i] - P) * (x[i] - P);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))


(defun main (line)
  (labels ((f (last lst)
             (when (null lst)
               (return-from f t))
             (when (> last (car lst))
               (return-from f nil))
             (f (max last (1- (car lst))) (cdr lst))))
    (if (f -1000000000 line) "Yes" "No")))

(let* ((n (read))
       (line (loop repeat n collect (read))))
  (princ (main line)))


Measured memory_bytes: 62524
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      int output = 0;
      while(N > 0){
        if(N % 10 == 2){
          output++;
        }
        N /= 10;
      }
      myout(output);
	}
	//Method addition frame start


  
	//Method addition frame end
}


Measured memory_bytes: 32860
#include<iostream>
#include<cstdio>
#include<cstring>
using std::min;

const int MAXN=2e5+5;

int n;char s[MAXN];
int a[MAXN],f[MAXN],minv[1<<26];

int main()
{
	int i,k;
	scanf("%s",s+1);n=strlen(s+1);
	for(i=1;i<=n;i++) a[i]=a[i-1]^(1<<(s[i]-'a'));
	memset(minv,0x3f,sizeof(minv));minv[0]=0;
	for(i=1;i<=n;i++)
	{
		f[i]=minv[a[i]]+1;
		for(k=0;k<26;k++)
			f[i]=min(f[i],minv[a[i]^(1<<k)]+1);
		minv[a[i]]=min(minv[a[i]],f[i]);
	}
	printf("%d\n",f[n]);
	return 0;
}


Measured memory_bytes: 264192
#include<bits/stdc++.h>
using namespace std;
#define loop(x,n) for (int x = 0;x < n;x++)
int main(){
int t; cin>>t;
  vector<int> v(t);
  loop(i,t){
  	cin>>v[i];
  }
  int sum = 0;
  loop(i,t){
  	for (int j = i+1;j < t;j++){
    	sum += v[i]*v[j];
    }
  }
  cout<<sum<<endl;
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef unsigned long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
//---------------------------------------------
 


int main(void)
{
int k;
int n;

cin>>k>>n;

vector<int> a(n);

rep(i,n) cin>>a[i];

int maxdis = 0;

for(int i=1;i<n;i++)
{

maxdis = max(maxdis,a[i]-a[i-1]);

}

maxdis = max(maxdis,k-a[n-1]+a[0]);

cout<<k-maxdis<<endl;


}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int a,b,c,temp;
    scanf("%d%d%d",&a,&b,&c);
    if(a>b)
    {
        temp=a;
        a=b;
        b=temp;
    }
    if(a>c)
    {
        temp=a;
        a=c;
        c=temp;
    }
    if(b>c)
    {
        temp=b;
        b=a;
        c=temp;
    }
    printf("%d",a*b/2);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
long int S;
int h,m,s;

scanf("%ld", &S);

h = S / 3600;
m = S % 3600 / 60;
s = S % 3600 % 60;

printf("%d:%d:%d\n",h,m,s);
return 0;
}

Measured memory_bytes: 592
n,y = map(int,input().split())
a = 10
b = 5
c = 1
d = y/1000
x,y,z = -1,-1,-1
check = 0
for i in range(n+1):
    for j in range(n+1-i):
        if a * i + b * j + c * (n-(i+j)) == d:
            x,y,z=i,j,n-(i+j)
print(x,y,z)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    string st;
    cin>>st;
    REP(i,st.size()){
        if(st[i]=='1'){
            cout<<9;
        }else{
            cout<<1;
        }
    }cout<<endl;
    return 0;
}

Measured memory_bytes: 768
n = int(input())
s = list(input())

mode = 0
stock = 0
left = 0
for i in range(n):
    if s[i] == '(':
        if mode == 0:
            stock += 1
        else:
            mode = 0
            stock = 1
    else:
        if mode == 0:
            stock -= 1
            if stock < 0:
                left += 1
                mode = 1
        else:
            left += 1

mode = 0
stock = 0
right = 0
for i in range(n - 1, -1, -1):
    if s[i] == ')':
        if mode == 0:
            stock += 1
        else:
            mode = 0
            stock = 1
    else:
        if mode == 0:
            stock -= 1
            if stock < 0:
                right += 1
                mode = 1
        else:
            right += 1

p = s.count('(')
q = n - p

if left + p < right + q:
    left += (right + q) - (left + p)
elif left + p > right + q:
    right += (left + p) - (right + q)

s = ['('] * left + s + [')'] * right

print(''.join(s))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define length(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, length(a))cin >> a[i]
#define ccin(i, j, a) rep(i, length(a))rep(j, length(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define sqrtl sqrt
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main(){
    intl n;
    cin >> n;
    if(n >= 1200)cout << "ARC" << endl;
    else cout <<"ABC" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n,h; cin>>n>>h;
  VI a(n),b(n); rep(i,n) cin>>a[i]>>b[i];
  sort(RALL(a)); sort(RALL(b));
  int m = a[0]; int dam = 0; ll cnt = 0;
  rep(i,n){
    if(b[i]<m) break;
    dam += b[i], cnt++;
    if(dam>=h) break;
  }
  int ad = 0;
  if(dam<h){
    int ad = (h-dam)/m; cnt += ad;
    dam += ad*m;
  }
  if(dam<h) cnt++;
  cout << cnt << endl;
	return 0;
}


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

using namespace std;

int main(){
	
	while(1){
		
		int n,l;
		cin >> n >> l;
		if(n==0&&l==0) break;
		int a[20];
		a[0]=n;
		int b[l],c[l];
		int pos=-1;
		bool same=false;
		while(!same){
			pos++;
			int d=a[pos];
			for(int i=0;i<l;i++){
				b[i]=d%10;
				d/=10;
			}
			sort(b,b+l);
			for(int i=0;i<l;i++){
				c[i]=b[i];
			}
			reverse(c,c+l);
			int e=0,f=0;
			for(int i=0;i<l;i++){
				e*=10;
				f*=10;
				e+=b[i];
				f+=c[i];
			}
			a[pos+1]=f-e;
			for(int i=0;i<pos+1;i++){
				if(f-e==a[i]){
					cout << i << " " << a[i] << " " << pos+1-i << endl;
					same=true;
					break;
				}
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int i, m, c, e, S;
    
    cin >> i >> m >> c >> e;
    S = i + m + c + e;
    
    int I, M, C, E, T;
    
    cin >> I >> M >> C >> E;
    T = I + M + C + E;
    
    if (S >= T){
        cout << S;
    }else{
        cout << T;
    }
    cout << endl;
    
}


Measured memory_bytes: 3096