akhauriyash/Code-Regression huggingface dataset:
#define NDEBUG

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>

typedef uint64_t num_t;

const int DBG = 0;

num_t num_abs(num_t x)
{
    return x >= 0? x: -x;
}
const num_t INF = 10E11;

num_t *readlist_alloc(int size)
{
    int i;
    num_t *a = calloc(size, sizeof(a[0]));
    for (i = 0; i < size; i ++) {
        int _ = scanf("%ld", &a[i]);
    }
    return a;
}
void print_problem(int N, num_t K, num_t A[])
{
    int i;
    printf("%d %lu\n", N, K);
    puts("A: ");
    for (i = 0; i < N; i ++) {
        printf("%lu ", A[i]);
    }
    printf("\n");
}

int get_num_bits(num_t n)
{
    int i = 0;
    assert(n >= 0);
    while(n) {
        i++;
        n = n >> 1ULL;
    }
    return i;
}

num_t get_x_template(int nbits, int N, num_t A[])
{
    int i, j;
    num_t X = 0ULL;
    for (i = 0; i < nbits; i++) {
        int c = 0;
        for (j = 0; j < N; j++)
            c += (A[j] & (1ULL << i)) >> i;
        if (c < N - c)
            X |= (1ULL << i);
    }
    return X;
}

num_t func(num_t A[], int N, num_t X)
{
    int i;
    num_t ret = 0ULL;
    for (i = 0; i < N; i++)
        ret = ret + (X ^ A[i]);
    return ret;
}

int main()
{
    int N;
    num_t K;
    num_t *A;
    int _ = scanf("%d%lu", &N, &K);
    A = readlist_alloc(N);
    int nbits = 40;
    int K_bits = get_num_bits(K);
    if (DBG) print_problem(N, K, A);
    if (DBG) printf("K %lu, bit %d\n", K, nbits);
    int i;
    num_t X_template = get_x_template(nbits, N, A);
    if (DBG) printf("X_template %lu\n", X_template);
    num_t X_max = 0ULL;
    num_t f_max = func(A, N, X_max);
    for (i = 0; i < nbits; i++) {
        num_t mask_sp = ~(1ULL<<i);
        num_t mask_lo = (1ULL<<i) - 1ULL;
        num_t mask_hi = ~mask_lo;
        //if (DBG) printf("%016lx %016lx %016lx\n", mask_sp, mask_lo, mask_hi);
        //if (!(K & mask_sp)) continue;
        num_t X = ((K & mask_hi) | (X_template & mask_lo)) & mask_sp;
        if (X > K)
            continue;
        num_t fx = func(A, N, X);
        if (DBG) printf("i %d X fx %lu %lu\n", i, X, fx);
        if (fx > f_max) {
            f_max = fx;
            X_max = X;
        }
    }
    if (DBG) printf("X_max %lu\n", X_max);
    printf("%lu\n", f_max);
    return 0;
}


Measured memory_bytes: 896
N = int(input())
s = input().strip()
flag = 1
A = [0 for _ in range(N)]
for a in range(2):
    for b in range(2):
        A[0]=a
        A[1]=b
        for i in range(1,N-1):
            if A[i]==0 and s[i]=="o":
                A[i+1]=A[i-1]
            elif A[i]==0 and s[i]=="x":
                A[i+1]=1-A[i-1]
            elif A[i]==1 and s[i]=="o":
                A[i+1]=1-A[i-1]
            elif A[i]==1 and s[i]=="x":
                A[i+1]=A[i-1]
        if A[N-1]==0 and s[N-1]=="o":
            if A[0]==A[N-2]:
                flag = 0
            else:
                flag = 1
                continue
        elif A[N-1]==0 and s[N-1]=="x":
            if A[0]==1-A[N-2]:
                flag = 0
            else:
                flag = 1
                continue
        elif A[N-1]==1 and s[N-1]=="o":
            if A[0]==1-A[N-2]:
                flag = 0
            else:
                flag = 1
                continue
        elif A[N-1]==1 and s[N-1]=="x":
            if A[0]==A[N-2]:
                flag = 0
            else:
                flag =1
                continue
        if A[0]==0 and s[0]=="o":
            if A[1]==A[N-1]:
                flag = 0
            else:
                flag =1
                continue
        elif A[0]==0 and s[0]=="x":
            if A[1]==1-A[N-1]:
                flag = 0
            else:
                flag = 1
                continue
        elif A[0]==1 and s[0]=="o":
            if A[1]==1-A[N-1]:
                flag = 0
            else:
                flag = 1
                continue
        elif A[0]==1 and s[0]=="x":
            if A[1]==A[N-1]:
                flag = 0
            else:
                flag = 1
                continue
        if flag==0:
            B = []
            for i in range(N):
                if A[i]==0:
                    B.append("S")
                else:
                    B.append("W")
            break
    if flag==0:break
if flag==1:
    print(-1)
else:
    print("".join(B))

Measured memory_bytes: 75516
import java.util.Scanner;

