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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#include <unordered_set>

//#define _USE_MATH_DEFINES
//#include <math.h>


#include <vector>
#include <list>

#include <set>
#include <map>

#include <unordered_map>

#include <queue>

#include <string>

#include <vector>

#define sqr(x) (x) * (x)

#include <algorithm>
#include <functional>

#include <bitset>

#include <functional>

#include <chrono>

typedef unsigned int u32;
typedef int i32;

typedef unsigned long long int u64;
typedef long long int i64;

typedef uint16_t u16;
typedef int16_t i16;

typedef uint8_t u8;
typedef int8_t i8;


using namespace std;
using namespace std::chrono;

struct less_key
{
    bool operator() (pair<i64, i64> p1, pair<i64, i64> p2)
    {
        return (p1.first < p2.first || (p1.first == p2.first && p1.second < p2.second));
    }
};

struct pair_hash
{
    std::size_t operator()(const pair<i64, i64>& k) const
    {
        return static_cast<size_t>(k.first ^ k.second);
    }
};


#include <random>

const i64 mod = 1000000007ll;
const i64 inf = 10000000000000007ll;

const i64 mod2 = 998244353ll;

const double eps = 0.00000001;

struct City {
    i64 y;
    i64 p;
    i64 i;
    string r;
};

struct less_key_city
{
    bool operator() (const City& c1, const City& c2)
    {
        return (c1.y < c2.y);
    }
};



City a[100005];

map<i64, vector<City> > p;

string gen(City q, i64 i) {
    stringstream ss;
    ss << setw(6) << setfill('0');
    ss << q.p;
    ss << setw(6) << setfill('0');
    ss << i + 1;
    return ss.str();
}

int main() {
    i64 n, m;

    cin >> n >> m;

    for (i64 i = 0; i < m; i++) {
        City c;
        cin >> c.p >> c.y;
        c.i = i;

        a[i] = c;
    }

    for (i64 i = 0; i < m; i++) {
        p[a[i].p].push_back(a[i]);
    }

    for (auto& t : p) {
        sort(t.second.begin(), t.second.end(), less_key_city());
    }

    for (auto& t : p) {
        for (i64 i = 0; i < t.second.size(); i++) {
            City& q = t.second[i];
            a[q.i].r = gen(q, i);
        }
    }


    for (i64 i = 0; i < m; i++) {
        cout << a[i].r << endl;
    }


    return 0;
}

Measured memory_bytes: 21760
// 桁dpでmod2019を状態として管理する？
// abc159のeみたいな感じ
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 200010;
const long long mod = 2019;
long long C[MAX_N];