public class Main {
	public static void main (String[]args){
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] num = line.split(" ");
		int a = Integer.parseInt(num[0]);
		int b = Integer.parseInt(num[1]);
		int c = Integer.parseInt(num[2]);

		if(a==b+c)System.out.println("Yes");
		else if(b==a+c)System.out.println("Yes");
		else if(c==a+b)System.out.println("Yes");
		else System.out.println("No");
	}

}


Measured memory_bytes: 8916
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N, K;
  cin >> N >> K;
  int A;
  rep(i, N) cin >> A;
  
  fin((N-1)/(K-1) + ((N-1)%(K-1)!=0));
}

Measured memory_bytes: 256
a[99][999],b,c;f(d,s,b,i){for(++a[d++][s];i--;)b>>i&1||f(d,s+i*d,b|1<<i,10);}main(){for(f(0,0,0,10);scanf("%d%d",&b,&c)/2;)printf("%d\n",b<15&c<400?a[b][c]:0);}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int n[10];
int main(void){
    int x,c1=0,c2=0;
    for(int i=0;i<6;i++){
        cin>>x;
        n[x]++;
    }
    for(int i=0;i<5;i++){
        if(n[i]==1)c1++;
        else if(n[i]==2)c2++;
    }
    if(c1==2&&c2==2)cout<<"YES\n";
    else cout<<"NO\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 200010
using namespace std;
struct node{
	char s[12];
}q[maxn];
char pre[12];
int cmp(node a,node b){
	return strcmp(a.s,b.s)<0;
}
int main(){
	int n,i,cnt=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%s",q[i].s);
	sort(q+1,q+1+n,cmp);
	strcpy(pre,q[1].s);
	for(i=2;i<=n;i++)
		if(strcmp(q[i].s,pre)!=0)strcpy(pre,q[i].s),cnt++;
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 4072
#include <stdio.h>

int main(void)

{

 int n, i, j, l;
 int a[200000];

 scanf("%d", &n);

 for(i = 0;i < n; i++)
{

 scanf("%d", &a[i]);

 }

int max = a[1] - a[0];
int min  = a[0];

 for(i = 0;i < n-1; i++)
{
 if(a[i + 1] - min > max)
 max = a[i + 1] - min;

 if(a[i + 1] < min)
 min = a[i + 1];
 
}
 printf("%d\n", max);

 return 0;
}


 

 


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

int main() {
	int A[5][4][11], n;
	for ( int i = 1; i <= 4; i++ ){
		for ( int j = 1; j <= 3; j++ ){
			for ( int k = 1; k <= 10; k++ ){
				A[i][j][k] = 0;
			}
		}
	}
	
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		A[b][f][r] += v;
	}
	
	for ( int f = 1; f <= 4; f++ ){
		if ( f > 1 ) cout << "####################\n";
		for ( int b = 1; b <= 3; b++ ){
			for ( int r = 1; r <= 10; r++ ){
				cout << " " << A[f][b][r];
			}
			cout << endl;
		}
	}
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, t[111], v[111];

int main() {
	cin >> n;
	cin >> t[0];
	reps(i,1,n) {
		cin >> t[i];
		t[i] += t[i-1];
	}
	rep(i,n) cin >> v[i];
	// 考えやすいように制限速度0のn番目の点を設置
	v[n] = 0;
	
	// 0.5秒刻みでシミュレート (1秒じゃなく0.5秒なのは入力例4みたいに奇数秒の区域の真ん中で速度が変わるパターンがあるから)
	// 各t[i]では速度をv[i]にしないといけないっていう制約がn個ある
	// 各iでそれより右にある全ての点の制約を守る範囲でなるべく加速したい
	
	// x座標が現在地以上で最も現在地に近い点の番号
	int ct = 0;
	// 答え、i秒目に出せる最高の速度、i-0.5秒目に出した速度
	double ans = 0, cv = 0, pre = 0;
	for (double i = 0.5; i <= t[n-1]; i += 0.5) {
		// 0.5秒で加速できる最大値 とりあえずこれだけ加速すると仮定しといて下の条件チェックで狭めていく
		cv += 0.5;
		// 点ctを追い越したら次は点ct+1を目指す
		if (t[ct]<i) ct++;
		// 満たさないといけない条件を全て確認
		// v[j+1]: j番目の点にたどり着いた瞬間次の制限速度がこれになる ∴ 時刻t[j]までにこの速度以下になってないといけない
		// t[j]-i: 今からj番目の点に辿り着くまでにかかる時間
		// 点jの制約はiがこれらの和以下であるってこと
		// 仮に今これらの和の速度を出すとすると、今後0.5秒ごとに0.5ずつ減速すればちょうど時刻t[j]に速度がv[j+1]になるとも言える
		// 点j全てから傾き-1の直線を引いて、直線x=iと交わる点それぞれのy座標がこれに対応する たぶん 思い出したら図書いて確認したい
		// 交点の中で一番y座標小さい点が今出せる速度の上限
		reps(j,ct,n) chmin(cv, v[j+1]+t[j]-i);
		// ⇡で次の点以降の速度制限については考えた 今いる範囲の速度制限もチェック
		cv = min(cv, 1.*v[ct]);
		// 直前の速度を上底、今の速度を下底とする台形の面積を答えに+
		ans += 0.25 * (pre + cv);
		pre = cv;
	}
	printf("%.6lf\n", ans);
}

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

int main(void){
	char str[21], rev[21];
	int n;
	int i;

	scanf("%20s", str);

	n = strlen(str);

	for (i = 0; i < n; i++){
		rev[i] = str[n - i - 1];
	}
	rev[n] = '\0';
	printf("%s\n", rev);

	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
int n,k,ans,tt;
int head[N],to[N],nxt[N],a[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline int dfs(int x) {
    int d=0;
    for(int i=head[x];i;i=nxt[i])
	d=max(d,dfs(to[i])+1);
    if(d==k-1&&a[x]!=1) ++ans,d=-1;
    return d;
}
int main() {
    cin>>n>>k,a[1]=1;
    if(gi()!=1) ++ans;
    for(int i=2,x;i<=n;i++)
	to[++tt]=i,nxt[tt]=head[x=a[i]=gi()],head[x]=tt;
    dfs(1);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4096
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int K = scan.nextInt();
    int A[] = new int[N];
    int Asum = 0;
    int a[] = new int[N];
    int ad[] = new int[N];
    List<Integer> x = new ArrayList<>();
    int result = 0;
    
    
    for(int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      Asum += A[i];
    }
    
    for(int i = 1; i*i <= Asum; i++){
      if(Asum%i == 0 && i != Asum/i){
        x.add(i);
        x.add(Asum/i);
      }else if(Asum%i == 0){
        x.add(i);
      }
    }
    
    int len = x.size();
    
    
    int[] X = new int[len];
    
    for(int i = 0; i < len; i++){
      if(i*10 < (len*10)/2){
        X[i] = x.get(2*i);
      } else {
        X[i] = x.get(2*(len-i)-1);
      }
    }
    
    for(int i = len-1; i >= 0; i--){
   
      int asum = 0;
      int adsum = 0;
      
      for(int j = 0; j < N; j++){
        a[j] = A[j]%X[i];
        ad[j] = A[j]/X[i];
        asum += a[j];
        adsum += ad[j];
      }
      
      Arrays.sort(a);
      
      int asub = 0;
      int Kcount = 0;
      
      for(int j = N-1; j > 0; j--){
        asub += a[j];
        Kcount += X[i]-a[j];
        if(asub+Kcount >= Asum-adsum*X[i]){
          break;
        }
      }
      
      if(Kcount <= K){
        result = X[i];
        break;
     }
    }

    System.out.println(result);
    
  }
}

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

typedef long long ll;
typedef pair<int,int> P;
#define INF (int)(1e9)
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i = 1;i <= (int)(n); i++)
#define FOR(i,k,n) for(int i = (k); i < (int)(n); i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define pb push_back
#define vec vector<int>


/*--------------------------------------------*/
/*ll factorial(ll);
void list_Prime(ll);
ll divisor(ll);
ll lcm(ll, ll);//AとBの最小公倍数
ll gcd(ll,ll);

int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
*/
/*--------------------------------------------*/
/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}
ll lcm(ll A, ll B) {//最小公倍数
    ll a = A;
    ll b = B;
    if (a == 0 || b == 0) { return 0; }
    if (a < 0) { a = -a; }
    if (b < 0) { b = -b; }
    while (b > 0) {
        ll c = a % b;
        a = b;
        b = c;
    }
    return A/a*B;
}

ll gcd(ll a,ll b){
    while (b != 0) {
        int t = b;
        b = a % b;
        a = t;
    }
    return a;
}


void list_Prime(ll n){//n以下の素数を全て見つける
    ll Limit=(int)sqrt((double)n);
    for(ll i=2;i<=n;i++)prime[i]=1;//最初はみんな素数かも
    //素数の整数倍を消していく(ルートnまで)
    for(ll i=2;i<=Limit;i++){
        if(prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    prime[j]=0;                
                }
            }
        }
    }
}