int main() {
    string S;
    cin >> S;
    int N = S.size();
    reverse(S.begin(),S.end());
    long long base = 1;
    map<long long, long long> Map;
    for(int i = 1; i <= N; ++i) {
        C[i] = (long long)(S[i-1] - '0')*base%mod;
        base *= 10LL;
        base %= mod;
    }
    for(int i = 1; i <= N; ++i) {
        C[i] += C[i-1];
        C[i] %= mod;
    }
    for(int i = 0; i <= N; ++i) {
        ++Map[C[i]];
    }
    long long res = 0LL;
    for(auto &p : Map) {
        long long num = p.second;
        res += num*(num-1)/2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5264
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int id = 0;
vector<int> c;
vector<vector<int>> g;
vector<int> seen;
vector<int> value;
void dfs(int node) {
  if(seen[node]) return;
  seen[node] = 1;
  value[node] = c[id];
  id++;
  for(auto& next : g[node]) {
    if(!seen[next]) dfs(next);
  }
}
int main() {
  int n;
  cin >> n;
  g.resize(n);
  c.resize(n);
  seen.resize(n);
  value.resize(n);
  for(int i=0;i<n-1;i++) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  for(int i=0;i<n;i++) cin >> c[i];
  sort(c.rbegin(), c.rend());
  dfs(0);
  long long m = 0;
  for(int i=0;i<n;i++) {
    for(auto& el : g[i]) {
      m += min(value[i], value[el]);
    }
  }
  cout << m / 2 << endl;
  for(int i=0;i<n;i++) cout << value[i] << endl;
  return 0;
}


Measured memory_bytes: 1280
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M1 = sc.nextInt();
        int D1 = sc.nextInt();
        int M2 = sc.nextInt();
        int D2 = sc.nextInt();
        System.out.println(String.format("%d", M1==M2 ? 0 : 1));
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll all = 0;
    rep(i,n) all = all ^ a[i];
    vector<ll> ans(n);
    rep(i,n) ans[i] = a[i] ^ all;
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

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

const long long mod = 1000000007;

long long factmod(int n, long long m){
  long long res = 1;
  while(n > 0){
    res *= n;
    res %= m;
    n--;
  }
  return res;
}

int main(){
  int n, m; cin >> n >> m;
  if(abs(n-m) > 1){
    cout << 0 << endl;
    return 0;
  }
  long long ans;
  if(abs(n-m) == 1){
    ans = factmod(n, mod) * factmod(m, mod) % mod;
  }
  else{
    ans = factmod(n, mod) * factmod(m, mod) % mod * 2 % mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import Data.Functor( (<$>))

main = do
    [w,h,x,y,r] <- (read <$>) . words <$> getLine
    let
	(left, top) = (r, h-r)
	(right, bottom) = (w - r, r)

    putStrLn $
	if left <= x && x <= right
		    &&
	    bottom <= y && y <= top
	    then "Yes"
	    else "No"



Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {

    ll N, M, ans;
    cin >> N >> M;
    ans = pow(2, M) * (1900 * M + 100 * (N - M));

    cout << ans;

    return 0;
}

Measured memory_bytes: 4008
# n*mの行列Aとm*1のベクトルbの積を出力するプログラム
n, m = input().split()
n = int(n)
m = int(m)

A = [[0] * m for i in range(n)]
for i in range(n):
    list = input().split()
    for j in range(m):
        A[i][j] = int(list[j])

b = [0] * m
for i in range(m):
    b[i] = int(input())

# 計算と結果出力
for i in range(n):
    c = 0
    for j in range(m):
        c += A[i][j] * b[j]
    print(c)


Measured memory_bytes: 6012
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E: White and Blue
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

struct WB {
  ll d;
  int w, b;
  WB() {}

  void set(int _w, int _b, int p) {
    w = _w, b = _b;
    d = (ll)(100 - p) * w + (ll)p * b;
  }

  bool operator<(const WB &wb) const { return d < wb.d; }
};

/* global variables */

WB wbs[MAX_N];

/* subroutines */

/* main */

// wn/(wn+bn) >= p/100 -> 100wn >= p(wn+bn) -> (100-p)wn-p*bn >= 0

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

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int wi, bi;
    scanf("%d%d", &wi, &bi);
    wbs[i].set(wi, bi, p);
    sum -= (ll)p * bi;
  }
  sort(wbs, wbs + n);

  int wc = 0;
  for (int i = n - 1; i >= 0 && sum < 0; i--, wc++) sum += wbs[i].d;

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}
 
int main(){
    int n,m;
    while(cin>>n>>m,n){
        vi where(n+1,-1);
        vector<map<int,ll>> w;
        char c;
        rep(i,m){
            cin>>c;
            if(c=='!'){
                ll a,b,x;
                cin>>a>>b>>x;
                if(where[a]==-1 && where[b]==-1){
                    int i=w.size();
                    where[a]=where[b]=i;
                    w.eb();
                    w[i][a]=0ll;
                    w[i][b]=x;
                }else if(where[a]==-1 || where[b]==-1){
                    if(where[a]==-1){
                        swap(a,b);
                        x*=-1;
                    }
                    int i=where[a];
                    where[b]=i;
                    w[i][b]=w[i][a]+x;
                }else{

                    int i=where[a];
                    int j=where[b];
                    int diff=w[i][a]+x-w[j][b];
                    for(auto data:w[j]){
                        where[data.fs]=i;
                        w[i].emplace(data.fs,data.sc+diff);
                    }
                }
            }else{
                int a,b;
                cin>>a>>b;
                if(where[a]!=where[b] || where[a]==-1){
                    cout<<"UNKNOWN"<<endl;
                }else{
                    int i=where[a];
                    cout<<w[i][b]-w[i][a]<<endl;
                }
            }
        }
    }
}



Measured memory_bytes: 7248
// C - Half and Half
#include <bits/stdc++.h>
using namespace std;

int main(){
	int A,B,C,X,Y; cin>>A>>B>>C>>X>>Y;
	int ans;
	if(A+B > C*2){
		int min_n = min(X, Y);
		ans = C*min_n*2;
		int rest_n = max(X, Y) - min_n;
		if(X > Y){//rest X -> A
			if(A > C*2) ans += C * rest_n * 2;
			else ans += A * rest_n;
		}
		else if(X < Y){//rest Y -> B
			if(B > C*2) ans += C * rest_n * 2;
			else ans += B * rest_n;
		}
	}
	else ans = A*X + B*Y;
	cout<< ans <<endl;
}

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

int n;
ll sum, l, ans, a[200100];

int main() {// freopen("_in.txt","r",stdin);
	scanf("%d",&n);  ans = 1e17;
	for (int i=1;i<=n;i++) scanf("%lld",a+i), a[i] -= i, sum += a[i];
	sort(a+1,a+n+1);
	ans = min(ans,sum - n * a[1]);
	for (int i=1;i<=n;i++) {
		l += a[i];
		ans = min(ans,i * a[i] - l + (sum - l) - (n-i) * a[i]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().strip().split()))


def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


ever_gcd = A[0]
for i in range(N - 1):
    ever_gcd = gcd(ever_gcd, A[i + 1])

print(ever_gcd)


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

int main() {
  int N;
  cin >> N;
  int total = 0;
  
  for(int i=0;i<N;i++){
    int l, r;
    cin >> l >> r;
    total += r - l + 1;
  }
  cout << total << endl;
}

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

using namespace std;

const int N = 100010;

int n, a[N << 1];

bool check(int x)
{
	int l = n, r = n;
	while (l > 1 && (a[l - 1] >= x) != (a[l] >= x)) --l;
	while (r < 2 * n - 1 && (a[r + 1] >= x) != (a[r] >= x)) ++r;
	if (l == 1 && r == 2 * n - 1) return (a[n] >= x) ^ ((n + 1) & 1);
	if (l == 1) return a[r] >= x;
	if (r == 2 * n - 1) return a[l] >= x;
	if (n - l <= r - n) return a[l] >= x;
	return a[r] >= x;
}

int main()
{
	int l = 0x7fffffff, r = 0;
	
	scanf("%d", &n);
	
	for (int i = 1; i <= 2 * n - 1; ++i)
	{
		scanf("%d", a + i);
		l = min(l, a[i]);
		r = max(r, a[i]);
	}
	
	while (l < r)
	{
		int mid = (0ll + l + r + 1) >> 1;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	
	cout << l;
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long n,x,sum[200005],sxor[200005];
long long l=1,ans=0;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		sxor[i]=sxor[i-1]^x;
		sum[i]=sum[i-1]+x;
	}
	for(int r=1;r<=n;r++){
		while((sum[r]-sum[l-1])!=(sxor[r]^sxor[l-1]))l++;
		ans+=r-l+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
ll n;
vector<ll>a(200010);
vector<ll>b(200010);
vector<vector<ll> >dp(200010,vector<ll>(4,-1));
ll solve(ll i,ll j){
    if(dp[i][j]>=0)return dp[i][j];
    ll res=inf*inf;
    ll retr;
    if(a[i+1]==0)retr=2;
    else if(a[i+1]%2==0)retr=0;
    else retr=1;
    ll retl;
    if(a[i]==0)retl=2;
    else if(a[i]%2==0)retl=0;
    else retl=1;
    ll unretr;
    if(a[i+1]==0)unretr=1;
    else if(a[i+1]%2==0)unretr=1;
    else unretr=0;
    ll unretl;
    if(a[i]==0)unretl=1;
    else if(a[i]%2==0)unretl=1;
    else unretl=0;
    if(j==0){
        res=min(res,solve(i+1,0)+unretr);
        res=min(res,solve(i+1,1)+unretr);
    }
    if(j==1){
        res=min(res,solve(i+1,1)+retr);
        res=min(res,b[n]-b[i]);
    }
    if(j==2){
        res=min(res,solve(i-1,2)+unretl);
        res=min(res,solve(i-1,3)+unretl);
    }
    if(j==3){
        res=min(res,solve(i-1,3)+retl);
        res=min(res,b[i]);
    }
    dp[i][j]=res;
    return res;
}
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a[i+1];
        b[i+1]=b[i]+a[i+1];
    }
    dp[0][2]=0;
    dp[0][3]=0;
    dp[n][0]=0;
    dp[n][1]=0;
    ll ans=min(solve(0,1),solve(0,0));
    ans=min(ans,min(solve(n,2),solve(n,3)));
    //cout<<ans<<endl;
    REP(i,1,n){
        ans=min(ans,solve(i,1)+solve(i,2));
        ans=min(ans,solve(i,1)+solve(i,3));
        ans=min(ans,solve(i,3)+solve(i,0));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 36224
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int getfives(int i) {
    int five = 5;
    int ans = 0;
    while(i / five) {
        ans += i / five;
        five *= 5;
    }
    return ans;
}

void solve52(int i) {
    int fives = getfives(i);
    cout << fives << endl;
}

int main() {
    int n;
    while(cin >> n, n) {
        solve52(n);
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=1e5+10;
int a[maxn],b[maxn];
int main(){
    cin>>n>>m;
    int f=0;
    for(int i=1;i<=m;i++){
        cin>>a[i];
        if(a[i]%2){
            f++;
        }
    }
    if(f>2){
        cout<<"Impossible";
        return 0;
    }
    int p=0;
    if(m==1){
        if(a[1]!=1){
            b[++p]=a[1]-1;
        }
        b[++p]=1;
    }
    else if(m==2){
        if(a[1]!=1){
            b[++p]=a[1]-1;
        }
        b[++p]=a[2]+1;
    }else{
        int k=1;
        for(int i=1;i<m;i++){
            if(a[i]%2==1){
                if(k==1){
                    swap(a[i],a[1]);
                }
                else swap(a[i],a[m]);
                k++;
            }
        }
        for(int i=1;i<=m;i++){
            if(i==1){
                if(a[i]-1!=0){
                    b[++p]=a[i]-1;
                }
            }
            else {
                b[++p]=a[i];
            }
        }
        b[p]++;
    }
    for(int i=1;i<=m;i++){
        cout<<a[i];
        if(i!=m) cout<<" ";
        else cout<<endl;
    }
    cout<<p<<endl;
    for(int i=1;i<=p;i++){
        cout<<b[i];
        if(i!=p) cout<<" ";
        else cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m) = readIntList()
    if (m == n) println("Yes")
    else println("No")
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 36004
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;


int main(){
    //bool ans=false;
    int ans=0;
    int N;
    vector<char> s;

    cin>>N;
    for(int i=0;i<N;i++){
        char a=0;
        cin>>a;
        s.push_back(a);
    }

    for(int i=0;i<N-2;i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define modulo 998244353
#define endl '\n'
using namespace std;
ll fxp(ll a, ll b)
{
    if(b == 0)return 1;
	if(b%2 == 0){
		ll c = fxp(a,b/2);
		return (c*c)%1000000007;
	}
	return (a*fxp(a,b-1))%1000000007;
}
int lcm(int c,int d)
{
    int a=c;
    int b=d;
    int ans;
    if(a>=b)
    {
        while(b!=0)
        { 
            int x=b;
            b=a%b;
            a=x;
        }
        ans = ( c*d)/a;
    }
    else
    {
        while(a!=0)
        {
            int x=a;
            a=b%a;
            b=x;
        }
        ans = ( c*d)/b;  
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int dp[n];
    dp[n-1]=0;
    dp[n-2]=abs(h[n-1]-h[n-2]);
    for(int i=n-3;i>=0;i--)
    {
        dp[i]=min(abs(h[i]-h[i+1])+dp[i+1],abs(h[i]-h[i+2])+dp[i+2]);
    }
    cout<<dp[0]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    bool can = true;
    for(int i = 0; i < N; i++){
        if(A[i] % 2 == 0){
            if(A[i] % 3 != 0 and A[i] % 5 != 0) can = false;
        }
    }
    if(can) puts("APPROVED");
    else puts("DENIED");
}


Measured memory_bytes: 3572
/*************************************************************************
    > File Name: f.cpp
    > Author: Amano Sei
    > Mail: amano_sei@outlook.com 
    > Created Time: 2019年12月22日 星期日 22时47分59秒
 ************************************************************************/

#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int maxn = 100005;

vector<int> edge[maxn];
int n;

int sp[2][maxn];
bool book[maxn];

void dfs(int u, int cr, int dep){
    book[u] = true;
    sp[cr][u] = dep;
    for(size_t i = 0; i < edge[u].size(); i++){
        register int cv = edge[u][i];
        if(!book[cv])
            dfs(cv, cr, dep+1);
    }
}

int main(){
    int cu, cv, u, v, ans = 0;
    scanf("%d%d%d", &n, &u, &v);
    for(int i = 0; i < n-1; i++){
        scanf("%d%d", &cu, &cv);
        edge[cu].push_back(cv);
        edge[cv].push_back(cu);
    }
    if(edge[u].size() == 1 && edge[u][0] == v){
        puts("0");
        return 0;
    }
    dfs(v, 0, 0);
    memset(book, 0, sizeof(book));
    dfs(u, 1, 0);
    for(int i = 1; i <= n; i++)
        if(sp[0][i] >= sp[1][i])
            ans = max(ans, sp[0][i]);
    printf("%d\n", ans-1);
    return 0;
}



Measured memory_bytes: 10496
#include <stdio.h>

int main()
{

    int a;
    char data[200001];

    scanf("%d", &a);
    char x;
    int r = 0;
    int reftr = 0;
    scanf("%s",data);
    for (int i = 0; i < a; i++)
    {
        if (data[i] == 'R')
            r++;
    } //count

   // printf("%d\n", r);
    //printf("%d\n", reftr);

    for (int i = 0; i <r; i++)
    {
        if (data[i] == 'R')
            reftr++;
    }
        printf("%d\n",r-reftr);
}

Measured memory_bytes: 2340
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<LL,LL> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

#define chl k<<1
#define chr k<<1|1

const int maxn=5e5+5;
int a[maxn],book[2*maxn],n,m,tree[maxn*3],t,ans[maxn];
struct node {int l,r,bianhao;};
node h[maxn];

bool cmp(node &a,node &b)
{
    return a.r<b.r;
}

void add(int k,int l,int r,int j,int v)
{
    if(j<l || j>r) return;
    if(l==r && l==j) {tree[k]+=v;return;}
    tree[k]+=v;
    int mid=(l+r)>>1;
    add(chl,l,mid,j,v);
    add(chr,mid+1,r,j,v);
}

int sum(int k,int l,int r,int ll,int rr)
{
    if(rr<l || ll>r) return 0;
    if(l>=ll && r<=rr) return tree[k];
    int mid=(l+r)>>1;
    return sum(chl,l,mid,ll,rr)+sum(chr,mid+1,r,ll,rr);
}

int main()
{
    n=read(); m=read();
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=0;i<m;i++) h[i].l=read(),h[i].r=read(),h[i].bianhao=i;
    sort(h,h+m,cmp);

    for(int i=0;i<m;i++)
    {
        int l=h[i].l,r=h[i].r;
        for(int j=t+1;j<=r;j++)
        {
            if(!book[a[j]]) book[a[j]]=j,add(1,1,n,j,1);
            else
            {
                add(1,1,n,book[a[j]],-1);
                book[a[j]]=j;
                add(1,1,n,j,1);
            }
        }
        t=r;
        ans[h[i].bianhao]=sum(1,1,n,l,r);
    }
    for(int i=0;i<m;i++)
        printf("%d\n",ans[i]);

	return 0;
}


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

public class Main {

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

        int H = sc.nextInt();
        int N = sc.nextInt();
        int[] A = new int[N];
        Arrays.setAll(A, i -> sc.nextInt());

        int sum = Arrays.stream(A).sum();
        if (sum >= H) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 58900
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define INF 1000000
typedef pair<int,int> P;

int main(){
	int n,m;
	P t[101];
	int dp[101];
	cin >> n >> m;
	for(int i=0;i<m;i++){
		cin >> t[i].first >> t[i].second;
	}
	sort(t,t+m);
	for(int i=0;i<=n;i++){
		dp[i] = INF;
	}
	dp[0] = 0;
	for(int i=0;i<m;i++){
		for(int j=t[i].second-1;j>=t[i].first-1;j--){
			if(dp[j] == INF) continue;
			dp[t[i].second] = min(dp[t[i].second],dp[j]+1);
		}
	}
	if(dp[n] == INF) cout << "Impossible" << endl;
	else cout << dp[n] << endl;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>
#include<cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

void dump_line(int *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

ll mypow(ll x,ll n){
	if(n==0) return 1;
	ll res=mypow(x*x,n/2);
	if(n&1) res=res*x;
	return res;
}

ll mod_pow(ll x,ll n,ll mod){
	if(n==0) return 1;
	ll res=mod_pow(x*x%mod,n/2,mod);
	if(n&1) res=res*x%mod;
	return res;
}

bool notprime[101];
int divs[101];


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

	for(int i=2;i<=n;i++){
		if(!notprime[i]){
			for(int j=2;i*j<=n;j++){
				notprime[i*j]=true;
			}
		}
	}
//	cout << "\n";
//	cout << "primes\n";
//	for(int i=2;i<=n;i++){
//		if(!notprime[i]) cout << i << "\n";
//	}
//	cout << "\n";

	//iの約数の中に含まれる素数jの数
	for(int i=2;i<=n;i++){
//		cout << i << "\n";
		int t = i;
		for(int j=2;j<=sqrt(i);j++){
			if(notprime[j] || t%j) continue;
			while(t%j==0 && notprime[t]){
				divs[j] ++;
//				cout << "\t" << j << "\n";
				t/=j;
			}
		}
//		cout << "\t" << t << "\n";
		divs[t]++;
	}
	int tmp;
	int ns[5]={};//0:3 1:5 2:15 3:25 4:75
	for(int i=2;i<=n;i++){
		if(notprime[i]) continue;
		tmp = divs[i];
		if(tmp >= 2) ns[0]++;
		if(tmp >= 4) ns[1]++;
		if(tmp >= 14) ns[2]++;
		if(tmp >= 24) ns[3]++;
		if(tmp >= 74) ns[4]++;
	}

//	cout << "ns\n";
//	dump_line(ns,5);

	for(int i=2;i<=n;i++){
		if(notprime[i]) continue;
//		cout << i << " " << divs[i] << "\n";
	}

	int ans=0;
	if(ns[1] >= 2 && ns[0]-2 >= 1){
//		cout << "3*5*5\n";
		ans+=ns[1]*(ns[1]-1)*(ns[0]-2)/2; //3*5*5
	}
	if(ns[2] >= 1 && ns[1]-1 >= 1) ans+=ns[2]*(ns[1]-1); //15*5
	if(ns[3] >= 1 && ns[0]-1 >= 1) ans+=ns[3]*(ns[0]-1); //25*3
	if(ns[4] >= 1) ans += ns[4]; //75

	cout << ans << "\n";

	return 0;
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int[] a = sc.IntArray();

        int total = Math.Abs(a[0]);
        for (int i = 1; i < n; i++)
        {
            total += Math.Abs(a[i] - a[i - 1]);
        }
        total += Math.Abs(a[n - 1]);

        for (int i = 0; i < n; i++)
        {
            int answer = total;

            int before = i == 0 ? 0 : a[i - 1];
            int middle = a[i];
            int after = i == n - 1 ? 0 : a[i + 1];

            answer -= Math.Abs(before - middle) + Math.Abs(after - middle);
            answer += Math.Abs(after - before);

            Console.WriteLine(answer);
        }
    }

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

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

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

            return _line[_index++];
        }

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

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

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


Measured memory_bytes: 28124
#include <bits/stdc++.h>
#define rep(i, N) for (long long i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    long long N, K;
    cin >> N >> K;
    vector<long long> a(N), b(N);
    vector<pair<long long, long long>> P(N);
    rep(i, N)
    {
        cin >> a[i] >> b[i];
        P[i] = make_pair(a[i], b[i]);
    }
    sort(P.begin(), P.end());
    long long i = 0, ans;
    long long count = 0;
    while (count < K)
    {
        ans = i;
        count += P[i].second;
        i++;
    }
    cout << P[ans].first << endl;
}


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

int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int now = 0;
  if (k < n) {
    for (int i = 0; i < k; i++) {
      now = a[now];
    }
    cout << now + 1 << endl;
    return 0;
  }
  vector<int> mem(n+1);
  for (int i = 0; i < n; i++) {
    mem[i] = now;
    now = a[now];
  }
  mem[n] = now;
  int rd;
  for (int i = n - 1; i >= 0; i--) {
    if (mem[n] == mem[i]) {
      rd = n - i;
      break;
    }
  }
  int mod = (int)((k - n) % rd);
  now = mem[n];
  for (int i = 0; i < mod; i++) {
    now = a[now];
  }
  cout << now + 1 << endl;
  return 0;
}

Measured memory_bytes: 4760
#import itertools

n, m, d = map(int, input().split())

#numbers = (int(i) for i in range(1,n+1))
#beauties = []
#
#for i in itertools.product(numbers, repeat=m):
#  print(i)
#  point = 0
#
#  for j in range(len(i)-1):
#    if abs(i[j] - i[j+1]) == d:
#      point += 1
#  beauties.append(point)
#
#print(sum(beauties)/len(beauties))
if d != 0:
  print((0.5 / (n / 2) ** 2) * (m - 1) * (n - d))
else:
  print((0.5 / (n / 2) ** 2) * (m - 1) * (n - d) / 2)



Measured memory_bytes: 2940
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map(String::toInt)
    val grid = (1..h).map {
        readLine()!!.toCharArray()
    }

    val d = listOf(-1 to 0, 0 to 1, 1 to 0, 0 to -1)

    for (y in (1..(h - 1))) {
        for (x in (1..(w - 1))) {
            if (grid[y][x] != '#') {
                continue
            }

            var no = true
            for ((dy, dx) in d) {
                if (y + dy !in (0..(h - 1))) {
                    continue
                }

                if (x + dx !in (0..(w - 1))) {
                    continue
                }

                if (grid[y + dy][x + dx] == '#') {
                    no = false
                    break
                }
            }

            if (no) {
                println("No")
                return
            }
        }
    }

    println("Yes")
}

Measured memory_bytes: 37916
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
//#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

int32_t main()
{
    io
   string s,t;
   cin>>s>>t;
   int n=s.length();
   int m=t.length();int ans=INT_MAX;
   for(int i=0;i<n-m+1;i++)
   {
    int cc=0;
    for(int j=i;j<i+m;j++)
    {
      if(s[j]!=t[j-i])
      {
          cc++;
      }
    }
    ans=min(cc,ans);
   }
   cout<<ans<<endl;

    
}

Measured memory_bytes: 3564
#!/usr/bin/env python3
#ABC75 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,K = LI()
xy = []
for _ in range(n):
    x,y = LI()
    xy.append((x,y))
ans = inf
for _ , uy in xy:
    for _ , dy in xy:
        if uy < dy:
            continue
        for rx , _ in xy:
            for lx , _ in xy:
                if rx < lx:
                    continue
                cnt = 0
                for x,y in xy:
                    if lx <= x <= rx and dy <= y <= uy:
                        cnt += 1
                if cnt >= K:
                    ans = min(ans,(rx - lx)*(uy - dy))
print(ans)


Measured memory_bytes: 49500
#include <cstdio>
#include<string>
#include<stack>
#include<queue>
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include<set>
#include<vector>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;
struct Human
{
	int age;
	double weight;
	char name[256];
};

int findSumOfDigits(int n) {
	int sum = 0;
	while (n > 0) { // n が 0 になるまで
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main()
{
	int l[10000];
	int n = 6;

	string s; // s.size() to_string char string %s
	int a,b,c,d;
	int sum = 0;
	vector<string> lang;
	vector<int> data;


	//cin>>N;
	// for (int i = 0; i < N; ++i) cin >> A[i];
	//while(true){break; ++res;}
	//cout << res << endl;
	//sort(a, a+N, greater<int>()) 大きい順ソート
	//set<int>values; values.insert() values.size()
	//map<string,int>salary; salary["John"] = 1400;
	// string num = to_string(counter);

	int count=0;
	int kari = 0;
	int N, K;

	cin >>a;
	



	cout << a/3600 <<":"<<(a%3600)/60<<":"<< (a % 3600) % 60 <<endl;


	return 0;
}


Measured memory_bytes: 3088
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<map> 
#include<string>
#include<queue>
#include<stack> 
#include<bitset>
#include<list>
#include<set>
#include<utility>
#include<iomanip>
#define IO ios::sync_with_stdio(false)
#define eps 1e-7
#define int long long
using namespace std;
const int mod=1e9+7;
int gcd(int x,int y)
{
	if(y==0)return x;
	else return gcd(y,x%y);
}
int tg[1000006],hg[1000005],n,a[1000005];
signed main()
{
	IO;
	cin>>n;
	int ans1,ans2,maxx=-1;
	bool flag1=true,flag2=false;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		maxx=max(maxx,a[i]);
		tg[a[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(i==1)
		hg[i]=a[i];
		else
		hg[i]=gcd(a[i],hg[i-1]);
	}
	for(int i=2;i<=maxx;i++)
	{
		int cnt=0;
		for(int j=1;i*j<=maxx;j++)
		{
			cnt+=tg[i*j];
			if(cnt>=2)
			{
				flag1=false;
				break;
			}
		}
	}
	if(hg[n]==1)flag2=true;
	if(flag1)
	{
		cout<<"pairwise coprime";
	}
	else if(flag2)
	{
		cout<<"setwise coprime";
	}
	else
	{
		cout<<"not coprime";
	}
}

Measured memory_bytes: 27040
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

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


void solve(){
	int n;
	cin >> n;
	int amount = 1000*((n+1000-1)/1000);
	cout << (amount-n) << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 3636
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stdio.h>

#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class T> using MAX_pq = priority_queue<T>;
template <class T> using MIN_pq = priority_queue<T,vector<T>,greater<T>>;
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol Mod=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r,q;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >>a[i];
  vector<lol> s(n+1);
  for(int i=1;i<=n;i++){
    s[i]=s[i-1]+a[i-1];
  }
  map<lol,int> mp;
  for(int i=0;i<=n;i++){
    mp[s[i]]++;
  }
  lol ans=0;
  set<lol> st;
  for(int i=0;i<=n;i++){
    if(st.find(s[i])==st.end()){
      lol w=mp[s[i]];
      ans+=w*(w-1)/2;
      st.insert(s[i]);
    }
  }
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 24448
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    
    int N, S, W, E = 0;
    int i = 0;
    while (s[i] != '\0') {
        if (s[i] == 'N') N++;
        if (s[i] == 'S') S++;
        if (s[i] == 'W') W++;
        if (s[i] == 'E') E++;
        i++;
    }
    
    if ( (N > 0 && S > 0) && (W == 0 && E == 0))
        cout << "Yes" << endl;
    else if ((W > 0 && E > 0) && (N == 0 && S == 0))
        cout << "Yes" << endl;
    else if (N > 0 && S > 0 && W > 0 && E > 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 888
#include <cstdio>
#include <vector>
#include <algorithm>

#define pf printf
#define F(i, a, b) for (LL i = a; i <= b; i ++)

typedef long long LL;

const LL N = 2e5 + 10;

using namespace std;

LL n, Ans, fa[N], v[N], S[N][2];
struct node {
	LL st, en, MN;
	friend bool operator < (node a, node b) { return a.st < b.st || a.st == b.st && a.en < b.en; }
};
vector <node> V[N];

void Dfs(LL k, LL Len) {
	LL l = S[k][0], r = S[k][1];
	if (!l) {
		V[k].push_back({0, 0, 0});
		return;
	}
	Dfs(l, Len), Dfs(r, Len);
	if (!V[l].size() || !V[r].size()) return;
	if (V[l].size() > V[r].size())
		swap(l, r);
	F(i, 0, V[l].size() - 1) {
		node a = V[l][i];
		LL L = 0, R = V[r].size() - 1, tmp = - 1;
		while (L <= R) {
			LL M = L + R >> 1;
			node b = V[r][M];
			if (a.en + v[l] + b.st + v[r] <= Len) {
				tmp = M, L = M + 1;
//				printf("%lld\n", tmp);
			}
			else
				R = M - 1;
//			pf("%lld %lld\n", L, R);
		}
		if (tmp > - 1)
			V[k].push_back({a.st + v[l], V[r][tmp].MN + v[r], 0});

		/*F(j, 0, V[r].size() - 1) {
			node b = V[r][j];
			if (a.en + v[l] + b.st + v[r] <= L)
				V[k].push_back({a.st + v[l], b.en + v[r]});
		}*/
	}
	if (!V[k].size()) return;
	LL p = V[k].size() - 1;
	F(i, 0, p)
		V[k].push_back({V[k][i].en, V[k][i].st, 0});
//	F(i, 0, V[k].size() - 1)
//		pf("%lld %lld\n", V[k][i].st, V[k][i].en);
//	pf("\n\n");
	sort(V[k].begin(), V[k].end());
	vector <node> a; a.clear();
	a.push_back({V[k][0].st, V[k][0].en});
	p = V[k].size() - 1;
	F(i, 1, p)
		if (V[k][i].st != V[k][i - 1].st)
			a.push_back({V[k][i].st, V[k][i].en});
	V[k] = a;
	V[k][0].MN = V[k][0].en;
	F(i, 1, p)
		V[k][i].MN = min(V[k][i - 1].MN, V[k][i].en);
}

LL OK(LL L) {
	F(i, 1, n) V[i].clear();
	Dfs(1, L);
	return V[1].size() > 0;
}

int main() {
	scanf("%lld", &n); LL l = 0, r = 0;
	F(i, 2, n) {
		scanf("%lld %lld", &fa[i], &v[i]);
		if (!S[fa[i]][0]) S[fa[i]][0] = i; else	S[fa[i]][1] = i;
		r += v[i];
	}
	while (l <= r) {
		LL m = l + r >> 1;
//		printf("%lld\n", m);
		if (OK(m))
			Ans = m, r = m - 1;
		else
			l = m + 1;
	}

	printf("%lld\n", Ans);
}

Measured memory_bytes: 45140
n = int(input())
c = [int(input()) for _i in range(n)]
c.append(-1)
dic = {}
dp = [0 for _i in range(n+1)]
dp[n] = 1
mod = 10**9 +7
for i in range(n):
    if c[i-1] != c[i]:
        if c[i] in dic:
            dp[i] = (dp[i-1] + dic[c[i]])%mod
        else:
            dp[i] = dp[i-1]
        dic[c[i]] = dp[i]
    else:
        dp[i] = dp[i-1]
    
print(dp[n-1]%mod)

Measured memory_bytes: 31008
#include<stdio.h>
int main(){
    int i, j, a[100], n, minj, tmp, count=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)scanf("%d", &a[i]);
    for(i=0; i<n; i++){
        minj=i;
        for(j=i; j<n; j++)if(a[j]<a[minj]){
                minj=j;
        }
        if(minj!=i)count++;
        tmp=a[i];
        a[i]=a[minj];
        a[minj]=tmp;
    }
    for(i=0; i<n-1; i++)printf("%d ", a[i]);
    printf("%d\n%d\n", a[n-1], count);
    return 0;
}

Measured memory_bytes: 600
N = int(input())
for k in range(1, N + 2):
    sn = k - 1
    if k * sn != 2 * N:
        continue

    print("Yes")
    print(k)
    s = [[0] * sn for _ in range(sn)]
    for i in range(sn):
        s[i][i] = s[i-1][i-1] + (i + 1)
        for j in range(i + 1, sn):
            s[i][j] = s[i][j-1] + j
            s[j][i] = s[i][j]
    s.append([s[i][i] for i in range(sn)])
    for x in s:
        print(sn, " ".join(map(str, x)))
    break
else:
    print("No")

Measured memory_bytes: 13456
from collections import deque

N,K = map(int,input().split())
A = list(map(int,input().split()))
nums = [0]*N

for i in range(N):
  nums[A[i]-1] += 1

nums.sort()

nums = deque(nums)

while True:
  if nums[0] == 0:
    nums.popleft()
  else:
    break
nums = list(nums)
if len(nums) <= K:
  print(0)
else:
  print(sum(nums[:len(nums)-K]))

Measured memory_bytes: 33668
import java.util.Scanner;
import java.lang.Math; 

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double r = scan.nextDouble();
		double cir = 2 * r * Math.PI;
		double area = Math.PI * r * r;
		System.out.printf("%.5f %.5f", area, cir);

	}

}



Measured memory_bytes: 28332
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int q = sc.nextInt();
		int h = sc.nextInt();
		int s = sc.nextInt();
		int d = sc.nextInt();
		int n = sc.nextInt();
		int min = Math.min(4 * q, h * 2);
		min = Math.min(min, s);
		long sum = 0;
		if (min * 2 > d) {
			if (n >= 2) {
				sum = (long) n / 2 * d;
			}
			sum += (long) ((n % 2) * min);
		} else {
			sum = (long) min * n;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 22996
#include<iostream>
using namespace std;
int main(){
int a, b, i, Mma=-1, min=1001;
  cin >> a;
  for(i=0;i<a;i++) {
  cin >> b;
  if(min>b) min=b;
    if(Mma<b) Mma=b;
  }
cout << Mma-min <<endl;
}

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

int main() {
  int n, t, a; cin >> n >> t >> a;
  double minsub = 1000;
  int ans;
  for (int i = 0; i < n; i++) {
    int h; cin >> h;
    double c = t - h * 0.006;
    double sub = abs(a - c);
    if (sub < minsub) {
      minsub = sub;
      ans = i + 1;
    }
  }
  cout << ans << endl;
}

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

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
long long MOD = 1000000007LL;

long long dp[210][210][210];


int main() {
	int n;
	cin >> n;
	dp[0][0][0] = 1;
	vector<char> v(n);
	rep(i, n) {
		cin >> v[i];
		if(v[i] == '-') {
			n--;
			i--;
		}
	}
	v.erase(v.begin()+n, v.end());

	rep(i, n) {
		char t = v[i];
		rep(j, n) {
			rep(k, n) {
				if(t == 'U') {
					if(j>0) (dp[i + 1][j][k] += j*dp[i][j][k]%MOD) %= MOD;
					(dp[i + 1][j + 1][k + 1] += dp[i][j][k]) %= MOD;
				}
				else {
					if(j - 1 >= 0 && k - 1 >= 0) (dp[i + 1][j - 1][k - 1] += j*k*dp[i][j][k]) %= MOD;
					if(j>0) (dp[i + 1][j][k] += k*dp[i][j][k]) %= MOD;
				}
			}
		}
	}
	rep(i,n+1){
		rep(j,n){
			rep(k,n){
				// cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
			}
		}
	}
	cout << dp[n][0][0] << endl;
}

Measured memory_bytes: 66220
a, b, c, d = map(int, input().split())
list1, list2 = [a, b], [c, d]
max1, max2, min1, min2 = max(list1), max(list2), min(list1), min(list2)
print(max(max1 * max2, min1 * min2, max1 * min2, max2 * min1))

Measured memory_bytes: 9172
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int min(int a, int b) {
    return (a <= b ? a : b);
}
int main(void) {
    char to[1001], from[1001];
    scanf("%s %s", to, from);
    int i, ans=1e9, cur=0, j;
    for (i=0; i < (int)strlen(to) && i+(int)strlen(from)<(int)strlen(to)+1; ++i) {
        // try all starting substring points
        cur=0;
        //printf("%d\n", i);
        for (j=0; j < (int)strlen(from); ++j) {
            //printf("%c %c\n", from[j], to[j+i]);
            if (from[j] != to[j+i]) {
                //printf("a\n");
                ++cur;
            }
        }
        ans=min(ans,cur);
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 1736
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	TestCases, OKs := readInt(), readInt()

	if TestCases == OKs {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	return t
}

Measured memory_bytes: 640
#include <stdio.h>
#define WHITE 0
#define BLACK 1
#define INF 10000
int d[101];
int G[101][101];
int color[101];
int num;
void prim(int w,int r);
int main(){
  int i,j,k,sum=0,r=0;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      scanf("%d",&G[i][j]);
    }}
  prim(G[i][j],r);

  for(i=0;i<num;i++){
    sum+=d[i];
  }
  printf("%d\n",sum);
  return 0;
}

void prim(int w,int r){
  int u,mincost,v,i,j;
  for(u=0;u<num;u++){
    d[u]=INF;/*接点の値*/
    color[u]=WHITE;
  }
  d[r]=0;/*最初の接点*/
  while(1){
    mincost=INF;/*最小を一応INFにしておく*/ 
    for(i=0;i<num;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost = d[i]; /*iでのこすとがきまる*/
	u=i;
      }
    }
    if(mincost == INF)
      break;
  
    color[u]=BLACK;
  
     for(v=0;v<num;v++){
      if(color[v]!=BLACK && G[u][v]<d[v] && G[u][v]!=-1){
	d[v]=G[u][v];
      }
     }
  }
  return;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
bool solve(){
	int N,K;
	cin>>N>>K;
	int mx = 0;
	int g = 0;
	rep(i,N){
		int a;
		cin>>a;
		g = gcd(g,a);
		chmax(mx,a);
	}
	if(K%g!=0) return 0;
	if(K>mx) return 0;
	return 1;
}

int main(){
	if(solve()) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

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

int main(){
	vector<int> nums;
	for( int i=0; i<5; i++ ){
		int n;
		cin >> n;
		nums.push_back(n);
	}
	sort( nums.rbegin(), nums.rend() );
	for( int i=0; i<4; i++ ){
		cout << nums[i] << " ";
	}
	cout << nums[4] << endl;
	return 0;
}

Measured memory_bytes: 0