ll divisor(ll n){
    for(ll i=2;i<=n;i++){
        ll d=1;
        ll tmp=i;
        while(tmp>0){
            d++;
            while(tmp%d==0){
                prime[i]++;
                tmp/=i;
            }
        }
    }
    ll sum=1;
    for(ll i=2;;i<=n;i++){
        sum*=(prime[i]+1)/MOD;
    }    
    cout<<"sum="<<sum<<endl;

    return sum%MOD;
}
*/
/*--------------------------------------------*/
int main(){
    int n,m;cin>>n>>m;
    ll ans=1;
    if(abs(n-m)>=2)cout<<"0"<<endl;
    else{
        if(n==m){
            for(ll i=n;i>0;i--){
                ans*=(i*i)%MOD;
                ans%=MOD;
                //cout<<ans<<endl;
            }
            ans*=2;
            ans%=MOD;
            cout<<ans<<endl;
        }else{
            ans*=max(n,m);
            for(ll i=min(n,m);i>0;i--){
                ans*=(i*i)%MOD;
                ans%=MOD;
            }
            cout<<ans<<endl;
        }
    }
    
}



Measured memory_bytes: 256
#include<stdio.h>
int a[10000],b[10000];
int main(void)
{
int n,k,i,c,x[501];
	while(1){
		c=0;
		scanf("%d",&n);
		scanf("%d",&k);
		if(n==0&&k==0){
			break;
		}
		for(i=0;i<=n;i++){
			a[i]=0;
			b[i]=0;
			x[i]=0;
		}
		x[1]=1;
		for(i=0;i<k;i++){
			scanf("%d %d",&a[i],&b[i]);
			if(a[i]==1){
				x[b[i]]=1;
				c++;
			}
		}
		for(i=0;i<k;i++){
			if(x[a[i]]==1&&x[b[i]]==0){
				x[b[i]]=3;
				c++;
			}
			if(x[b[i]]==1&&x[a[i]]==0){
				x[a[i]]=3;
				c++;
			}
		}
		printf("%d\n",c);
		}
return 0;
}

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	ll X; cin >> X;
	vector<pair<ll,ll>> pow5;
	for(ll i = -1000; i <= 1000; ++i) {
		pow5.push_back({i*i*i*i*i,i});
	}
	for(auto& a:pow5){
		for(auto& b:pow5){
			if(a.first - b.first == X){
				cout << a.second << " " << b.second << endl;
				return 0;
			}
		}
	}
    return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#define MAX 100000
using namespace std;

//求k辆运载量为P的卡车能装多少货物 
int check(int W[], int n, int k, int P)
{
	int j = 0;
	for (int i = 0; i < k; i++) {
		int temp = 0;
		while (temp + W[j] <= P) {
			temp += W[j];
			j++;
			if (j == n) {
				return n;
			}
		}	
	}
	
	return j;
	
//	int temp = 0;
//	int cnt = 1;
//	int i;
	
//	for (i = 0; i < n; i++) {
//		if (temp + W[i] > P) {
//			temp = W[i];
//			cnt++;
//			if (cnt > k)
//				break;
//		}
//		else {
//			temp += W[i];
//		}
//	}
}

int binarySearch(int W[], int n, int k)
{
	int low = 0;
	int high = MAX*10000;
	int mid;
	
	while (low + 1 < high) {
		mid = (low + high) / 2;
		//test-def
		//printf("\nlow=%d high=%d\n", low, high);
		//tesd-end
		//int a = check(W, n, k, mid-1);
		int a = check(W, n, k, mid);
		//test-def
		//printf("\na=%d b=%d\n", a, b);
		//tesd-end
//		if (a < n && b >= n) {
//			return mid;
//		}
//		else if (a >= n){
//			high = mid - 1;
//		}
//		else if (b < n) {
//			low = mid + 1;
//		}
		if (a >= n) {
			high = mid;
		}
		else {
			low = mid;
		}
	}
	
	return high;
}

int main(void)
{
	int n, k;
	int W[MAX];
	int total;
	
	cin >> n;
	cin >> k;
	for (int i = 0; i < n; i++) {
		cin >> W[i];
	}
	cout << binarySearch(W, n, k) << endl;
	
	return 0;
} 


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

int main() {
  ll sum = 0;
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  for (int i = 1; i < n; i++){
    if (a[i-1] == a[i] || a[i-1] < a[i] ) continue;
    ll diff = a[i-1]-a[i];
    sum += diff;
    a[i] += diff;
  }
  cout << sum << endl;
}

Measured memory_bytes: 4784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		String[] labelStr = sc.nextLine().split(" ");

		int[] label = new int[6];
		for (int i=0; i < 6; i++) {
			label[i] = Integer.parseInt(labelStr[i]);
		}

		Dice d = new Dice(label);

		int q = sc.nextInt();
		for ( int i=0; i < q; i++) {
			int ul = sc.nextInt(); // upper label
			int fl = sc.nextInt(); // front label

			if (ul == d.ue) {}
			else if (ul == d.mae) d.kok('N');
			else if (ul == d.migi) d.kok('W');
			else if (ul == d.ushiro) d.kok('S');
			else if (ul == d.hidari) d.kok('E');
			else if (ul == d.shita) d.kok('N').kok('N');

			if (fl == d.mae) {}
			else if (fl == d.migi) d.kok('R');
			else if (fl == d.ushiro) d.kok('R').kok('R');
			else if (fl == d.hidari) d.kok('L');

			System.out.println(d.migi);
		}

	}

}

class Dice {
	int ue,mae,migi,hidari,ushiro,shita;

	Dice(int[] label) {
		ue = label[0];
		mae = label[1];
		migi = label[2];
		hidari = label[3];
		ushiro = label[4];
		shita = label[5];
	}

	Dice kok(char newsrl) { // korogasu or kaitenn saseru
		int temp = 0;

		switch (newsrl) {
		case 'N':
			temp = ue;
			ue = mae;
			mae = shita;
			shita =ushiro;
			ushiro = temp;
			break;
		case 'S':
			temp = ue;
			ue = ushiro;
			ushiro = shita;
			shita = mae;
			mae = temp;
			break;
		case 'E':
			temp = ue;
			ue = hidari;
			hidari = shita;
			shita = migi;
			migi = temp;
			break;
		case 'W':
			temp = ue;
			ue = migi;
			migi = shita;
			shita = hidari;
			hidari = temp;
			break;
		case 'R':
			temp = mae;
			mae = migi;
			migi = ushiro;
			ushiro = hidari;
			hidari = temp;
			break;
		case 'L':
			temp = mae;
			mae = hidari;
			hidari = ushiro;
			ushiro = migi;
			migi = temp;
			break;
		}

		return this;
	}

	boolean check(Dice d) {
		if (this.ue == d.ue && this.mae == d.mae &&
				this.migi == d.migi && this.hidari == d.hidari &&
				this.ushiro == d.ushiro && this.shita == d.shita) {
			return true;
		} else
			return false;
	}

}

Measured memory_bytes: 26128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;
    char c;
    cin>>c;
    cout<<(char)(c+1);
    return 0;
}



Measured memory_bytes: 256
import std;

auto input()
{
    return readln().chomp();
}

alias sread = () => readln.chomp();

void main()
{
    string s = input();
    long s_len = s.length;
    //writeln(s);
    //writeln(s_len);
    writeln(s[0 .. ((s.length) - 8)]);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;

    }
}


Measured memory_bytes: 3612
#include<cstdio>
#include<algorithm>
#define M 2000000000
 
using namespace std;
int main(void)
{
    int n,i,j,s,a[5000],b[5000],m;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    m=M;
    for(i=0;i<=a[0];i++){
        for(j=0;j<n;j++) b[j]=a[j];
        b[0]-=i; s=i;
        for(j=0;j<n-1;j++){
            if(b[j]>0){
                b[j+1]-=b[j];
                s+=b[j]*2;
                b[j]=0;
            }
        }
        if(b[n-1]>0) s+=b[n-1];
        m=min(m,s);
    }
    printf("%d\n",m);
    return 0;
}
 


Measured memory_bytes: 2792
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int x[51];
ll dp[51][5001];
int main() {
  int n, a;
  cin >> n >> a;
  int mx = a, tmp;
  reps(i, n){
	cin >>tmp;
	x[i]=tmp -a;
	mx = max(mx, tmp);
  }
  rep(j, n+1)
  rep(t, (2*n*mx+1)){
	  if(j == 0 && t == n*mx)
		  dp[j][t] = 1LL;
	  else if(j > 0 && ((0 > t - x[j])))
		  dp[j][t] = dp[j-1][t];
	  else if(j > 0 && (0 <= t - x[j]))
		  dp[j][t] = dp[j-1][t]+dp[j-1][t-x[j]];
	  else 
		  dp[j][t] = 0LL;
  }
  cout << dp[n][n*mx] - 1 << endl;
  return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  string S;
  long long cnt=0,sum=0;
  cin >> S;
  for(int i=0;i<S.size();i++){
    if(S[i]=='B')cnt++;
      else sum+=cnt;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdio>

#define SQ(x) (x)*(x)
#define CU(x) (x)*(x)*(x)

using namespace std;

int main(void){
    int q;
    double x;
    double x_a;
    
    while(cin>>q,q!=-1){
        x=q/2.0;
        x_a=abs(CU(x)-q);
        while(true){
            if(x_a<0.00001*q)break;
            x=x-(CU(x)-q)/(3*SQ(x));
            x_a=abs(CU(x)-q);
        }
        printf("%.6lf\n",x);
    }
    return(0);
}

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

#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define let const auto
#define USE1(T) template <typename T>
#define USE2(T, U) template <typename T, typename U>
#define I_ inline
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

USE1(T) using duo = std::pair<T, T>;
USE1(T) using vec = std::vector<T>;
using ll = long long;
// clang-format off
USE2(T,U) I_ bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U) I_ bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int) I_ T in(){T x;std::cin>>x;return x;}
USE1(T=int) I_ vec<T> in(int n){vec<T> v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE1(T) vec<T> ndvec(T v,int n){return vec<T>(n, v);}
USE2(T,...Ts) auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T) I_ void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts) I_ void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
I_ int rd(){int x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
I_ void wr(int x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
struct IoSetup {
  IoSetup(){
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(10);
    std::cerr.precision(10);
  }
} iosetup;
// clang-format on
// }}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dx[] = {0, 0, 0, -1, -1, -1, -2, -2, -2};
const int dy[] = {0, -1, -2, 0, -1, -2, 0, -1, -2};

signed main() {
  ll H = in(), W = in();
  int N = in();
  map<duo<ll>, int> cnt;
  rep(i, N) {
    ll a = in(), b = in();
    rep(d, 9) { cnt[duo<ll>(a + dy[d], b + dx[d])]++; }
  }
  ll ans[10] = {};
  for (auto kv : cnt) {
    if (kv.fst.fst < 1 || kv.fst.snd < 1) continue;
    if (kv.fst.fst > H - 2 || kv.fst.snd > W - 2) continue;
    ans[kv.snd]++;
  }
  ll tot = 0;
  rep(i, 10) tot += ans[i];
  ans[0] = (H - 2) * (W - 2) - tot;
  rep(i, 10) { pr(ans[i]); }
  return 0;
}


Measured memory_bytes: 56448
from heapq import heappush, heappop
from collections import deque
import itertools
from itertools import permutations
import sys
import bisect
sys.setrecursionlimit(10**6)
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YN=['YES','NO']
YNeos='YNeos'
mo=10**9+7
imp='IMPOSSIBLE'


n=I()
a=LI()
ans=1
c=[i for i in a]
c.sort()
def rp(i,j):
    b=[i for i in a]
    b[i],b[j]=b[j],b[i]
    return b
for i in range(n):
    for j in range(i,n):
        d=rp(i,j)
        if d==c:
            ans=0

print(YN[ans])



Measured memory_bytes: 40528
let s = read_line ()
let n, fs, is, i = Array.(String.length s, make 26 false, make 26 0, ref 0)
let f s n = Printf.printf "%s%c\n" s (Char.chr (n + 97)); exit 0
let _ = String.(Char.(iter (fun c -> let n = code c - 97 in fs.(n) <- true; is.(!i) <- n; incr i) s;
  if n < 26 then (i := 0; while fs.(!i) do incr i done; f s !i);
  for j = n - 1 downto 0 do i := code s.[j] - 96; while !i < 26 && fs.(!i) do incr i done; if !i < 26 then f (sub s 0 j) !i; fs.(is.(j)) <- false done; print_endline "-1"))

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

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

  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < n; j ++) {
      if (i == j) continue;

      if (abs(a[i] - a[j])%(n-1) == 0) {
        cout << a[i] << " " << a[j] << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3120
var count = 0;

function Main(input) {

	input = input.split("");
	for(var i = 0;i<3;i++){
	    if(input[i] === input[i+1]) count++;
	}
	
	if(count === 0){
	    console.log("Good");
	}else{
	    console.log("Bad");
	}
	
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second

typedef long long LL;

int n ;
int a[12345];

int main() {
  //  freopen("test.txt","r",stdin);
    cin >> n ;
    int ans = 0;
    for (int i =1 ; i<= n ; i++) {
        cin >> a[i];
        ans += a[i];
    }
    sort( a+1,a+1+n);
    if ( ans % 10 != 0) {
        cout << ans;
        return 0;
    }
    for (int i=1 ; i<= n ; i++) {
        if ( a[i] % 10 != 0 ) {
            ans -= a[i];
            cout << ans ;
            return 0;
        }
    }
    cout << 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N;
pair<iP, int>p[100];
double res[100];
vector<int>u, v;

ll f(int i, int j, int k) {
	ll x1 = p[j].first.first - p[i].first.first;
	ll y1 = p[j].first.second - p[i].first.second;
	ll x2 = p[k].first.first - p[i].first.first;
	ll y2 = p[k].first.second - p[i].first.second;
	return x1*y2 - y1*x2;
}

double F(int i, int j, int k) {
	double x1 = p[j].first.first - p[i].first.first;
	double y1 = p[j].first.second - p[i].first.second;
	double x2 = p[k].first.first - p[i].first.first;
	double y2 = p[k].first.second - p[i].first.second;
	return(M_PI - acos((x1*x2 + y1*y2) / sqrt((x1*x1 + y1*y1)*(x2*x2 + y2*y2)))) / (M_PI * 2);
}

int main() {
	cin >> N;
	for (int i = 0; i != N; ++i) {
		cin >> p[i].first.first >> p[i].first.second;
		p[i].second = i;
	}
	sort(p, p + N);
	u.push_back(0);
	u.push_back(1);
	v.push_back(0);
	v.push_back(1);
	for (int i = 2; i != N; ++i) {
		while (u.size() >= 2 && f(u.back(), i, u[u.size() - 2]) > 0) {
			u.pop_back();
		}
		u.push_back(i);
	}
	for (int i = 2; i != N; ++i) {
		while (v.size() >= 2 && f(v.back(), v[v.size() - 2], i) > 0) {
			v.pop_back();
		}
		v.push_back(i);
	}
	res[p[0].second] = F(0, u[1], v[1]);
	res[p[N - 1].second] = F(N - 1, u[u.size() - 2], v[v.size() - 2]);
	for (int i = 1; i != u.size() - 1; ++i)
		res[p[u[i]].second] = F(u[i], u[i - 1], u[i + 1]);
	for (int i = 1; i != v.size() - 1; ++i)
		res[p[v[i]].second] = F(v[i], v[i - 1], v[i + 1]);
	for (int i = 0; i != N; ++i)
		printf("%.10f\n", res[i]);
	return 0;
}

Measured memory_bytes: 384
#![allow(unused_imports)]

mod pcl {

}




fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let x = s.trim().parse::<i64>().unwrap();

    let n500 = x / 500;
    let n5 = x % 500 / 5;

    println!("{}", n500 * 1000 + n5 * 5);
}


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

#define ll long long

int main(void) {
	
	ll a, b; cin >> a >> b;
	if (a > b) swap(a, b);
	ll num1, num2, num3;
	num1 = num2 = num3 = 0;
	if (a <= 0 && b >= 0) {
		return 0 * puts("Zero");
	}
	if (a > 0 && b > 0) {
		return 0 * puts("Positive");
	}
	if (a < 0 && b < 0) {
		int num = (b - a + 1);
		if (num & 1) return 0 * puts("Negative");
		else return 0 * puts("Positive");
	}
	return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w,m; cin >> h >> w >> m;
  int br[300001];
  int bc[300001];
  int cntr[300001] = {};
  int cntc[300001] = {};
  int maxr=0,maxc=0;
  for(int i = 0; i < m; ++i){
    cin >> br[i] >> bc[i];
    ChangeMax(maxr,++cntr[br[i]]);
    ChangeMax(maxc,++cntc[bc[i]]);    
  }
  bitset<300001>r,c;
  int cr=0,cc=0;
  if(w < h)for(int i = w+1; i <= h; ++i)if(maxr == cntr[i])cr+=r[i] = 1;
  if(h < w)for(int i = h+1; i <= w; ++i)if(maxc == cntc[i])cc+=c[i] = 1;
  for(int i = min(w,h); i >= 1; --i){
    if(maxr == cntr[i])cr+=r[i] = 1;
    if(maxc == cntc[i])cc+=c[i] = 1;
  }
  int cntd = 0;
  for(int i = 0; i < m; ++i)
    cntd += r[br[i]]&c[bc[i]];
  cout << maxr + maxc - (cntd == cr*cc) << endl;
}


Measured memory_bytes: 8416
#include<stdio.h>
#define MAX 100005
#define NIL -1

typedef struct{
  int r;
  int l;
  int p;
}node;

int n,D[MAX];
node T[MAX];

void print(int u);
int rec(int u,int p);

int main(){
  int i,j,d,v,c,l,r;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
    T[i].l=NIL;
    T[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
 
  for(i=0;i<n;i++){
    if(T[i].p==NIL) r=i;
  }
    
  rec(r,0);

  for(i=0;i<n;i++) print(i);
  




  return 0;
}

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p==NIL){
    printf("root, ");
  }
  else if(T[u].l==NIL){
    printf("leaf, ");
  }
  else printf("internal node, ");

  printf("[");
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int u,int p){
  D[u]=p;
  if(T[u].r != NIL)   rec(T[u].r,p);
  if(T[u].l != NIL)   rec(T[u].l,p+1);
}



Measured memory_bytes: 6388
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, u, v = LI()
G = [[] for _ in range(n)]
for a, b in LIR(n - 1):
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]


def bfs(root):
    dq = deque([root])
    dist = [-1] * n
    dist[root] = 0
    while dq:
        u = dq.popleft()
        for v in G[u]:
            if dist[v] == -1:
                dist[v] = dist[u] + 1
                dq += [v]
    return dist


dist_u = bfs(u - 1)
dist_v = bfs(v - 1)
ans = 0
for i in range(n):
    if dist_v[i] > dist_u[i]:
        ans = max(ans, dist_v[i] - 1)


print(ans)


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=0;
vector<ll> A;

signed main(){
    cin >> N;
    ans = N/1000;
    if(N%1000!=0) ans++;
    cout << 1000*ans-N << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, A, B;
    cin >> N >> A >> B;
    if (A > B) swap(A, B);
    if ((B - A) % 2 == 0) {
        cout << (B - A) / 2 << endl;
    } else {
        int ans = min(B - 1, N - A);
        ans = min(ans, A + (B - A - 1) / 2);
        ans = min(ans, N - B + 1 + (B - A - 1) / 2);
        cout << ans << endl;
    }
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#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() {
  int a, b; cin >> a >> b;
  rep(i,1001) {
    double a_cos = i * 0.08;
    double b_cos = i * 0.1;
    if ( a_cos < a+1 && a_cos >= a && b_cos < b+1 && b_cos >= b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
      	int tmp = a;
      	int number = 1 ;
      	while(tmp < b)
        {
          tmp=tmp+(a-1);
          number++;            
        }
      	if (b == 1) System.out.println(0);
        else   	System.out.println(number);
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, T; cin >> n >> T;
	vector<pair<int,int>> no;
	vector<int> can;
	for(int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		if(a) no.push_back({a, b});
		else {
			can.push_back(b);
		}
	}
	sort(can.begin(), can.end());
	vector<long long> sums;
	int ans = 0;
	long long s = 0;
	for(int i = 0; i < (int)can.size(); i++){
		s++;
		s += can[i];
		sums.push_back(s);
		if(s <= T){
			ans = max(ans, i + 1);
		}
	}
	auto eval = [&](vector<int> ord, int stp){
		long long c = 0;
		for(int p : ord){
			c++;
			c = c + no[p].first * c + no[p].second;
			if(c > stp) break;
		}
		return c;
	};
	int len = no.size();
	vector<int> used(len, 0);
	int m = 0;
	vector<int> done;
	for(int i = 0; i < len; i++){
		m++;
		int option = 1<<30, ch = -1;
		vector<int> ndone;
		int sz = done.size();
		using ll = long long;
		auto M = create<pair<ll, ll>>(sz, sz);
		for(int j = 0; j < sz; j++){
			pair<ll,ll> now = {1, 0};
			for(int k = j; k < sz; k++){
				now.first  *= (no[done[k]].first + 1);
				now.second *= (no[done[k]].first + 1);
				now.second += no[done[k]].first + no[done[k]].second + 1;
				M[j][k] = now;
			}
		}
		for(int j = 0; j < len; j++){
			if(!used[j]){
				for(int k = 0; k <= done.size(); k++){
					ll v = 0;
					if(k){
						v = M[0][k - 1].second;
					}
					v = (no[j].first + 1) * (v + 1) + no[j].second;
					if(k < done.size()){
						v *= M[k][done.size() - 1].first;
						v += M[k][done.size() - 1].second;
					}
					if(option > v){
						option = v;
						ch = j;
						vector<int> now = done;
						now.insert(now.begin() + k, j);
						ndone = now;
					}
				}
			}
		}
		if(option > T) break;
		// cout << "opt " << option << '\n';
		used[ch] = 1;
		m = option;
		done = ndone;
		int p = lower_bound(sums.begin(), sums.end(), T - m + 1) - sums.begin();
		ans = max(ans, p + i + 1);
	}
	cout << ans << '\n';
	return 0;
}


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

int main() {
	int K, S, ans = 0; cin >> K >> S;
	for( int x = 0; x <= K; x++ ){
		for( int y = 0; y <= K; y++ ){
			if( S - x - y <= K && x + y <= S ){
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


ll niz[1000005];

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    bool ima = 0;
    ff(i,0,n - 1){
        cin >> niz[i];
        if(niz[i] == 0)ima = 1;
    }
    if(ima){
        cout << 0 << "\n";
        return 0;
    }
    ll tr = 1;
    ll broj = 1e9;
    broj *= broj;
    bool da = 0;
    ff(i,0,n - 1){
        if(da)break;
        ll x = niz[i];
        ll sta = broj / x;
        if(broj%x != 0){
            if(tr >= sta)da = 1;
        }
        else{
            if(tr > sta)da = 1;
        }
        if(!da)tr *= x;
    }
    if(da)cout << -1 << "\n";
    else cout << tr << "\n";
    return 0;
}


Measured memory_bytes: 4480
#include <iostream>

using namespace std;


int dp[1000030][3];
int a[1000030];
int b[1000030];
int c[1000030];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    int res=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    cout<<res;
    return 0;
}


Measured memory_bytes: 12928
N = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]


count = 0
for t in T:
    S.append(t)
    i = 0
    while t != S[i]:
        i += 1
    if i != (len(S) - 1):
        count += 1
    S.pop()
print(count)



Measured memory_bytes: 6340
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

#define int ll
//#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
#define PI 3.141592653589
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
using pld = pair <ld, ld>;

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

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

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
}

int foo(int a)
{
    if (a == -1)
        return 0;
    vector <int> kek = {a, 1, a + 1, 0};
    return kek[a % 4];
}

signed main()
{
    Start();
    int a, b;
    cin >> a >> b;
    cout << (foo(b) ^ foo(a - 1));
    return 0;
}


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

int main() {
	int N,x,c=0;
	std::vector<int> a;
	std::cin>>N>>x;
	for(int i=0;i<N;++i)
	{
		int y;
		std::cin>>y;
		a.push_back(y);
	}
	std::sort(a.begin(),a.end());
	for(int i=0;i<N;++i){
		if(x>=a[i])
		{
			++c;
			x-=a[i];
		}
	}
	if(x>0 && c == N)
		c -= 1;
	std::cout<<c<<std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}


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

int main()
{
    string s;
    cin>>s;
    int ans = INT_MAX;
    for(int i=0;i<=s.length()-3;i++)
    {
        string temp = s.substr(i,3);
        int temp1 = stoi(temp);
        ans = min( ans , abs(temp1 - 753));
    }
    cout<<ans;
}

Measured memory_bytes: 3576